SHARE
TWEET

Untitled

a guest Sep 16th, 2019 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top