读取
import java.util.Scanner;
public class index{
public static void main(String[] args){
Scanner in = new Scanner(System.in);
System.out.println("What's your name?");
String name = in.nextLine();
Scanner inage = new Scanner(System.in);
System.out.println("What is your age?");
int age = inage.nextInt();
System.out.println("name:" + name);
System.out.println("age:" + age);
}
}
大数值:BigInteger
举个例子:
public class index{
public static void main(String[] args){
Scanner in = new Scanner(System.in);
System.out.println("How many numbers do you need to draw?");
int k = in.nextInt();
System.out.println("What is the highest you can draw?");
int n = in.nextInt();
BigInteger lotteryOdds = BigInteger.valueOf(1);
System.out.println(lotteryOdds);
int a = 1;
for(int i = 1; i < k; i++){
lotteryOdds = lotteryOdds.multiply(BigInteger.valueOf(n - i + 1)).divide(BigInteger.valueOf(i));
System.out.println("n - i + 1 :" + (n - i + 1));
System.out.println("i: " + i);
System.out.println("divide: " + ((n - i + 1)/i));
a = a * ((n - i + 1)/i);
System.out.println("Big : " + (BigInteger.valueOf(n - i + 1)).divide(BigInteger.valueOf(i)));
System.out.println("a: " + a);
System.out.println("lotteryOdds : " + lotteryOdds);
System.out.println("++++++++++++++++++++++==+++++");
}
System.out.println("Your odds are 1 in " + lotteryOdds + ".Good luck!");
System.out.println("a :" + a);
}
}