0

Hii Friends.. I am new at here... I have finishied the "Basic Concepts" and "if..else.." chapter.. I want to use the user input and if else statements in one programm.. evry time some error occures.. plzz help.. Thanks..!!

8th Sep 2016, 4:36 AM
Manoj Verma
Manoj Verma - avatar
6 Réponses
+ 4
Here is an example: import java.io.InputStream; import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.print("Enter your age: "); String age = scanner.nextLine(); System.out.println(age); if (Integer.parseInt(age) < 18) { System.out.println("Hello, boy."); } else { System.out.println("Hello, mister."); } } }
8th Sep 2016, 8:31 AM
Zen
Zen - avatar
+ 1
Show your code plz
8th Sep 2016, 8:30 AM
OA-CRU
OA-CRU - avatar
0
The way zen showed it is a great example. just make sure with code playground, you import your scanner and input streamer if not it wont work.
8th Sep 2016, 10:42 AM
Aquarius
Aquarius - avatar
0
but if you use eclipse you dont need to :)
8th Sep 2016, 10:44 AM
Aquarius
Aquarius - avatar
0
Thank u friends... your replies are motivation to me to learn java...
8th Sep 2016, 11:48 AM
Manoj Verma
Manoj Verma - avatar
0
Thank u zen...
8th Sep 2016, 11:50 AM
Manoj Verma
Manoj Verma - avatar