Java Program To Find Absolute Value Of Number

Write Java program to find the absolute value of the given number

// WAP to find absolute value of number

import java.util.Scanner;
public class AbsoluteValue 
{
    public static void main(String[] args)
    {
        int n,absolute;
        
        // object 'sc' created to scan data
        Scanner sc = new Scanner(System.in);
        System.out.println("Enter the value :--> ");
        n = sc.nextInt();

        absolute = Math.abs(n);

        System.out.println("Absolute value is :--> " + absolute);

    }    
}

Output:


<< Previous | Next >>


Leave a Reply

Your email address will not be published.