0
Anyone has an example of how to use the method next() from the scanner class?
2 Antworten
+ 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);
 	}
 }
+ 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.");
 	}
 }



