How Do You Find the Max of a Number in Java

public static void main(String[] args) {System. out. println(“The largest number of the two numbers is ” + Math. max(num1,num2));System. out. println(“The smallest number of the two numbers is ” + Math. min(num1,num2));

How do you find the max and min of a number in Java?

  1. int[] nums={6,-1,-2,-3,0,1,2,3,4};
  2. Arrays. sort(nums);
  3. System. out. println(“Minimum = ” + nums[0]);
  4. System. out. println(“Maximum = ” + nums[nums. length-1]);

How do you find the max of two numbers in Java?

  1. public class MyMaxEx {
  2. public static void main(String[] args) {
  3. System.out.println( “Max value of 523, 456 is: ” +Math.max( 523 , 456 ));
  4. System.out.println( “Max value of 34.23, 45 is: ” +Math.max( 34.23 , 45 )); …
  5. }
Marcus Vance

Marcus Vance

Cybersecurity & Digital Privacy Researcher

Marcus Vance is a cybersecurity auditor and technology writer dedicated to educating the public about online safety, data privacy regulations, enterprise security, and emerging cyber threats.

Share this article
Twitter Facebook Pinterest