Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок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); } }
2 ответов
+ 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