Negative numbers - what should happen? I make a break from the loop, but should it ignore ?
Maybe something else is wrong?
import java.util.Scanner;
import java.util.Scanner;
public class Solution {
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner(System.in);
int maximum = -2147483648;
int inputNumber = sc.nextInt();
while (inputNumber > 0) {
int inputMaximum = sc.nextInt();
maximum = Math.max(maximum, inputMaximum);
inputNumber--;
}
if (maximum <= 0) {
}
else {
System.out.println(maximum);
}
}
}
package com.codegym.task.task05.task0532;
/*
Task about algorithms
*/
import java.util.Scanner;
public class Solution {
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner(System.in);
int maximum = 0;
int inputNumber = sc.nextInt();
while (inputNumber > 0) {
int inputMaximum = sc.nextInt();
if (inputMaximum <= 0 || inputNumber <= 0) {
break;
}
else {
maximum = Math.max(maximum, inputMaximum);
}
inputNumber--;
}
if (maximum == 0) {
}
else {
System.out.println(maximum);
}
}
}