Write a java program that deal with a number entered by the user and print the absolute value of the entered number?
Example:
Entered value = 1 output value = 1
Entered value = -1 output value = 1
Answers
Answered by
3
Note:-
To get the absolute value, use Math.abs()
Your Answer:-
import java.util.*;
public class Absolute{
public static void main (String ar []){
Scanner sc=new Scanner(System.in);
System.out.println("Enter a number");
int n=sc.nextInt();
System.out.println("Absolute value of "+n+" is "+(Math.abs(n)));
}
}
Similar questions