Last active
December 27, 2015 15:48
-
-
Save shigemk2/7350010 to your computer and use it in GitHub Desktop.
やさしいJava 5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.*; | |
class Sample1 | |
{ | |
public static void main(String[] args) throws IOException | |
{ | |
System.out.println("整数を入力してください"); | |
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | |
String str = br.readLine(); | |
int res = Integer.parseInt(str); | |
if (res == 1) | |
System.out.println("1が入力されました"); | |
System.out.println("処理を終了します"); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.*; | |
class Sample2 | |
{ | |
public static void main(String[] args) throws IOException | |
{ | |
System.out.println("整数を入力してください"); | |
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | |
String str = br.readLine(); | |
int res = Integer.parseInt(str); | |
if (res == 1) { | |
System.out.println("1が入力されました"); | |
System.out.println("1が選択されました"); | |
} | |
System.out.println("処理を終了します"); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.*; | |
class Sample3 | |
{ | |
public static void main(String[] args) throws IOException | |
{ | |
System.out.println("整数を入力してください"); | |
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | |
String str = br.readLine(); | |
int res = Integer.parseInt(str); | |
if (res == 1) { | |
System.out.println("1が入力されました"); | |
System.out.println("1が選択されました"); | |
} | |
else { | |
System.out.println("1以外が入力されました"); | |
} | |
System.out.println("処理を終了します"); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.*; | |
class Sample4 | |
{ | |
public static void main(String[] args) throws IOException | |
{ | |
System.out.println("整数を入力してください"); | |
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | |
String str = br.readLine(); | |
int res = Integer.parseInt(str); | |
if (res == 1) { | |
System.out.println("1が入力されました"); | |
System.out.println("1が選択されました"); | |
} | |
else if (res == 2) { | |
System.out.println("2が入力されました"); | |
} | |
else { | |
System.out.println("1か2を入力してください"); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.*; | |
class Sample5 | |
{ | |
public static void main(String[] args) throws IOException | |
{ | |
System.out.println("整数を入力してください"); | |
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | |
String str = br.readLine(); | |
int res = Integer.parseInt(str); | |
switch(res) { | |
case 1: | |
System.out.println("1が入力されました"); | |
break; | |
case 2: | |
System.out.println("2が入力されました"); | |
break; | |
default: | |
System.out.println("1か2を入力してください"); | |
break; | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.*; | |
class Sample6 | |
{ | |
public static void main(String[] args) throws IOException | |
{ | |
System.out.println("aかbを入力してください"); | |
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | |
String str = br.readLine(); | |
int res = str.charAt(0); | |
switch(res) { | |
case 'a': | |
System.out.println("aが入力されました"); | |
break; | |
case 'b': | |
System.out.println("bが入力されました"); | |
break; | |
default: | |
System.out.println("aかbを入力してください"); | |
break; | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.*; | |
class Sample7 | |
{ | |
public static void main(String[] args) throws IOException | |
{ | |
System.out.println("あなたは男性ですか?"); | |
System.out.println("YまたはNを入力してください"); | |
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | |
String str = br.readLine(); | |
int res = str.charAt(0); | |
if(res == 'Y' || res == 'y') { | |
System.out.println("あなたは男性ですね"); | |
} | |
else if (res == 'N' || res == 'n') { | |
System.out.println("あなたは女性ですね"); | |
} | |
else { | |
System.out.println("YまたはNを入力してください"); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.*; | |
class Sample8 | |
{ | |
public static void main(String[] args) throws IOException | |
{ | |
System.out.println("何番目のコースにしますか"); | |
System.out.println("整数を入力してください"); | |
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | |
String str = br.readLine(); | |
int res = Integer.parseInt(str); | |
// 三項演算子 | |
char ans = (res == 1) ? 'A' : 'B'; | |
System.out.println(ans + "コースを選択しました"); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SampleP1 | |
{ | |
public static void main(String[] args) | |
{ | |
int a = 0; | |
if (a >= 0 && a < 10) | |
System.out.println("ふああ"); | |
if (a != 0) | |
System.out.println("ふえええ"); | |
if (a > 10 || a == 0) | |
System.out.println("ふおおお"); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.*; | |
class SampleP2 | |
{ | |
public static void main(String[] args) throws IOException | |
{ | |
System.out.println("整数を入力してください"); | |
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | |
String str = br.readLine(); | |
int res = Integer.parseInt(str); | |
if (res % 2 != 0) { | |
System.out.println(res+"は奇数です"); | |
} | |
else { | |
System.out.println(res+"は偶数です"); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.*; | |
class SampleP3 | |
{ | |
public static void main(String[] args) throws IOException | |
{ | |
System.out.println("整数を入力してください"); | |
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | |
String str1 = br.readLine(); | |
String str2 = br.readLine(); | |
int res1 = Integer.parseInt(str1); | |
int res2 = Integer.parseInt(str2); | |
if (res1 == res2) { | |
System.out.println("2つの数は同じ値です"); | |
} | |
else if (res1 < res2){ | |
System.out.println(res1+"より"+res2+"のほうが大きい値です"); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.*; | |
class SampleP4 | |
{ | |
public static void main(String[] args) throws IOException | |
{ | |
System.out.println("0から10までの整数を入力してください"); | |
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | |
String str = br.readLine(); | |
int res = Integer.parseInt(str); | |
if (0 <= res && res <= 10) { | |
System.out.println("正解です"); | |
} | |
else { | |
System.out.println("まちがいです"); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.*; | |
class SampleP5 | |
{ | |
public static void main(String[] args) throws IOException | |
{ | |
System.out.println("成績を入力してください"); | |
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | |
String str = br.readLine(); | |
int res = Integer.parseInt(str); | |
switch(res) { | |
case 1: | |
System.out.println("もっとがんばりましょう"); | |
break; | |
case 2: | |
System.out.println("もう少しがんばりましょう"); | |
break; | |
case 3: | |
System.out.println("さらに上を目指しましょう"); | |
break; | |
case 4: | |
System.out.println("たいへんよくできました"); | |
break; | |
case 5: | |
System.out.println("たいへん優秀です"); | |
break; | |
default: | |
break; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment