190k views
3 votes
IN JAVA

Write the definition of a method printLarger, which has two int parameters and returns nothing. The method prints the larger value of the two parameters to standard output on a single line by itself.

User Phocs
by
7.5k points

1 Answer

5 votes

Answer:

Here's an example code for the method printLarger:

public static void printLarger(int a, int b) {

int larger = a > b ? a : b;

System.out.println(larger);

}

This method takes two integer parameters, a and b, and then determines which value is larger by using a ternary operator. The larger value is then stored in the variable larger. Finally, the method prints the larger value to the console by using the println() method from the System class.

To use this method, you can simply call it from another part of your program and pass in two integer values like this:

printLarger(5, 10);

This will output 10 to the console, since 10 is the larger of the two values.

User GoalBased
by
7.7k points