Advertisement
irmantas_radavicius

Untitled

Feb 27th, 2022
836
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.99 KB | None | 0 0
  1. import java.util.*;
  2.  
  3.  
  4. public class Sandbox {
  5.  
  6.     public static void main(String args[]) {       
  7.         try {      
  8.             Scanner sc = new Scanner(System.in);
  9.             /*
  10.             Random rnd = new Random();
  11.            
  12.             int a = rnd.nextInt(2001) - 1000;
  13.             int b = rnd.nextInt(2001) - 1000;
  14.             int c = rnd.nextInt(2001) - 1000;
  15.             System.out.println(a);
  16.             System.out.println(b);
  17.             System.out.println(c);
  18.             */
  19.            
  20.             int [] numbers = { 0, 0, 0, 0 };
  21.            
  22.             System.out.print("Enter four numbers: ");
  23.             numbers[0] = sc.nextInt();
  24.             numbers[1] = sc.nextInt();
  25.             numbers[2] = sc.nextInt();         
  26.             numbers[3] = sc.nextInt();
  27.            
  28.             int max = Math.max(Math.max(numbers[0], numbers[1]), Math.max(numbers[2], numbers[3]));
  29.  
  30.             System.out.format("You have entered: %d %d %d %d\n",
  31.                 numbers[0], numbers[1], numbers[2], numbers[3]
  32.             );
  33.             System.out.println("Maximum is " + max);           
  34.            
  35.             sc.close();        
  36.  
  37.         } catch(Exception e){      
  38.             System.out.println("Unexpected error, sorry!");
  39.         }      
  40.        
  41.     }
  42.    
  43. }
  44.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement