一段读取输入的简单java代码 使用了Scanner类,nextLine()读取一行,next()读取一个单词,对应着还有nextDouble()等,意思很明确,呵呵。
1
import
java.util.
*
;
2 public class test
3 {
4 public static void main(String[] args)
5 {
6 Scanner in = new Scanner(System.in);
7 System.out.println( " what is your name? " );
8 String name = in.nextLine();
9 System.out.println( " how old are you? " );
10 int age = in.nextInt();
11 System.out.println( " hello, " + name + " ,next year your age will be " + (age + 1 ));
12 }
13 }
2 public class test
3 {
4 public static void main(String[] args)
5 {
6 Scanner in = new Scanner(System.in);
7 System.out.println( " what is your name? " );
8 String name = in.nextLine();
9 System.out.println( " how old are you? " );
10 int age = in.nextInt();
11 System.out.println( " hello, " + name + " ,next year your age will be " + (age + 1 ));
12 }
13 }