JcGaming

Quieta- Activity 7 Java. Finding the Largest and Smallest value from user input

Jun 7th, 2023
654
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.76 KB | Source Code | 0 0
  1. /**
  2.  * Quieta, John Carl
  3.  * CCS-1D
  4.  */
  5.  
  6. import java.util.Scanner;
  7.  
  8. public class main {
  9.     public static void main(String[] args) {
  10.         Scanner scanner = new Scanner(System.in);
  11.         int[] cat = new int[10];
  12.  
  13.  
  14.         for (int i = 0; i < cat.length; i++) {
  15.             System.out.print("Enter the value of [" + i + "]: ");
  16.             cat[i] = scanner.nextInt();
  17.         }
  18.  
  19.         int small = cat[0];
  20.         int large = cat[0];
  21.         for (int i = 1; i < cat.length; i++) {
  22.             if (cat[i] < small) {
  23.                 small = cat[i];
  24.             }
  25.             if (cat[i] > large) {
  26.                 large = cat[i];
  27.             }
  28.         }
  29.  
  30.         System.out.println("Largest is " + large + " and smallest is " + small);
  31.     }
  32. }
  33.  
Advertisement
Add Comment
Please, Sign In to add comment