- Java code
public class Test{ public static void main(String[]args) { int year, month, day; System.out.println("请输入 年,月,日:"); //C代码:scanf("%d,%d,%d", &year, &month, &day); System.out.println(year+"年"+month+"月"+day+"日); }}
初学JAVA,C代码:scanf("%d,%d,%d", &year, &month, &day);
不知道在JAVA里面怎么实现?
谢谢!
------解决方案--------------------------------------------------------
Scanner scan=new Scanner(System.in);
------解决方案--------------------------------------------------------
- Java code
int year, month, day; System.out.println("请输入 年,月,日:"); Scanner scanner = new Scanner(System.in); scanner.useDelimiter("[,\r\n]"); year = scanner.nextInt(); month = scanner.nextInt(); day = scanner.nextInt(); System.out.println(year+"年"+month+"月"+day+"日");
------解决方案--------------------------------------------------------
这个也可以System.in.read();
还有就是用IO流了
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
------解决方案--------------------------------------------------------
import java.util.Scanner;
Scanner input=new Scanner(System.in);
System.out.println( "请输入名字: ");
String name=input.next();
------解决方案--------------------------------------------------------