1.代码如下:
package com.aaa;
import java.util.Scanner;
public class Shuzi {
public static void main(String[] args) {
// 求数字的绝对值
Scanner sc=new Scanner(System.in);
while (true) {
System.out.println("请输入你要判断的数字");
double a = sc.nextDouble();
if (a >= 0) {
a = a;
} else if (a < 0) {
a = -a;
}
System.out.println("您输入的数字的绝对值为:" + a);
}
}
}
2. 运行结果图如下: