Problems with else if (URGENT)


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Problems with else if (URGENT)

Hybrid View

  1. #1
    Join Date
    Oct 2004
    Location
    Chicago
    Posts
    108

    Angry Problems with else if (URGENT)

    Does anybody know what is causing errors i this code

    class grades{
    public static void main(String args[]){
    double grade = Double.valueOf(args[0]);
    String letterg;
    if(grade==0)
    {letterg = "F";}
    else if((grade>0)&&grade<0.5)
    {letterg = "D-";}

    else if(((grade)=>0.5)&&grade<1.0)
    {letterg = "D";}
    else if((grade=>1.0)&&grade<1.5)
    {letterg = "D+";}
    else if((grade>1.5)&&grade<2.0)
    {letterg = "C-";}
    else if(grade==2.0)
    {letterg = "C";}
    else if((grade>2.0)&&grade<2.5)
    {letterg = "C+";}
    else if((grade=>2.5)&&grade<3.0)
    {letterg = "B-";}
    else if(grade==3.0)
    {letterg = "B";}
    else if((grade>3.0)&&grade<3.5))
    {letterg = "B+";}
    else if((grade=>3.5)&&grade<4.0)
    {letter ="A";}
    else
    {letter ="Invalid number!"}

    System.out.println("Your grade is"+letter);
    }

    }


    Whenever i try to complie this I get:

    grades.java:10: illegal start of expression
    else if(((grade)=>0.5)&&grade<1.0)
    ^
    grades.java:31: ')' expected
    System.out.println("Your grade is"+letter);

  2. #2
    Join Date
    May 2004
    Location
    Durham, UK
    Posts
    174
    Hi Wizard,

    there was quite a few bits wrong with it, the main ones are that greater than or equal to is >= in java not =>
    few wrong var names, a missing semi colon, and I think you mean to use parseDouble rather than valueof,

    The corrected code is below - hope this helps.

    Graham

    -------------------------------------------

    class grades{
    public static void main(String args[]){
    double grade = Double.parseDouble(args[0]);

    String letterg;
    if(grade==0)
    {letterg = "F";}
    else if((grade>0)&&grade<0.5)
    {letterg = "D-";}

    else if(((grade)>=0.5)&&grade<1.0)
    {letterg = "D";}
    else if((grade>=1.0)&&grade<1.5)
    {letterg = "D+";}
    else if((grade>1.5)&&grade<2.0)
    {letterg = "C-";}
    else if(grade==2.0)
    {letterg = "C";}
    else if((grade>2.0)&&grade<2.5)
    {letterg = "C+";}
    else if((grade>=2.5)&&grade<3.0)
    {letterg = "B-";}
    else if(grade==3.0)
    {letterg = "B";}
    else if((grade>3.0)&&(grade<3.5))
    {letterg = "B+";}
    else if((grade>=3.5)&&grade<4.0)
    {letterg ="A";}
    else
    {letterg ="Invalid number!";}

    System.out.println("Your grade is"+letterg);
    }

    }

  3. #3
    Join Date
    Oct 2004
    Location
    Chicago
    Posts
    108

    Thumbs up

    Thank you very much, I finally got this to compile.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center