我是一個新的java程序員,在我下面的代碼中,當我嘗試輸入像john smith這樣的員工姓名時,只有john被輸出打印出來。 如果我把使用掃描器類的輸入
System.out.print("Enter Employee Name: ");
String employeeName = s.next();
上述
System.out.print("Enter SEX: ");
char SEX = s.next().charAt(0);
這段代碼輸出不是要求我employeename值。並直接打印剩餘的值。
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
**package cs480;
import java.util.Scanner;
public class CS480D1_Richa_2_Week2 {
public static void main(String [] args){
Scanner s=new Scanner(System.in);
System.out.print("Ente Employee ID: ");
int employeeId = s.nextInt();
System.out.print("Ente SEX: ");
char SEX = s.next().charAt(0);
System.out.print("Ente Employee Name: ");
String employeeName = s.next();
System.out.println("Employee ID is " +employeeId);
System.out.println("Employee Name is " +employeeName);
System.out.println("Employee gender is " +SEX);
}
}**
檢查右側的'Related'部分的分隔符。你會得到你的答案 –