2011-09-27 5 views
1
System.out.println("-----------------------------------------------------------"); 
    System.out.println("Please select a task"); 
    System.out.println("1: List employees with details"); 
    System.out.println("2: List of clients in state"); 
    System.out.println("3: List portfolio of client"); 
    System.out.println("4: Release an employee"); 
    System.out.println("5 Display stocks available for purchase/selling"); 
    System.out.println("6: Display client details"); 
    System.out.println("7: Buy Stock for client "); 
    System.out.println("0: Exit program"); 
    System.out.println("-----------------------------------------------------------" + "\n" + "\n"); 

    System.out.print("Input:"); 

    Scanner scan = new Scanner(System.in); 

    input = scan.nextInt(); 

    if (input == 1) 
     { 
     System.out.println("length of array list: " + employeeList.size()); 

     int index = 0; 
     while (index < employeeList.size()) 
      { 
      System.out.println(employeeList.get(index)); 
      index++; 
      } 
     } 
    else if (input == 2) 
     { 
     String state_choice; 
     System.out.println("Please enter the abbrivation for the state:"); 
     state_choice = scan.nextLine(); 

이것은 현재 코드에서 가져온 부분입니다. 실제로 무시합니다. 나는 이전 엔트리에서 "\ n"때문에 그것을 생각한다. 내 항목 앞에 다른 scan.nextLine()을 넣지 않고 "\ n"또는 추가 문자를 제거 할 수있는 방법이 있습니까? java 문서에서 아무 것도 볼 수 없었습니다.문자열 java null 문자 nextLine()

답변

1

input = scan.nextInt(); 뒤에 scan.nextLine();을 그냥 추가하십시오. 문제는 input = scan.nextInt(); 내에 있으며 정수만 읽으므로 scan.nextLine();을 입력하면 Enter 키를 눌러 새 줄 \n을 삭제할 수 있습니다. ;

1

는 Eng.Fouad 말했다 무엇 만 scanner.nextLine()하지 input.nextLine())

다음

내가 잘 실행 가지고 무엇 : 어쨌든, 내 잘못은 내가 그냥 고정

import java.util.ArrayList; 
import java.util.Scanner; 

public class Testing { 
    private static final ArrayList<String> employeeList = new ArrayList<String>(); 

    public static void main(String[] args) { 

     System.out.println("---------------------------------------------------------"); 
     System.out.println("Please select a task"); 
     System.out.println("1: List employees with details"); 
     System.out.println("2: List of clients in state"); 
     System.out.println("3: List portfolio of client"); 
     System.out.println("4: Release an employee"); 
     System.out.println("5: Display stocks available for purchase/selling"); 
     System.out.println("6: Display client details"); 
     System.out.println("7: Buy Stock for client "); 
     System.out.println("0: Exit program"); 
     System.out.println("---------------------------------------------------------"); 
     System.out.println("\n\n"); 

     System.out.print("Input: "); 

     Scanner scan = new Scanner(System.in); 

     int input = scan.nextInt(); 
     scan.nextLine(); 

     if (input == 1) { 
      System.out.println("length of array list: " + employeeList.size()); 

      int index = 0; 
      while (index < employeeList.size()) { 
       System.out.println(employeeList.get(index)); 
       index++; 
      } 
     } else if (input == 2) { 
      System.out.print("Please enter the abbrivation for the state: "); 
      String state_choice = scan.nextLine(); 
      System.out.println("State: " + state_choice); 

     } 

    } 
} 
+0

네 감사합니다 :) –