0% found this document useful (0 votes)
218 views2 pages

Triforce Printer Java

The document contains code that prints a Triforce shape based on a user-input height. It takes the height as input, validates it is between 2 and 20, then prints the Triforce using a series of loops and conditional statements. Blank spaces and "/" and "\" characters are printed to build up the shape, with an underscore line printed at the midpoint height.

Uploaded by

Makd95
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
218 views2 pages

Triforce Printer Java

The document contains code that prints a Triforce shape based on a user-input height. It takes the height as input, validates it is between 2 and 20, then prints the Triforce using a series of loops and conditional statements. Blank spaces and "/" and "\" characters are printed to build up the shape, with an underscore line printed at the midpoint height.

Uploaded by

Makd95
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

iimport java.util.

Scanner;

public class Triforce {

public static void main(String[] args) {

// TODO: Range of 2-20,


// 2h-1 blank spaces on first line
// 2h-2 length of triangle _
//
System.out.print("Enter height: ");
Scanner keyboard = new Scanner(System.in);
int h = 0;
try {
h = Integer.parseInt(keyboard.nextLine());
} catch (NumberFormatException e) {
System.out.println("\n"+"Invalid height.");
return;
}

keyboard.close();
if (h <2 || h >20) {
System.out.println("\n"+"Invalid height.");
return;
}
System.out.print("\n");
for (int line=1; line<=2*h; line++) {
if (line < h) {
for (int i = 1; i<=(2*h-line); i++) {
System.out.print(" ");
if (i == (2*h-line)) {
System.out.print("/");
if (line == 1) {
System.out.println("\\");
}
if (line>1) {
for (int j = 2*line-2;j != 0; j=j-1) {
System.out.print(" ");
if (j==1) {
System.out.println("\\");
}
}
}
}
}
} if (line ==h) {
for (int i = 1; i<=(2*h-line); i++) {
System.out.print(" ");
if (i == (2*h-line)) {
System.out.print("/");
}
}
for (int i= 1; i<= 2*line-2; i++) {
System.out.print("_");
}
System.out.println("\\");
}
if (line > h) {
for (int i = 1; i<=(2*h-line); i++) {
System.out.print(" ");
if (i == (2*h-line)) {
System.out.print("/");
}
}
if (line ==2*h) {
System.out.print("/");
}
if (line != 2*h) {
for (int r = 0; r < 2*(line-h)-2; r++) {
System.out.print(" ");
}
} else {
for (int r = 0; r < 2*(line-h)-2; r++) {
System.out.print("_");
}
}
System.out.print("\\");
if (line != 2*h) {
for (int w = 2*(2*h-line); w>0; w--) {
System.out.print(" ");
}
} else {
System.out.print("/");
for (int r = 0; r < 2*(line-h)-2; r++) {
System.out.print("_");
}
System.out.println("\\");
}
if (line != 2*h) {
System.out.print("/");
for (int r = 0; r < 2*(line-h)-2; r++) {
System.out.print(" ");
}
System.out.println("\\");
}
}
}
}
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy