0

Anyone has an example of how to use the method next() from the scanner class?

20th Nov 2016, 8:04 PM
Fabiana
Fabiana  - avatar
2 ответов
+ 4
import java.util.*; class Example { public static void main(String args[]) { Scanner in =new Scanner(System.in); //defined Scanner obj System.out.println("Hello... What's Your name ?"); //get user input and store in variable named 'name' String name=in.next(); System.out.println("Hello, "+name); } }
20th Nov 2016, 8:23 PM
Sunera Avinash
Sunera Avinash - avatar
+ 2
import java.util.*; public class Example { public static void main(String [] args) { Scanner w =new Scanner(System.in); //Defining Scanner Object as w System.out.print("Enter your age: "); //get user input, store in variable "age" int age = w.nextInt(); System.out.println("You are " + age + " years old."); } }
20th Nov 2016, 8:49 PM
Emon Sen Majumder
Emon Sen Majumder - avatar