Results 1 to 5 of 5
  1. #1
    java greek is offline Member
    Join Date
    Sep 2009
    Posts
    4
    Rep Power
    0

    Default Help! How to make triangle with java

    AA
    BBAA
    AABBAA
    BBAABBAA
    AABBAABBAA

    using for loop

  2. #2
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    7

    Default

    What have you tried?

  3. #3
    java greek is offline Member
    Join Date
    Sep 2009
    Posts
    4
    Rep Power
    0

    Default

    Quote Originally Posted by r035198x View Post
    What have you tried?
    public class P4 {
    public static void main(String[] args) {
    int height;


    Scanner sc = new Scanner(System.in);
    System.out.print("Enter height: = ");
    height = sc.nextInt();

    for (int i=0; i<=height;i++ ){

    for (int j=0; j<i;j++ )
    {
    if (height%2 == 0)

    System.out.print("AA");
    else
    System.out.print("BB");
    }

    System.out.println("");
    }

  4. #4
    java greek is offline Member
    Join Date
    Sep 2009
    Posts
    4
    Rep Power
    0

    Default

    for

    for (int i=0; i<height;i++ ){
    if (i%2 == 0)
    System.out.print("AA");

    else
    System.out.print("BB");

    for (int j=0; j<i;j++ )
    if (j%2==0)
    System.out.print("AA");
    else
    System.out.print("BB");

    i get

    AA
    BBAA
    AAAABB

  5. #5
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    7

    Default

    Have a look at it, check the code against the output you get.
    You are allowed to change it as many times as you wish checking the effects by running it again. You'll also learn a lot during that process.

Similar Threads

  1. Help! How to make triangle with java
    By java greek in forum JCreator
    Replies: 1
    Last Post: 09-07-2009, 02:15 PM
  2. change the square to triangle java
    By anotsu in forum New To Java
    Replies: 3
    Last Post: 07-09-2009, 11:17 AM
  3. Triangle
    By jkswebsite in forum New To Java
    Replies: 8
    Last Post: 01-10-2009, 02:08 PM
  4. Java Zelda Triangle Problem
    By Hevonen in forum New To Java
    Replies: 3
    Last Post: 10-12-2008, 08:21 PM
  5. [SOLVED] How do I make a triangle?
    By Zebra in forum Java Applets
    Replies: 6
    Last Post: 05-20-2008, 02:23 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •