go6eto

17204 ex8

Jun 14th, 2021
721
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.*;
  2. public class ex8{
  3.  public static void main(String[] args)
  4.     {
  5.         Scanner scanner = new Scanner(System.in);
  6.         System.out.print("Input an integer number: ");
  7.         int a = scanner.nextInt();  
  8.         System.out.printf("The absolute value of %d is: %d",a, convert (a));
  9.         System.out.printf("\n");
  10.     }
  11.     public static int convert (int n)
  12.     {
  13.         int absvalue = (n >= 0) ? n : -n;
  14.         return absvalue;
  15.     }
  16. }
RAW Paste Data