square or triangle creator

i am woking on this code for a while now but cant seem to find a way t

Page 1 of 1

3 Replies - 3772 Views - Last Post: 02 November 2009 - 08:11 AM Rate Topic: -----

#1 helpmeimnew   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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;

BufferedReader object = new BufferedReader(new InputStreamReader(System.in));

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: ");

int A= Integer.parseInt(object.readLine());
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: ");

int A= Integer.parseInt(object.readLine());
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("\nChoose your character to form your shape: ");
System.out.println("1. * ");
System.out.println("2. & ");
subject = scanSubject.nextDouble();
subject = subject;

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


try{

BufferedReader object2 = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the number");
int B= Integer.parseInt(object.readLine());
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{

BufferedReader object2 = new BufferedReader(new InputStreamReader(System.in));

System.out.println("Enter the number");
int B= Integer.parseInt(object2.readLine());
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   User is offline

  • D.I.C Lover
  • member icon

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

Re: square or triangle creator

Posted 02 November 2009 - 06:46 AM

Please do not post your question in the heading of your post. Make another post and include your question/issue.

Also :code:
Was This Post Helpful? 0
  • +
  • -

#3 helpmeimnew   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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;

BufferedReader object = new BufferedReader(new InputStreamReader(System.in));

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: ");

int A= Integer.parseInt(object.readLine());
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: ");

int A= Integer.parseInt(object.readLine());
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("\nChoose your character to form your shape: ");
System.out.println("1. * ");
System.out.println("2. & ");
subject = scanSubject.nextDouble();
subject = subject;

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


try{

BufferedReader object2 = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the number");
int B= Integer.parseInt(object.readLine());
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{

BufferedReader object2 = new BufferedReader(new InputStreamReader(System.in));

System.out.println("Enter the number");
int B= Integer.parseInt(object2.readLine());
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.
Was This Post Helpful? 0
  • +
  • -

#4 ts230   User is offline

  • D.I.C Head

Reputation: 11
  • View blog
  • 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.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1