Reverse digits of a Number in java

Reverse digits of a Number in java

Write a program that finds out HCF of two numbers a and b.

What Is HCF?

HCF or Highest Common Factor is the greatest common divisor between two numbers.

For example:

Let there be two arbitrary numbers such as 75 and 90.

75 = 3 * 5 * 5

90 = 2 * 3 * 3 * 5

Common Divisor = 3 * 5 = 15

Here, the HCF of the three given numbers would be 15 since it divides every given number without leaving a fraction behind.

Solution of Reverse digits of a Number :–

import java.util.*;
import java.lang.*;
import java.io.*;

public class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		//your code here
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int k = sc.nextInt();
      int arr[]=new int[n];
      for(int i=0;i<n;i++)
        {
          arr[i]=sc.nextInt();
        }
      Arrays.sort(arr);
      System.out.println(arr[0]-arr[n-1]);
   }
}

Add a Comment

Your email address will not be published. Required fields are marked *