1. 程式人生 > >HDU 2003 絕對值

HDU 2003 絕對值

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));
		}
		
	}

}