Practice of Java programming basics-I want to display triangles with for statements ②

I made a program that I made when I was a newcomer, now in my second year. For statement again. This is a continuation of Previous article.

Conclusion: I managed to complete it with the help of science synchronization

problem

Please enter the height of the triangle
5
*
**
***
****
*****
****
***
**
*

Implementation

I made it as follows.

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 height of the triangle");
		String line;
		try {
			line = reader.readLine();
			int hight = Integer.parseInt(line);
			for( int i = 0; i < hight; i++) {
				for (int j = 0; j < i ;j++) {
					System.out.print("*");
				}
				System.out.println();
			}
			for( int i = hight; i > 0; i--) {
				for (int j = 0; j < i; j++) {
					System.out.print("*");
				}
				System.out.println();
			}
		} catch (NumberFormatException e) {
			System.out.println("Please enter an integer");
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}

Impressions

I couldn't think of "j <i". After that, when writing a for statement, for (initial setting; end condition </ b>; continuous processing) {} I wrote that, and sometimes it didn't work as I expected.

Recommended Posts

Practice of Java programming basics-I want to display triangles with for statements ①
Practice of Java programming basics-I want to display triangles with for statements ②
I want to display images with REST Controller of Java and Spring!
Reintroduction to Java for Humanities 0: Understanding the Act of Programming
[Java] How to test for null with JUnit
I want to use java8 forEach with index
[Introduction to Java] Basics of java arithmetic (for beginners)
Initialization of for Try to make Java problem TypeScript 5-4
Java programming exercises for newcomers unpopular with active engineers
I want to display the name of the poster of the comment
[For beginners] Minimum sample to display RecyclerView in Java
Introduction to Java for beginners Basic knowledge of Java language ①
I want to transition screens with kotlin and java!
Try connecting to AzureCosmosDB Emulator for Docker with Java
I want to get along with Map [Java beginner]
How to execute WebCamCapture sample of NyARToolkit for Java
Implemented a strong API for "I want to display ~~ on the screen" with simple CQRS
How to use trained model of tensorflow2.0 with Kotlin / Java
I want to make a list with kotlin and java!
I want to make a function with kotlin and java!
Initialization with an empty string to an instance of Java String type
[Java Silver] Things to be aware of regarding switch statements
Even in Java, I want to output true with a == 1 && a == 2 && a == 3
I want to implement various functions with kotlin and java!
A memo to start Java programming with VS Code (2020-04 version)
I want to narrow down the display of docker ps
Be sure to compare the result of Java compareTo with 0
Investigated how to call services with Watson SDK for Java
[Java] I want to test standard input & standard output with JUnit
Java to play with Function
[Java] Practice of exception handling [Exception]
[Java] How to display Wingdings
Connect to DB with Java
Seasonal display with Java switch
Java while and for statements
Returning to the beginning, getting started with Java ② Control statements, loop statements
Utilization of Java array elements, for, length, value, and extended for statements
The story of Collectors.groupingBy that I want to keep for posterity
Collection of programming selection tasks to make and remember (Java basics)
[For beginners] Minimum sample to update RecyclerView with DiffUtils in Java
Source to display character array with numberPicker in Android studio (Java)
[Java] I want to perform distinct with the key in the object
How to check for the contents of a java fixed-length string
[Code Pipeline x Elastic Beanstalk] Summary of errors and countermeasures for CI / CD Java applications to Elastic Beanstalk with Code Pipeline
I'm worried about producing with JAVA and XML, so make a note of what I'm trying to do without forgetting (display in for statement)