Results 1 to 14 of 14
  1. #1
    eppoair2 is offline Member
    Join Date
    Nov 2010
    Location
    Virginia
    Posts
    14
    Rep Power
    0

    Default Integer Variable

    is there a fragment of code that will test whether an integer variable score contains a valid test score. Valid test scores are in the range 0 to 100?

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,874
    Rep Power
    8

    Default

    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    eppoair2 is offline Member
    Join Date
    Nov 2010
    Location
    Virginia
    Posts
    14
    Rep Power
    0

    Default

    Hey Kevin,
    Thank you for your response.

    here is what I did: Will you consider this right ?

    import java.util.Scanner;

    public class Ismail
    {
    public static void main(String[] args)
    {

    int score;
    Scanner in= new Scanner(System.in);
    System.out.print("Enter your Score");
    score= keyboard.nextInt();

    if ( score >= 0) && ( score <= 100)


    System.out.println( "The test score is Valid.");

    else if

    system.out.println(" the test score is beyond the boundaries which are 0 and 100");
    }
    }

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,352
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by eppoair2 View Post
    else if

    system.out.println(" the test score is beyond the boundaries which are 0 and 100");
    What had your compiler to say about this?

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  5. #5
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,874
    Rep Power
    8

    Default

    Quote Originally Posted by eppoair2 View Post
    Hey Kevin,
    here is what I did: Will you consider this right ?
    Surely the compiler can tell you better whether something is right or not. I would guess it's going to complain about quite a few things though.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  6. #6
    eppoair2 is offline Member
    Join Date
    Nov 2010
    Location
    Virginia
    Posts
    14
    Rep Power
    0

    Default

    Yes, As you said the complier complained about this :
    1- cannot find symbol variable keyboard
    2- package system does not exist

  7. #7
    eppoair2 is offline Member
    Join Date
    Nov 2010
    Location
    Virginia
    Posts
    14
    Rep Power
    0

    Default Interger issue

    Yes, As you said the complier complained about this :
    1- cannot find symbol variable keyboard
    2- package system does not exist

  8. #8
    eppoair2 is offline Member
    Join Date
    Nov 2010
    Location
    Virginia
    Posts
    14
    Rep Power
    0

    Default

    Josh,
    I changed it, but I still the above error from the complier

    public class Ismail
    {
    public static void main(String[] args)
    {

    int score;
    Scanner in= new Scanner(System.in);
    System.out.print("Enter your Score");
    score= keyboard.nextInt();

    if ( score >= 0)
    {
    if ( score <= 100)


    System.out.println( "The test score is Valid.");
    }
    else
    {


    system.out.println(" the test score is beyond the boundaries which are 0 and 100");
    }
    }
    }

  9. #9
    Jonah Bron's Avatar
    Jonah Bron is offline Member
    Join Date
    Sep 2010
    Location
    California
    Posts
    26
    Rep Power
    0

    Default

    Quote Originally Posted by eppoair2 View Post
    cannot find symbol variable keyboard
    That's because you're trying to use a variable (keyboard) that doesn't exist. You want to use the in variable instead.
    Last edited by Jonah Bron; 06-23-2011 at 07:37 PM.

  10. #10
    eppoair2 is offline Member
    Join Date
    Nov 2010
    Location
    Virginia
    Posts
    14
    Rep Power
    0

    Default

    How can i fix this : How can i add this variable, so I can clear up my error

  11. #11
    Jonah Bron's Avatar
    Jonah Bron is offline Member
    Join Date
    Sep 2010
    Location
    California
    Posts
    26
    Rep Power
    0

    Default

    Quote Originally Posted by eppoair2 View Post
    How can i fix this : How can i add this variable, so I can clear up my error
    Use the "in" variable instead.

  12. #12
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,755
    Rep Power
    7

    Default

    Java Code:
    if ( score >= 0)
    {
    if ( score <= 100)
    Also, you don't need to nest if statements. The if statement you had in a previous post was almost correct. The problem was that an if statement only wants a single condition. You tried to give it two. You can get around this just like in algebra you can use brackets. Place them around the whole statement.

  13. #13
    pytho is offline Member
    Join Date
    Jun 2011
    Location
    Indiana
    Posts
    6
    Rep Power
    0

    Default

    you named your scanner 'in' on this line: Scanner in= new Scanner(System.in);

    so in the line where you do this: score= keyboard.nextInt();
    you are calling keyboard, which should be 'in'

    also, you don't need to say: int score;
    just define it this way: int score = in.nextInt();

  14. #14
    eppoair2 is offline Member
    Join Date
    Nov 2010
    Location
    Virginia
    Posts
    14
    Rep Power
    0

    Default Thank you

    I just want to thank you all for your help. People like you push me to enhance my will to learn more in Java.

    Kudos to all of you

Similar Threads

  1. Dynamic variable name based on other variable
    By nadissen in forum Eclipse
    Replies: 4
    Last Post: 05-06-2011, 06:22 PM
  2. Replies: 11
    Last Post: 07-07-2010, 06:02 AM
  3. convert unsigned integer to signed integer in java?
    By diskhub in forum New To Java
    Replies: 6
    Last Post: 05-17-2010, 12:50 AM
  4. Variable name determined by another variable's value
    By Lumpkabob in forum New To Java
    Replies: 5
    Last Post: 04-14-2009, 08:00 AM
  5. Integer vs int
    By bugger in forum New To Java
    Replies: 1
    Last Post: 11-14-2007, 09:13 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •