Results 1 to 7 of 7
  1. #1
    edwed18 is offline Member
    Join Date
    Nov 2012
    Posts
    5
    Rep Power
    0

    Default Scanner and if/else problem.

    Hello,

    I am trying to create an easy program that when I insert a given point(from keyboard), the output will become a grade.

    So far my code is:

    Java Code:
    
    
    import java.util.*;
    
    public class Grade
    {
    	public static void main(String[]args)
    
       {	
    
    	Scanner input = new Scanner(System.in);
    	
            int points=input.nextlnt();
    
    	if(grade>=70)
          {
    	if(grade>=90)
    	  
            System.out.println("Excellent");
    
       else
    	System.out.println("Well done");
    	
          }
    
       else
    	System.out.println("Fail");
       }
    
    }
    The java compilator complains but I am unable to understand where my errors are. But pretty sure it´s a Syntax error.
    Last edited by edwed18; 11-12-2012 at 05:54 PM.

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default Re: Scanner and if/else problem.

    Well, what does the compiler say?
    The full error text, and highlight the line on which it occurs.

    I would also recommend indenting your code properly, as that can solve lots of unintentional errors.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    edwed18 is offline Member
    Join Date
    Nov 2012
    Posts
    5
    Rep Power
    0

    Default Re: Scanner and if/else problem.

    Here is the error code from cmd:


    C:\JavaPrograms>javac Summa.java
    Summa.java:16: error: cannot find symbol
    number=input.nextlnt();
    ^
    symbol: method nextlnt()
    location: variable input of type Scanner
    1 error

    C:\JavaPrograms>javac Summa.java
    Summa.java:16: error: cannot find symbol
    number=input.nextlnt();
    ^
    symbol: method nextlnt()
    location: variable input of type Scanner
    1 error

    Sure, I have indented my code(just minor changes). Is this enough or can I improve even more?

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default Re: Scanner and if/else problem.

    That should be nextInt().
    That's a capital 'I', not an 'l' (at least I think that's what you wrote).
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  5. #5
    edwed18 is offline Member
    Join Date
    Nov 2012
    Posts
    5
    Rep Power
    0

    Default Re: Scanner and if/else problem.

    Yes, you´re correct. Now all my programs works As for the indenting - Is there a rule or procedure I should follow? I have never thought about sorting out my programs as long as they are quite easy to read.

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default Re: Scanner and if/else problem.

    Here's the code conventions.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  7. #7
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,457
    Rep Power
    20

    Default Re: Scanner and if/else problem.

    Quote Originally Posted by edwed18 View Post
    As for the indenting - Is there a rule or procedure I should follow?
    Code Conventions for the Java Programming Language

    db

    edit I missed by seconds?
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Problem with Scanner
    By zarak in forum New To Java
    Replies: 1
    Last Post: 12-01-2011, 08:22 PM
  2. Scanner problem.
    By keo in forum New To Java
    Replies: 6
    Last Post: 04-07-2011, 09:30 AM
  3. Scanner problem
    By mkay in forum New To Java
    Replies: 2
    Last Post: 10-28-2010, 01:09 AM
  4. Problem with scanner
    By JavaJ in forum New To Java
    Replies: 6
    Last Post: 03-16-2010, 09:51 PM
  5. Problem with scanner
    By Kangaroo128 in forum New To Java
    Replies: 11
    Last Post: 09-01-2009, 09:07 AM

Posting Permissions

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