Make a rhombus using Java

I think there is a better way ...


public class ex3 {
	public static void main(String[] args) {
		int i, j;
		int max = 5;
		int p = max / 2 + 1;
		int left = p;
		int right = p;

		for (i = 1; i <= max; i++) {
			for (j = 1; j <= max; j++) {
				if (j >= left && j <= right) {
					System.out.print("*");
				} else {
					System.out.print(" ");
				}
			}
			System.out.println();
			if (i < p) {
				left--;
				right++;
			} else {
				left++;
				right--;
			}
		}
	}
}

Execution result

sample.png

Recommended Posts

Make a rhombus using Java
[Java] Make it a constant
How to make a Java container
Upload a file using Java HttpURLConnection
Create a Java project using Eclipse
How to make a Java array
How to make a Java calendar Summary
How to make a Discord bot (Java)
[Java] Let's make a DB access library!
How to make a groundbreaking diamond using Java for statement wwww
Java beginner tried to make a simple web application using Spring Boot
I tried to make a talk application in Java using AI "A3RT"
I did Java to make (a == 1 && a == 2 && a == 3) always true
I wanted to make (a == 1 && a == 2 && a == 3) true in Java
Create Scala Seq from Java, make Scala Seq a Java List
Try to make a music player using Basic Player
Ssh connect using SSHJ from a Java 6 app
Sorting using java comparator
Make Blackjack in Java
[Java] Create a filter
Scraping practice using Java ②
Make a reflection utility ②
Make a reflection utility ③
Scraping practice using Java ①
Create a portfolio app using Java and Spring Boot
Make "I'm not a robot" in Java EE (Jakarta EE)
Studying java8 (such as reading a file using Stream)
[Personal memo] Make a simple deep copy in Java
Let's make a robot! "A simple demo of Java AWT Robot"
I tried using Log4j2 on a Java EE server
Using the database (SQL Server 2014) from a Java program 2018/01/04
How to convert A to a and a to A using AND and OR in Java
Try to build a Java development environment using Docker
I tried scraping a stock chart using Java (Jsoup)
A note about Java GC
Try using RocksDB in Java
Let's make a calculator application in Java ~ Display the application window
Java --How to make JTable
[Beginner] Try to make a simple RPG game with Java ①
Refactoring: Make Blackjack in Java
[Beginner] android app that rolls a ball using a sensor [Java]
Create a java method [Memo] [java11]
I want to make a list with kotlin and java!
I just wanted to make a Reactive Property in Java
I want to make a function with kotlin and java!
[Java] Create a temporary file
Find a subset in Java
I tried using Hotwire to make Rails 6.1 scaffold a SPA
What is a Java collection?
[Java] Draw a simple pattern
Using Mapper with Java (Spring)
I tried using Java REPL
Try Hello World using plain Java on a Docker container
Socket communication with a web browser using Java and JavaScript ②
I tried to make a client of RESAS-API in Java
Using Docker from Java Gradle
Socket communication with a web browser using Java and JavaScript ①
Java creates a Word document
Create a MOB using the Minecraft Java Mythicmobs plugin | Preparation 1
A Simple CRUD Sample Using Java Servlet / JSP and MySQL
Bubble sort using ArrayList (JAVA)