0

can anyone help me out. Im trying to get the largest among three numbers by inputting those numbers

import java.util.Scanner; class program { static int num(int val1 , int val2) { if(val1>val2) { return val1 ; } else { return val2; } } public static void main(String[] args) { int x,y,z ; Scanner in = new Scanner(System.in); x=in.nextInt(); y=in.nextInt(); z= num(int val1,int val2); System.out.println(z); } }

8th Jun 2017, 4:34 PM
Joseph Nithish
Joseph Nithish - avatar
2 Respostas
+ 3
When you call the method you are creating new ints. You didn't use x or y at all. Change: z = num(int val1, int val2); To: z = num(x, y); That will get you the largest between those 2 numbers. You can just compare z with the next number to get the largest between 3 numbers.
8th Jun 2017, 5:02 PM
Rrestoring faith
Rrestoring faith - avatar
0
Neat!!! Got it @ Rrestoring faith. Thanku
8th Jun 2017, 5:14 PM
Joseph Nithish
Joseph Nithish - avatar