1. 程式人生 > >Java練習 SDUT-1117_求絕對值(選擇結構)

Java練習 SDUT-1117_求絕對值(選擇結構)

close 結構 sample memory 實驗 ext else java練習 put

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

Time Limit: 1000 ms Memory Limit: 65536 KiB

Problem Description

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

Input

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

Output

輸出它的絕對值。

Sample Input

-4

Sample Output

4

超級水題

import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner cin = new Scanner(System.in);
        int n;
        n = cin.nextInt();
        if(n<0)
            System.out.println(-n);
        else
            System.out.println(n);
        cin.close();
    }
}

Java練習 SDUT-1117_求絕對值(選擇結構)