public class scanner {
public static void main(String[] args) {
//创建一个扫描器对象,用于接受数据
Scanner scanner=new Scanner(System.in);
System.out.println("使用next方式接收:");
//判断是否输入
if (scanner.hasNext()){
String str=scanner.next();//next不能得到带有空格的字符串,直到空格世界结束
String str1=scanner.nextLine();//直到回车之前都可以接受
System.out.println(str);
System.out.println(str1);
}
scanner.close();
}
}
import javax.sound.midi.Soundbank;
import java.util.Scanner;
public class scanner_num {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int num = 0;
double sum = 0;
while (scanner.hasNextDouble()) {
num += 1;
double b = scanner.nextDouble();
sum += b;
System.out.println("当前总和为:" + sum);
}
if (num==0){
System.out.println("无");
}
else {
System.out.println(n/m);
}
System.out.println(n);
scanner.close();
}
}
字符串内容的相同可用 s.equals判断。返回值为true or false ,地址相同可用==判断。
public class switch_project {
public static void main(String[] args) {
Scanner scanner=new Scanner(System.in);
String get=scanner.nextLine();
//switch穿透特性,若不break,则符合条件的case后,全部输出。且字符串的比较是在JKD7以后的功能
switch (get){
case "Hello":
System.out.println("对喽");
//break;
case "wdo":
System.out.println("xua");
break;
}
}
}
for循环
输出9*9乘法表
public class nine_nine {
public static void main(String[] args) {
for (int i = 1; i <= 9; i++) {
for (int i1 = 1; i1 <= i; i1++) {
System.out.print(i+"*"+i1+"="+(i1*i)+"\t");
}
System.out.println();
}
}
}