Code
package com.company;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int min = 0;
int max = 0;
boolean first = true;
while(true) {
System.out.println("Enter Number:");
boolean isAnInt = scanner.hasNextInt();
if(isAnInt) {
int number = scanner.nextInt();
if(first) {
first = false;
min = number;
max = number;
}
if(number > max) {
max = number;
}
if(number < min) {
min = number;
}
} else {
break;
}
scanner.nextLine(); //handle input
}
System.out.println("Min = " + min + ", max = " + max);
scanner.close();
}
}
I'm not understanding this at all.... how it works... if someone wouldn't mind helping me out, i'd appreciate it, ty guys!
Mostly i don't get how it's figuring out which number is max and which is minimum value... i don't get how it's reasoning that
This post was edited by ferf on Nov 8 2018 07:37pm