1. 程式人生 > >1117-C語言實驗——求絕對值(選擇結構)-JAVA

1117-C語言實驗——求絕對值(選擇結構)-JAVA

C語言實驗——求絕對值(選擇結構)

Time Limit: 1000 ms Memory Limit: 65536 KiB

Problem Description

從鍵盤上輸入任意一個整數,然後輸出它的絕對值!

Input

從鍵盤上輸入任意一個整數。

Output

輸出它的絕對值。

Sample Input

-4

Sample Output

4

Hint

Source

import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		while (scanner.hasNext()) {
			int n = scanner.nextInt();
			System.out.println(Math.abs(n));
		}
	}
}