Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 1 of 1

Thread: Triangle issues

  1. #1
    Junior Member
    Join Date
    Feb 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Triangle issues

    Well, recently I chose to start working on Java. So I bought this book and now, on one of the exercises it wants me to make an isosceles triangle that has spaces in between each star ( * ). I would type it out but it seems that the forum wont allow me to put the example in proper format.

    Here is what I have so far.

    package testin;
    import java.util.Scanner;
     
    public class Main {
     
        public static void main(String[] args) {
            Scanner scr = new Scanner(System.in);
            int sideSize;
     
           System.out.print("Enter size of the equal " +
           "sides in an triangle:");
           sideSize = scr.nextInt();
     
           System.out.println();
     
           for (int row=0; row<sideSize; row++)
           {
     
                  for (int col=1; col <=row; col++)
                  {
     
                         if ((col == 1) || (col == row))
                         {
     
                                System.out.print("*");
                         }
     
                  else
                  {
     
                         System.out.print(" ");
                  }
     
                  System.out.println();
           }
           for ( int col=1; col<sideSize; col++)
           {
     
                  System.out.print("*");
           }
     
           System.out.print(" ");
     
           }
    }
    }
    Last edited by helloworld922; February 24th, 2010 at 11:35 AM.


Similar Threads

  1. Triangle Printing - Java Program
    By mparthiban in forum Java Programming Tutorials
    Replies: 1
    Last Post: January 5th, 2012, 09:00 AM
  2. Equilateral Triangle Using nested for loop
    By uchizenmaru in forum Loops & Control Statements
    Replies: 2
    Last Post: January 14th, 2010, 09:01 PM
  3. Having Issues Past this
    By baGoGoodies111 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 12th, 2009, 07:19 PM
  4. Triangle Question
    By Leeds_Champion in forum What's Wrong With My Code?
    Replies: 0
    Last Post: October 29th, 2009, 11:33 PM
  5. Replies: 0
    Last Post: October 2nd, 2009, 10:51 PM