Java学习日志2

First Post:

Last Update:

Word Count:
190

Read Time:
1 min

今天基本从头到尾复习了下C的语法(与Java通用)

面向对象的新输入方式:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
/**
* @author OliverChen
*/
public class KeyIn {
public static void main(String[] args) {
java.util.Scanner s = new java.util.Scanner(System.in);
System.out.println("请输入一个数字");
int i = s.nextInt();
System.out.println("您输入的数字为" + i);
System.out.println("请输入您的名字");
String str = s.next();
System.out.println("您好!" + str);
}
}

或者是

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import java.util.Scanner;
/**
* @author OliverChen
*/
public class KeyIn {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
System.out.println("请输入一个数字");
int i = s.nextInt();
System.out.println("您输入的数字为" + i);
System.out.println("请输入您的名字");
String str = s.next();
System.out.println("您好!" + str);
}
}