nextInt和nexLine

 1 package day07;
 2 
 3 import java.util.Scanner;
 4 
 5 public class DemoTest02 {
 6     public static void main(String[] args) {
 7         /*nextInt和next Line方法配合使用的时候,nextline方法没有键盘录入的机会。
 8         建议:键盘录入数据,如果是字符串和整数一起接受,使用next方法接受字符串*/
 9         Scanner sc = new Scanner(System.in);
10         System.out.println("请输入整数:");
11         int num = sc.nextInt();
12         System.out.println("请输入字符串:");
13         String s = sc.nextLine();
14         System.out.println(num);
15 
16     }
17 }

执行结果:

posted @ 2021-01-08 22:18  Eleanor123  阅读(94)  评论(0编辑  收藏  举报