首页 > 解决方案 > 使用 java 扫描器

问题描述

如果这看起来很新鲜,我很抱歉,但我知道我们都得从哪里开始......它阻止我把用户数据放在甜点之后,远在它之前......这是一个编辑问题

包裹扫描仪;导入 java.util.Scanner;

公共类使用扫描仪{

public static void main(String[] args) {
    // TODO Auto-generated method stub
    Scanner sc = new Scanner(System.in);
    String userName;
    int age; 
    String dessert;
    
    
    System.out.println("Hi What is your name? ");
    
     userName = sc.nextLine();
    
    System.out.println ("How are you doing, " + userName + "?");
    System.out.println ("What is you age, " + userName + "?");
    
    age = sc.nextInt();
    
    System.out.println ("Hello, " + userName +  " you are " + age);
    
    System.out.println ("ok, " + userName + " .Your are " + age + "." + " What is your favorite dessert?"); 
      
    dessert = sc.nextLine();
    
    System.out.println (" Hello, " + userName + "You are " + age + " and your favorite dessert is " + dessert);
    
    
    
    
}

}

标签: java

解决方案


age 是一个整数,使用 age = sc.nextInt();


推荐阅读