P
P
PRAIT2020-10-22 16:15:28
Java
PRAIT, 2020-10-22 16:15:28

How to remake looping java code?

package test;
public class Test {
    public static void main(String[] args) {
        int count = 10;
        int i = 0;
        while (i < count) {
            int k = 0;
            while (k < i+1) {
                System.out.print("*");
                k++;
            }
            System.out.println();
            i++;
        }
    }
}


There is a code that displays the floor of a triangle as *.
I would like the letters corresponding to the name of the variable to be displayed instead of the asterisk.
Here's an example: I get an asterisk from i and an asterisk from k, how do I get i and k instead of asterisks when looping?

i
ik
ikk

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
rageorg, 2020-10-22
@rageorg

> I would like that instead of an asterisk, the letters corresponding to the name of the variable would be displayed.
In the code, instead of an asterisk, put the letter of the corresponding variable.
https://ideone.com/v0Did5

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question