LoginSignup
1
1

More than 5 years have passed since last update.

Java SE 7/8 Bronzeを勉強した中で詰まったところ

Posted at

整数同士の演算では小数点以下は切り捨てられる

System.out.println(5/2);

//出力結果:2

小数の型はswitch文の条件にはつかえない

double num = 2.5 ;

switch(num){
    case 2.5:
        System.out.println("2.5");
        break;

    default:
        System.out.println("2.5以外");
        break;
}
//コンパイルエラー
//互換性のない型:doubleからintへの不可逆変換

for文で無限ループ

for文の条件式を抜くことで無限ループになる

for(int i=0;/*この部分*/;i++){ 
    System.out.print(i);
}
//出力結果:012345678910........ 
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1