Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Main{
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- System.out.print("Enter size: ");
- int sz = scan.nextInt();
- int arr[] = new int[sz];
- int len = 0;
- for (int i = 0; i < sz; i++) {
- System.out.printf("Enter element %d: ", i +1);
- int tmpInt = scan.nextInt();
- if (tmpInt <= 0)
- break;
- len = i;
- arr[i] = tmpInt;
- }
- for (int i = 0; i <= len; i++) {
- if (i == 0 )
- System.out.print("[");
- System.out.print(arr[i]);
- if (i == len )
- System.out.print("]");
- else
- System.out.print(",");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment