Advertisement
Vladkoheca

Max number.java

Oct 23rd, 2024 (edited)
7
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.56 KB | Source Code | 0 0
  1. import java.util.Scanner;
  2. public class MyClass {
  3.     public static void main(String[] args) {
  4.         Scanner sc = new Scanner(System.in);
  5.  
  6.         System.out.print("Enter how many numbers you want to compare: ");
  7.         int n = sc.nextInt();
  8.         int max = Integer.MIN_VALUE;
  9.  
  10.         for (int i = 1; i <= n; i++) {
  11.             System.out.print("Enter number " + i + ": ");
  12.             int x = sc.nextInt();
  13.  
  14.             if (x > max) {
  15.                 max = x;
  16.             }
  17.         }
  18.         System.out.println("The maximum number is: " + max);
  19.     }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement