HDU 2003 绝对值

版权声明:转载请附上本文博客链接 https://blog.csdn.net/qq_42174271/article/details/85207494

import java.text.DecimalFormat;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		@SuppressWarnings("resource")
		Scanner in = new Scanner(System.in);
		while(in.hasNext()) {
			double a = in.nextDouble();
			Absolute(a);
		}

	}

	public static void Absolute(double a) {
		DecimalFormat df = new DecimalFormat("#.00");
		if (a>=0) {
			System.out.println(df.format(a));
		}else {
			String str="" + a;
			str = str.substring(1);
			double b = Double.valueOf(str);
			System.out.println(df.format(b));
		}
		
	}

}

猜你喜欢

转载自blog.csdn.net/qq_42174271/article/details/85207494