java scanner accepts user input

 

 

Scanner : Receive keyboard input and interact with the user

 

import java.util.Scanner;


public class TestScanner {
	
	public static void main(String[] args) {
		test2 ();
	}

	private static void test1() {
		Scanner scan = new Scanner(System.in);
		System.out.println("Please enter a parameter and enter a carriage return to end the input");
		String inputStr = scan.next();
		System.out.println("The input character is: " + inputStr);
		
	}
	
	private static void test2() {
		Scanner scan = new Scanner(System.in);
		System.out.println("Please enter the addend and enter Enter to end the input");
		int a = scan.nextInt();
		System.out.println("Please enter the summand and enter Enter to end the input");
		int b = scan.nextInt();
		System.out.println("Sum is: " + (a + b));
	}

}

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326721849&siteId=291194637