キャストする
public static void main(String[] args){ double d = 52343.231; int i = (int)d; System.out.println(i); }
[vagrant@localhost java]$ javac MyApp.java
[vagrant@localhost java]$ java Myapp
エラー: メイン・クラスMyappが見つからなかったかロードできませんでした
[vagrant@localhost java]$ java MyApp
52343
if文
public static void main(String[] args){ int score = 85; if(score > 80){ System.out.println("great"); } }
public static void main(String[] args){ int score = 85; String msg = score > 80 ? "great" : "soso..!"; System.out.println(msg); }
switch
public static void main(String[] args){ String signal = "red"; switch(signal) { case "red": System.out.println("stop!"); break; case "blue": System.out.println("go"); break; case "yello": System.out.println("caution"); break; default: System.out.println("wrong signal!"); break; } }
public static void main(String[] args){
int i = 0;
while (i < 10){
System.out.println(i);
i++;
}
}
[/java]
[vagrant@localhost java]$ java MyApp
0
1
2
3
4
5
6
7
8
9
こうも行ける。
[java]
public static void main(String[] args){
int i = 0;
do {
System.out.println(i);
i++;
}
while (i < 10);
}
[/java]
[java]
public static void main(String[] args){
for (int i = 0; i < 10; i++){
System.out.println(i);
}
}
[/java]
break, continue
[java]
public static void main(String[] args){
for (int i = 0; i < 10; i++){
if (i==5){
continue;
}
System.out.println(i);
}
}
[/java]
うおおおおおおお、短期間で詰め込んでるな