Advertisement
Guest User

Untitled

a guest
Sep 16th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.Scanner;
  3.  
  4. public class Homework17 {
  5.  
  6. public static void main(String[] args) {
  7.  
  8. ArrayList list = new ArrayList();
  9.  
  10. Scanner scanner = new Scanner(System.in);
  11. System.out.println("請輸入數字,但輸入-1會中止");
  12.  
  13. int userInput = scanner.nextInt();
  14. while(userInput != -1) {
  15. list.add(userInput);
  16. userInput = scanner.nextInt();
  17. }
  18. System.out.println("中止,顯示輸入所有數字");
  19.  
  20. for(int i=0 ; i < list.size();i++) {
  21. System.out.print(list.get(i)+" ");
  22. }
  23.  
  24.  
  25. }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement