Skip to content

Instantly share code, notes, and snippets.

@shikajiro
Created July 18, 2013 14:11
Show Gist options
  • Save shikajiro/6029652 to your computer and use it in GitHub Desktop.
Save shikajiro/6029652 to your computer and use it in GitHub Desktop.
【解答例】 int型の配列に、次の商品の金額を入れてください。 ・モスバーガー ・テリヤキチキンバーガー ・ジンジャーエール それらを全て買った場合の合計金額を表示するプログラムを書いてください。
public class HomeWork {
public static void main(String[] args) {
int[] menu = new int[3];
menu[0] = 320;
menu[1] = 320;
menu[2] = 210;
int total = 0;
for (int i = 0; i < menu.length; i++) {
total += menu[i];
}
//もちろん拡張for文を使ってもOK
// for (int i : menu) {
// total += i;
// }
System.out.println("合計は" + total + "円です。");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment