I'm asking you a question!

Asked 2 years ago, Updated 2 years ago, 114 views

import java.util.Scanner;

public class Pro06 {

public static void main(String[] args) {
    System.out.print("Enter N:");
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    for(int i = N; i<0;i--) {
        for(int j =1; j<i+1;j++) {
            System.out.print("★");
        }
        System.out.println("");
    }
}

}

If I put 5 in the N value, I want to print out the following stars.

★★★★★

★★★★

★★★

★★

java for print-asterisk

2022-09-21 19:00

1 Answers

    int N = 5;
    for(int i = N; i > 0 ; i--) {
        for(int j = 0; j < i; j++) {
          System.out.print("★");
        }
        System.out.println("");
    }

The code itself is a way of weaving like above, but....

This type of question has the same homework solution, so I don't like to answer it on the Internet.

https://ko.wikibooks.org/wiki/%EB%B3%84_%EC%B0%8D%EA%B8%B0

If you look at these links, there are many ways to solve them, so if you don't understand, I recommend you to search and analyze them steadily by looking at various codes.


2022-09-21 19:00

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.