将输入重定向到控制台读取
/** from n o w j a v a . c o m**/ import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); int val; System.out.print("Enter an integer please:"); val = keyboard.nextInt(); val *= val; // squared the input value System.out.println("Squared value=" + val); } }