Created
July 18, 2013 14:11
-
-
Save shikajiro/6029652 to your computer and use it in GitHub Desktop.
【解答例】
int型の配列に、次の商品の金額を入れてください。
・モスバーガー ・テリヤキチキンバーガー ・ジンジャーエール それらを全て買った場合の合計金額を表示するプログラムを書いてください。
This file contains 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
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