# square or triangle creator

Page 1 of 1

## 3 Replies - 3772 Views - Last Post: 02 November 2009 - 08:11 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=136056&amp;s=045b6f6854f3b8256b1464e2858f4c0f&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 helpmeimnew

Reputation: 0
• Posts: 2
• Joined: 02-November 09

# square or triangle creator

Posted 02 November 2009 - 06:44 AM

square or triangle creator, i am woking on this code for a while now but cant seem to find a way to have different results of the shape each time i input different values.. can sumone guide me.. thanks a lot

package nero;

import java.io.*;
import java.util.Scanner;

class midtermShape{

private static final int Name = 0;

public static void main(String[] args) throws NumberFormatException, IOException {

Scanner scanShape = new Scanner (System.in);

int Shape;
System.out.println("san jaun college!");
System.out.println("\nChoose the shape you want to operate: ");
System.out.println("1. Square");
System.out.println("2. Triangle");
Shape = scanShape.nextInt();
Shape = Shape;

int subject2 = 0;
if (Shape == 1){
System.out.println("You chose the shape: Square");

Scanner scanSubject = new Scanner (System.in);

double subject;

System.out.println("\nChoose the Character you want to form for the square: ");
System.out.println("1. * ");
System.out.println("2. & ");
subject = scanSubject.nextDouble();
subject = subject;

if (subject == 1){
System.out.println("You chose character: * ");
try{
System.out.println("\nEnter the number: ");

for (int i = 0; i < 5; i ++ ){
for (int j=0; j>i;j++ ){
System.out.print(" * ");
}
System.out.println("****");
}
}
catch(Exception e){}

}else if(subject == 2){

System.out.println(" You chose the character: & ");
try{
System.out.println("Enter the number: ");

for (int i = 0; i < 5; i ++ ){
for (int j=0; j>i;j++ ){
System.out.print(" & ");
}
System.out.println(" &&&& ");
}
}
catch(Exception e){}

}

}else if(Shape == 2){

System.out.println("You chose the shape: Triangle");

Scanner scanSubject = new Scanner (System.in);

double subject;

System.out.println("\nWelcome to Asia Pacific College!");
System.out.println("1. * ");
System.out.println("2. & ");
subject = scanSubject.nextDouble();
subject = subject;

if (subject == 1){
System.out.println("You chose character: * ");

try{

System.out.println("Enter the number");
for (int i=1; i<B;i++ ){
for (int j=1; j<=i;j++ ){
System.out.print("*");
}
System.out.println("");
}
}
catch(Exception e){}
}

}

}else if(subject == 2){

System.out.println(" You chose the character: & ");
try{

System.out.println("Enter the number");
for (int i=1; i<B;i++ ){
for (int j=1; j<=i;j++ ){
System.out.print("*");
}
System.out.println("");
}
}
catch(Exception e){}
}

}}

thanks for the help...

This post has been edited by helpmeimnew: 02 November 2009 - 06:46 AM

Is This A Good Question/Topic? 0

## Replies To: square or triangle creator

### #2 jjsaw5

• D.I.C Lover

Reputation: 92
• Posts: 3,063
• Joined: 04-January 08

## Re: square or triangle creator

Posted 02 November 2009 - 06:46 AM

Also

### #3 helpmeimnew

Reputation: 0
• Posts: 2
• Joined: 02-November 09

## Re: square or triangle creator

Posted 02 November 2009 - 06:58 AM

square or triangle creator, i am woking on this code for a while now but cant seem to find a way to have different results of the shape each time i input different values.. can sumone guide me.. thanks a lot

```package nero;

import java.io.*;
import java.util.Scanner;

class midtermShape{

private static final int Name = 0;

public static void main(String[] args) throws NumberFormatException, IOException {

Scanner scanShape = new Scanner (System.in);

int Shape;
System.out.println("san jaun college!");
System.out.println("\nChoose the shape you want to operate: ");
System.out.println("1. Square");
System.out.println("2. Triangle");
Shape = scanShape.nextInt();
Shape = Shape;

int subject2 = 0;
if (Shape == 1){
System.out.println("You chose the shape: Square");

Scanner scanSubject = new Scanner (System.in);

double subject;

System.out.println("\nChoose the Character you want to form for the square: ");
System.out.println("1. * ");
System.out.println("2. & ");
subject = scanSubject.nextDouble();
subject = subject;

if (subject == 1){
System.out.println("You chose character: * ");
try{
System.out.println("\nEnter the number: ");

for (int i = 0; i < 5; i ++ ){
for (int j=0; j>i;j++ ){
System.out.print(" * ");
}
System.out.println("****");
}
}
catch(Exception e){}

}else if(subject == 2){

System.out.println(" You chose the character: & ");
try{
System.out.println("Enter the number: ");

for (int i = 0; i < 5; i ++ ){
for (int j=0; j>i;j++ ){
System.out.print(" & ");
}
System.out.println(" &&&& ");
}
}
catch(Exception e){}

}

}else if(Shape == 2){

System.out.println("You chose the shape: Triangle");

Scanner scanSubject = new Scanner (System.in);

double subject;

System.out.println("\nWelcome to Asia Pacific College!");
System.out.println("1. * ");
System.out.println("2. & ");
subject = scanSubject.nextDouble();
subject = subject;

if (subject == 1){
System.out.println("You chose character: * ");

try{

System.out.println("Enter the number");
for (int i=1; i<B;i++ ){
for (int j=1; j<=i;j++ ){
System.out.print("*");
}
System.out.println("");
}
}
catch(Exception e){}
}

}

}else if(subject == 2){

System.out.println(" You chose the character: & ");
try{

System.out.println("Enter the number");
for (int i=1; i<B;i++ ){
for (int j=1; j<=i;j++ ){
System.out.print("*");
}
System.out.println("");
}
}
catch(Exception e){}
}

}}

```

thanks for the help...

Mod Edit
Make sure to have the square brackets around your code tags.

### #4 ts230

Reputation: 11
• Posts: 225
• Joined: 11-July 09

## Re: square or triangle creator

Posted 02 November 2009 - 08:11 AM

So you're trying to 'paint' shapes to the console? That will not work as you thought it will most of the times.