Skip to content

Instantly share code, notes, and snippets.

@shikajiro
Created July 18, 2013 14:50
Show Gist options
  • Save shikajiro/6029958 to your computer and use it in GitHub Desktop.
Save shikajiro/6029958 to your computer and use it in GitHub Desktop.
真偽型(boolean)の変数を変数名 weather、 初期値trueで、さらに 小数点型(double)の変数を変数名 temperature、 初期値を35.5 で作成してください。 もし、weatherがtrue かつ temperatureが30.0以上ならば、"今日は暑いですね"と表示させてください。それ以外の場合は "今日は涼しいですね" と表示させてください。
public class HomeWork {
public static void main(String[] args) {
boolean weather = true;
double temperature = 35.5;
if (weather == true && temperature >= 30.0) {
System.out.println("今日は暑いですね");
} else {
System.out.println("今日は涼しいですね");
}
//ちなみに変数がboolean型の場合、trueとの比較は省略できます。
// if (weather && temperature >= 30.0)
//条件式は変数と値の順番が前後しても問題はありません。
// if (weather && 30.0 <= temperature)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment