Advertisement
grodek118

Greatest in list

May 26th, 2022
738
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.company;
  2.  
  3.  
  4. import java.util.ArrayList;
  5. import java.util.Scanner;
  6.  
  7. public class Main {
  8.     public static void main(String[] args) {
  9.         Scanner scanner = new Scanner(System.in);
  10.         ArrayList<Integer> numbers = new ArrayList<>();
  11.  
  12.         while (true) {
  13.             int input = Integer.valueOf(scanner.nextLine());
  14.  
  15.             if (input == -1) {
  16.                 break;
  17.             }
  18.             numbers.add(input);
  19.         }
  20.  
  21.         int greatest = numbers.get(0);
  22.  
  23.         for (int i = 0; i < numbers.size(); i++) {
  24.             int number = numbers.get(i);
  25.             if (greatest < number) {
  26.                 greatest = number;
  27.             }
  28.         }
  29.  
  30.         System.out.println("The greatest number is " + greatest);
  31.  
  32.     }
  33. }
Advertisement
RAW Paste Data Copied
Advertisement