Computer Science, asked by ziadalsaydia, 3 months ago

Write a java program that deal with a number entered by the user and print the absolute value of the entered number? (0.znark) Example: Entered value 1 output value =1 output value=1 %3D Entered value = -1

Answers

Answered by BrainlyProgrammer
4

Corrected Question:-

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

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