scanner使用
import java.util.Scanner;
public class Demo{
public static void main (String[] args){
Scanner scanner = new Scanner(System.in);
System.out.println("使用nextline方式接收");
if(scanner.hasNextLine()){
String str =scanner .nextLine();
System.out.println("str");
}
scanner .close();
}
}
import java.util.Scanner;
public class Demo{
public static void(String[] args){
double sum =0;
int m=0;
while(scanner.hasNextDouble()){
double x = scanner.nextDouble();
m=m+1;
sum+=x;
System.out.println("你输入了第"+m+"个数据,然后当前结果sum="+sum);
}
System.out.println(m+"个数的和为"+sum");
System.out.println(m+"平均值为"+(sum/m)");
scanner.close();
}}
99乘法表
public class Demo{
public static void(String[] args){
for(int j=1; j<=9;j++){
for(int i =1; i<=j; i++){
System.out.print(j+"*"+i+"="+(i*j)+"\t");
}
System.out.println();
}
}}