sc.next()
以空格为结束符
sc.nextLine()
以回车为结束符
import java.util.Scanner;
public class test0101 {
public static void main(String[] args) {
System.out.print("输入:");
Scanner sc = new Scanner(System.in);
String s = sc.next();
//String s = sc.nextLine();
System.out.println("输出:" + s);
}
}
sc.nextInt()
以空格为结束符
若录入其他符号比如",“”."会直接报错
import java.util.Scanner;
public class test0101 {
public static void main(String[] args) {
System.out.print("输入:");
Scanner sc = new Scanner(System.in);
int s = sc.nextInt();
System.out.println("输出:" + s);
}
}
sc.useDelimiter(",")
+sc.nextInt()
以逗号结束
import java.util.Scanner;
public class test0101 {
public static void main(String[] args) {
System.out.print("输入:");
Scanner sc = new Scanner(System.in);
sc.useDelimiter(",");
int s = sc.nextInt();
System.out.println("输出:" + s);
}
}
sc.useDelimiter(",")
+sc.next()
以逗号结束
import java.util.Scanner;
public class test0101 {
public static void main(String[] args) {
System.out.print("输入:");
Scanner sc = new Scanner(System.in);
sc.useDelimiter(",");
String s = sc.next();
System.out.println("输出:" + s);
}
}
sc.useDelimiter(",")
+sc.nextLine()
以回车结束
import java.util.Scanner;
public class test0101 {
public static void main(String[] args) {
System.out.print("输入:");
Scanner sc = new Scanner(System.in);
sc.useDelimiter(",");
String s = sc.nextLine();
System.out.println("输出:" + s);
}
}