Like Tree2Likes
  • 2 Post By dennis.cpp

What is wrong with this code?

This is a discussion on What is wrong with this code? within the Tech Board forums, part of the Community Boards category; Hi, I've been trying to write my first code ever.. I think I somehow managed to do it but there ...

  1. #1
    Registered User
    Join Date
    May 2011
    Posts
    4

    What is wrong with this code?

    Hi,
    I've been trying to write my first code ever..
    I think I somehow managed to do it but there is a compiler error and I can't figure out what it is , it seems correct to me so you might help me correct the error.


    The program suppose to ask the user for 5 numers and then it print the maximum value and the minumum value.
    Here is what I wrote:
    Code:
    package firstA;
    import java.util.Scanner ;
     class FirstA {
    
      
        public static void main(String[] args) {
            int a, b, c, d, e, max = 0, min  = 0;
            Scanner keyboard = new Scanner(System.in);
                  
            System.out.println ("Enter five numbers") ;
            a = keyboard.netxtInt ();
            b = keyboard.netxtInt ();
            c = keyboard.netxtInt ();        
            d = keyboard.netxtInt ();        
            e = keyboard.netxtInt ();
           
            if (a > b && a > c && a > d && a > e)
                max = a ;
            else if (b > a && b > c && b > d && b > e)
                max = b ;
            else if (d > a && d > b && d > c && d > e)
                max = d ;
            else if (c > a && c > b && c > d && c > e)
                max = c ;
            else if (d > a && d > b && d > c && d > e)
                max = d ;
            else if (e > a && e > b && e > c && e > d)
                max = e ;
            System.out.println("the maximum number is" + max);
            
           if (a < b && a < c && a < d && a < e)
                min = a ;
            else if (b < a && b < c && b < d && b < e)
                min = b ;
            else if (d < a && d < b && d < c && d < e)
                min = d ;
            else if (c < a && c < b && c < d && c < e)
                min = c ;
            else if (d < a && d < b && d < c && d < e)
                min = d ;
            else if (e < a && e < b && e < c && e < d)
                min = e ;
            
            System.out.println("the minimum number is" + min);
        }
        
    }
    the wrrors are in these lines
    a = keyboard.netxtInt ();
    b = keyboard.netxtInt ();
    c = keyboard.netxtInt ();
    d = keyboard.netxtInt ();
    e = keyboard.netxtInt ();

    PS. I know there maybe another way to do it but I want to do it this way, and please exuse the mess because I am totaly new to this forum.

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by scorpionz View Post
    Hi,
    I've been trying to write my first code ever..
    I think I somehow managed to do it but there is a compiler error and I can't figure out what it is
    So you are getting an error, but you didn't actually feel like telling us what it was?
    Quote Originally Posted by scorpionz View Post
    it seems correct to me so you might help me correct the error.
    It is generally easier to figure out what an error means if you actually include the error.

    I think the error you are getting is: "This is Java, not C!"


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Mar 2008
    Posts
    82
    excuse the wild guess, but mnemonics can't be so bad that when asking for next int, they use the method name netxtInt()? :-D

  4. #4
    Registered User
    Join Date
    May 2011
    Posts
    4
    well, I have mentioned that I am totaly new to this thing , so you may take it easy on me if you please!!
    you could've tell me nicely about the things I should include in the post and any other mistakes that I made instead of being arogant and trying to show me asa fool.
    thx anyways.

  5. #5
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    You made an account to post Java code on a C forum, and you wonder why you aren't getting the answer you want?


    Quzah.
    Hope is the first step on the road to disappointment.

  6. #6
    Registered User
    Join Date
    Mar 2008
    Posts
    82
    use nextInt() instead of netxtInt() is what I'm saying. i.e. spelling mistake!

  7. #7
    Registered User
    Join Date
    May 2011
    Posts
    4
    No I don't wonder why I didn't get the answer I want.
    I know I didn't get it because of people like you.

    Anyways you don't know the circumtances which made me post here.

    bottom line , I am sorry for my post just act like you didn't see it.
    BYE

  8. #8
    Registered User
    Join Date
    May 2011
    Posts
    4
    stabu thank you very much for you help man , I really apriciated,
    it was really a stupid mistake . I guess its because I didn't sleep until now

  9. #9
    language hopper dennis.cpp's Avatar
    Join Date
    Jan 2011
    Location
    Herborn, Hesse, Germany
    Posts
    197
    Quote Originally Posted by scorpionz View Post
    No I don't wonder why I didn't get the answer I want.
    I know I didn't get it because of people like you.
    Third post and already, it's all our fault. Wow, that's quick. You want helpful answers? Then don't act like a cry-baby because of some (obviously necessary) explicit criticism. Btw., what circumstances could possibly be the reason for posting Java questions in a C forum? Your internet provider refuses connection to every other forum on the internet?

  10. #10
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,335
    Quite.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. What is wrong with this code?
    By cornacum in forum C Programming
    Replies: 8
    Last Post: 05-03-2009, 09:51 PM
  2. what is wrong with the following code?
    By raj_ksrt in forum C Programming
    Replies: 4
    Last Post: 01-12-2009, 10:54 AM
  3. What is wrong with my code?
    By dakarn in forum C Programming
    Replies: 6
    Last Post: 10-14-2008, 05:16 AM
  4. What's wrong with my code?
    By Codefish in forum C++ Programming
    Replies: 4
    Last Post: 07-27-2005, 05:19 PM
  5. What's wrong with this code??
    By Xanth in forum C Programming
    Replies: 11
    Last Post: 12-23-2004, 01:41 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21