Results 1 to 5 of 5
  1. #1
    CYANiDE is offline Member
    Join Date
    Sep 2009
    Posts
    6
    Rep Power
    0

    Default Simple "if" statement problem....compiling error.

    Java Code:
    import java.util.Scanner;
    
    public class LazyDays
    {
    	public static void main (String[] args)
    	{
    	
    	Scanner scan = new Scanner();
    	
    	int temp;
    	
    	System.out.println ("What is the current temperature?");
    	temp = scan.nextInt();
    	
    	
    		if (temp < 20)
    			{
    			if (temp > 95)
    				{
    				System.out.println("Go visit our shops!");
    				}
    			} 
    		if (temp >= 80)
    			{
    			System.out.println("Go swimming!");
    			}
    		if (60 <= temp)
    			{
    			if (80 < temp)
    				{
    				System.out.println("Go play tennis!");
    				}
    			}
    		if (40 <= temp)
    			{
    				if (temp < 60)
    				{
    				System.out.println("Go play golf!");
    				}
    			}
    		if (temp < 40)
    			{
    			System.out.println("Go skiing!");
    			}	
    	}
    }
    Assignment says we must use cascading if statements, which is why I use them. I keep getting this error:

    Java Code:
    LazyDays.java:8: cannot find symbol
    symbol  : constructor Scanner()
    location: class java.util.Scanner
    	Scanner scan = new Scanner();
    				   ^

  2. #2
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    If you want to use it to read from standard input then provide it as argument to the constructor
    new Scanner(System.in);

  3. #3
    xcallmejudasx's Avatar
    xcallmejudasx is offline Senior Member
    Join Date
    Oct 2008
    Location
    Houston, TX & Flint, MI
    Posts
    609
    Rep Power
    7

    Default

    new Scanner(System.in)
    Liberty has never come from the government.
    Liberty has always come from the subjects of government.
    The history of liberty is the history of resistance.
    The history of liberty is a history of the limitation of governmental power, not the increase of it.

  4. #4
    xcallmejudasx's Avatar
    xcallmejudasx is offline Senior Member
    Join Date
    Oct 2008
    Location
    Houston, TX & Flint, MI
    Posts
    609
    Rep Power
    7

    Default

    ahh damn too slow :(
    Liberty has never come from the government.
    Liberty has always come from the subjects of government.
    The history of liberty is the history of resistance.
    The history of liberty is a history of the limitation of governmental power, not the increase of it.

  5. #5
    CYANiDE is offline Member
    Join Date
    Sep 2009
    Posts
    6
    Rep Power
    0

    Default

    YUP! Thanks! Can't believe I missed that.

    After testing, I realized I needed to make some changes to make it work as it should.

    Final code.

    Java Code:
    import java.util.Scanner;
    
    public class LazyDays
    {
    	public static void main (String[] args)
    	{
    	
    	Scanner scan = new Scanner(System.in);
    	
    	int temp;
    	
    	System.out.println ("What is the current temperature?");
    	temp = scan.nextInt();
    	
    	
    		if (temp < 20)
    			{
    			System.out.println("Go visit our shops!");
    			}
    		if (temp > 95)
    			{
    			System.out.println("Go visit our shops!");
    			}
    		if (temp >= 80)
    			{
    			System.out.println("Go swimming!");
    			}
    		if (temp >= 60)
    			{
    			if (temp < 80)
    				{
    				System.out.println("Go play tennis!");
    				}
    			}
    		if (temp >= 40)
    			{
    				if (temp < 60)
    				{
    				System.out.println("Go play golf!");
    				}
    			}
    		if (temp < 40)
    			{
    			System.out.println("Go skiing!");
    			}	
    	}
    }
    Thanks J-F!

Similar Threads

  1. Replies: 1
    Last Post: 06-30-2009, 03:32 PM
  2. Replies: 3
    Last Post: 05-25-2009, 09:50 PM
  3. Replies: 0
    Last Post: 03-16-2009, 12:53 AM
  4. Can't get my "if" statement to read user input
    By daletron3030 in forum New To Java
    Replies: 7
    Last Post: 01-16-2009, 06:24 AM
  5. Replies: 1
    Last Post: 10-20-2008, 08:35 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
  •