F How to find Absolute Number in Java with user input? | CodeTheta

How to find Absolute Number in Java with user input?

June 06, 2017

In Java you can easily find Absolute Number with user input. Follow the below code :

Code :
import java.util.Scanner;
public class Absolute_Number {
public static void main(String[] args) {
    int Number;
    System.out.println("Enter The Negative or Positive Number: ");
    Scanner in = new Scanner(System.in);
    Number = in.nextInt();
    if (Number < 0)
    {
      Number = (-1)* Number;
    }
    System.out.println("Result is: "+ Number);
    }
}

Output :
Enter The Negative or Positive Number: -230
Result is: 230

IDE Used To Test This Code : Dr. Java

Try this code in your computer for better understanding. Enjoy the code. If you have any Question you can contact us or mail us.We will reply you as soon as possible.

Post a Comment