I made a program that I made when I was a newcomer, now in my second year. For statement again.
Conclusion: I couldn't display the triangle, so I decided to display the rectangle in order.
Please enter the height of the triangle
5
*
**
***
****
*****
****
***
**
*
I don't know how to make a triangle. .. .. I just remember having a hard time last year. For the time being, I tried to implement it so as to make a quadrangle whose length is the entered integer.
Check32.java
package practice;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Check32 {
public static void main(String[] args) {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Please enter the length of the rectangle");
String line;
try {
line = reader.readLine();
int hight = Integer.parseInt(line);
for( int i = 0; i < hight; i++) {
for (int j = 0;j < hight;j++) {
System.out.print("*");
}
System.out.println();
}
} catch (NumberFormatException e) {
System.out.println("Please enter an integer");
} catch (IOException e) {
e.printStackTrace();
}
}
}
The execution result is as follows.
Please enter the length of the rectangle
5
*****
*****
*****
*****
*****
I couldn't complete it on my own. (Although it is still in the process of completion) What kind of keyword should I search for in the first place? I was struggling even in that place. I made it by referring to this site. I learned that nesting for creates a table.
The favorite triangle will be carried over to the next.
Recommended Posts