1.Scanner类的使用
import java.util.Scanner;
public class ScannerDemo {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
//接收一个整型数据
int i = sc.nextInt();
System.out.println(i);
//接收一个字符串
String s = sc.next();
System.out.println(s);
}
2.Random类的使用
import java.util.Random;
public class ScannerDemo {
public static void main(String[] args) {
Random ran = new Random();
int i = ran.nextInt(50);
System.out.println(i);
double d = ran.nextDouble();
System.out.println(d);
}
网友评论