5
5

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 5 years have passed since last update.

柴田望洋著 Javaによるアルゴリズムとデータ構造の誤植

Last updated at Posted at 2014-03-15
import java.util.Scanner;

public class TriSample {
	public static void main(String[] args){
		
		Scanner scan = new Scanner(System.in);
		
		System.out.println("数値を入力してください。");
		
		int n;
		
		do {
			System.out.print("段数は:");
			n = scan.nextInt();
		} while (n <= 0);
		
		for(int i = 1; i <= n; i++){
			for(int j = 1; j <= i; j++){
				System.out.print('*');
				System.out.println(); //ここが間違ってる
			}
			
		}
	}
}

というわけで自分が作成した三角形を表示させるアルゴリズムを載せておきます

import java.util.Scanner;

public class TriSample {
	public static void main(String[] args){
		
		Scanner scan = new Scanner(System.in);
		
		System.out.println("数値を入力してください。");
		
		int n;
		
		do {
			System.out.print("段数は:");
			n = scan.nextInt();
		} while (n <= 0);
		
		for(int i = 1; i <= n; i++){
			for(int j = 1; j <= i; j++){
				System.out.print('*');				
			}
			System.out.println();
			
		}
		scan.close();
	}
}
5
5
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
5
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?