Results 1 to 6 of 6
  1. #1
    soc86 is offline Member
    Join Date
    Oct 2008
    Posts
    39
    Rep Power
    0

    Default If statement, please help??

    I am also having problems with my if statement, any advise?

    public class Level{

    public static void main (String[]arg){

    int percentage;
    char grade;

    System.out.println("What percentage did you achieve?");
    percentage=UserInput.readInt;

    if (percentage >=70<100) {
    grade= 'D';
    } else if (percentage =>60) {
    grade= 'M';
    } else if (percentage =>40) {
    grade= 'P';
    } else if (percentage =>35) {
    grade= 'N';
    } else if (percentage =>0) {
    grade= 'F';
    } else if (percentage =<-1 101>) {
    grade= 'M';
    }

  2. #2
    Supamagier is offline Senior Member
    Join Date
    Aug 2008
    Posts
    384
    Rep Power
    6

    Default

    What do you want to do with these statements?
    Java Code:
    if (percentage >=70<100) 
    else if (percentage =<-1 101>)
    You should use something like this:
    Java Code:
    if (percentage >=70 && percentage < 100)
    Java Code:
    else if (percentage <= -1 || percentage > 101)
    && means AND
    || means OR
    I die a little on the inside...
    Every time I get shot.

  3. #3
    soc86 is offline Member
    Join Date
    Oct 2008
    Posts
    39
    Rep Power
    0

    Default

    Thanks, nice games by the way!!!

    now its stating illegal expression tho?

    if (percentage >=70 && <100) {
    grade= 'D';

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    what is less than 100 here?

    Understand that you have two different statements that are being checked for equality, this:

    percentage >= 70

    and this

    < 100

    You never specify exactly what is being tested to be less than 100.

  5. #5
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    7

    Default A word of advise..

    Fubarable... you may want to reconsider how much effort you put into Soc86 code/questions...
    • He/she has absolutely no idea what he/she is doing... no basic programming knowledge, much less java.
    • Suggestions given before have been ignored.

    see my comments:
    What is wrong with my switch??
    Switch help please!!!!

    I'm not saying that Soc86 shouldn't get any help, but I'm afraid what help is given will not be understood.... on top of that, I'm starting to get the idea that Soc86 might be looking for the gimme-working-code sorta stuff (I hope I'm wrong about this).

    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    Thanks for the heads-up Chris. If you're right, and he is totally lost, then his best bet would be to leave the forum and get some one-on-one help through his teacher or through tutoring.

    /Pete

Similar Threads

  1. If statement demo
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-23-2008, 08:05 PM
  2. Switch Statement Help
    By bluegreen7hi in forum New To Java
    Replies: 6
    Last Post: 02-06-2008, 05:16 AM
  3. Help with if statement
    By carl in forum New To Java
    Replies: 1
    Last Post: 08-06-2007, 07:53 AM
  4. Statement or Prepared Statement ?
    By paty in forum JDBC
    Replies: 3
    Last Post: 08-01-2007, 04:45 PM
  5. If Statement
    By aDrizzle in forum New To Java
    Replies: 4
    Last Post: 07-08-2007, 08:55 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
  •