SHARE
TWEET

Untitled

a guest Jul 12th, 2019 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Scanner;
  2.  
  3. public class App {
  4.  
  5.     public static void main(String[] args) throws Exception {
  6.         System.out.println("Quanti vuoi inserire?");
  7.         Scanner scan = new Scanner(System.in);
  8.         int quantity = Integer.parseInt(scan.nextLine());
  9.         int[] values = new int[quantity];
  10.         int max = -1;
  11.         for (int i = 0; i < quantity; i++) {
  12.             while (!scan.hasNextInt()) {
  13.                 scan.next();
  14.                 System.out.println("Accetto solo numeri.");
  15.             }
  16.             int input = scan.nextInt();
  17.             values[i] = input;
  18.             max = input > max ? input : max;
  19.         }
  20.         System.out.print("I numeri inseriti sono:");
  21.         for (int item : values) {
  22.             System.out.print(item);
  23.         }
  24.         System.out.println("Il piu grande era: " + max);
  25.         scan.close();
  26.     }
  27. }
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
 
Top