Results 1 to 5 of 5
- 10-14-2009, 09:43 PM #1
Member
- Join Date
- Sep 2009
- Posts
- 6
- Rep Power
- 0
Simple "if" statement problem....compiling error.
Assignment says we must use cascading if statements, which is why I use them. I keep getting this 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!"); } } }
Java Code:LazyDays.java:8: cannot find symbol symbol : constructor Scanner() location: class java.util.Scanner Scanner scan = new Scanner(); ^
- 10-14-2009, 09:51 PM #2
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
If you want to use it to read from standard input then provide it as argument to the constructor
new Scanner(System.in);
- 10-14-2009, 09:51 PM #3
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.
- 10-14-2009, 09:52 PM #4
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.
- 10-14-2009, 09:56 PM #5
Member
- Join Date
- Sep 2009
- Posts
- 6
- Rep Power
- 0
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.
Thanks J-F!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!"); } } }
Similar Threads
-
Compiling/Running Project in Command Line: "Could not find main class" Error
By Yasemin Gokce in forum New To JavaReplies: 1Last Post: 06-30-2009, 02:32 PM -
[SOLVED] Why does the compiler return "not a statement" for this method body please?
By trueblue in forum New To JavaReplies: 3Last Post: 05-25-2009, 08:50 PM -
"Cached Item Was Locked" causing Select Statement: Hibernate + EHCache
By cloutierm in forum Advanced JavaReplies: 0Last Post: 03-15-2009, 11:53 PM -
Can't get my "if" statement to read user input
By daletron3030 in forum New To JavaReplies: 7Last Post: 01-16-2009, 05:24 AM -
the dollar sign "$", prints like any other normal char in java like "a" or "*" ?
By lse123 in forum New To JavaReplies: 1Last Post: 10-20-2008, 07:35 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks