求一个数的绝对值
package com.one;
import java.util.*;
/*
* This program is to find the absolute value of an unknown number;
*/
public class ifStatement {
public static void main(String[] args) {
System.out.println("Please input a num:");
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();
System.out.println("The absolute value of " + num + " is " + abs(num));
}
public static int abs(int num){
if(num>0)
return num;
else {
return -num;
}
}
}