can anyone help me out. Im trying to get the largest among three numbers by inputting those numbers | SoloLearn: Learn to code for FREE!

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); } }

6/8/2017 4:34:53 PM

Joseph Nithish

2 Answers

New Answer

+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.

0

Neat!!! Got it @ Rrestoring faith. Thanku