I want to convert a number (20) into vertical lines and have those lines display a character (*) increasing by one as the lines increase.
I have:
import java.util.*;
public class increase {
public static void main(String[]args) {
Scanner input = new Scanner (System.in);
System.out.println("Please enter the rumber of rows.");
int tot = input.nextInt();
for(int rows=0; rows<=tot; rows++) {
System.out.println((rows to characters here));
}
}
}
You can achieve this by modifying your for loop to control the number of characters printed on each line:
import java.util.*;
public class Increase {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Please enter the number of rows.");
int tot = input.nextInt();
for (int rows = 1; rows <= tot; rows++) {
// Print '*' characters based on the current row number
for (int i = 1; i <= rows; i++) {
System.out.print("*");
}
// Move to the next line after printing the characters
System.out.println();
}
}
}
Can you, please, give an example of what you want? For an example, the input does not necessarily have to be 20.
something like
"*".repeat(count)
? But not clear what is meant by “rows to characters“. These whole question seem like one of the many draw a triangle pattern assignmentsTry the following, for (int i = 1; i <= 20; i++) System.out.println(“*”.repeat(i));.
The question might not be a duplicate of the question linked in the closed notice. But, this question is lacking in details, so could be closed for that reason.