I need to get the maximum of three ints, but my code will not give output when the second number is less than zero.
package main; import java.util.Scanner; public class Max { public static void main(String[] args) { Scanner in=new Scanner(System.in); int a=in.nextInt(); int b=in.nextInt(); int c=in.nextInt(); int max; if(a>b){ if(a>c)max =a; else max =c; } else{ if(b>c)max=b; else max=c; System.out.println(max); } } } It passed the test of other situations. Could you tell me why it happened?
List. Then by usingCollections.max()to get the largest value.