1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

for文を使って演習(拡張for文、二重ループ)

Posted at

問題

拡張for文で以下の配列の要素を全て出力してください。
{"まぐろ", "いくら", "うに", "さば", "いか", "ほたて"}

public static void main(String[] args) {
    String sushi[] = {"まぐろ", "いくら", "うに", "さば", "いか", "ほたて"};

    for( String stomach : sushi) {
    System.out.println(stomach);
    }
}
//演算結果
//まぐろ
//いくら
//うに
//さば
//いか
//ほたて

問題

底辺の値を受け取り 斜辺が右向きの三角形を出力してください。

public static void main(String[] args) {  
    triangle(5);
}  
 public static void triangle(int bottom) {
   	for (int i = 0; i < bottom; i++) {
       	for (int j = 0; j <= i; j++) {
   			System.out.print("〇");
   		}
   		System.out.println(" ");
   	}
}

//演算結果
//〇 
//〇〇 
//〇〇〇 
//〇〇〇〇 
//〇〇〇〇〇 

1
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?