Write a for loop that reads in 3 nonnegative integers from t
Write a for loop that reads in 3 non-negative integers from the user (one at a time) and assigns the maximum value to a variable maxVal.
Solution
ForLoop.java
import java.util.Scanner;
 public class ForLoop {
   public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int maxVal = 0;
        System.out.println(\"Enter 3 non negative integers: \");
        int n;
        for(int i=0; i<3; i++){
            n = scan.nextInt();
            if(maxVal < n){
            maxVal = n;  
            }
        }
        System.out.println(\"Max value is \"+maxVal);
    }
}
Output:
Enter 3 non negative integers:
 6 9 8
 Max value is 9

