Skip to content

Instantly share code, notes, and snippets.

@mokomokohitsuzi
Created October 9, 2016 13:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mokomokohitsuzi/5f2ffa083fd6398cb9820e8600b4010a to your computer and use it in GitHub Desktop.
Save mokomokohitsuzi/5f2ffa083fd6398cb9820e8600b4010a to your computer and use it in GitHub Desktop.
新・明解Java入門 演習3-1
import java.util.Scanner;
public class En3_1 {
public static void main(String[] args) {
Scanner stdIn = new Scanner(System.in);
System.out.print("絶対値:");
int zettai = stdIn.nextInt();
// 入力された数字が-の場合、-をかける。
if (zettai < 0) {
zettai = -zettai;
}
System.out.println("その絶対値は" + zettai + "です。");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment