Results 1 to 3 of 3

Thread: Some java help Please

  1. #1
    Join Date
    Mar 2010
    Posts
    2

    Some java help Please

    hi guys im new to this whole java thing and im taking a class on java
    my prof gave us an assignment heres the question:

    "7) Using nested for loops, write code to create the following pattern. The first row contains one star, the second three, etc. so that the 4th row contains 7 stars. (Watch out for spacing).

    *
    ***
    *****
    *******
    "
    its suppose to be a pyramid by the way but it wont let me post the exact pattern

    I need help please lol ive tried everything and i keep getting a weird triangle of stars

  2. #2
    Join Date
    May 2008
    Posts
    2,389

    Re: Some java help Please

    Hi friend,

    Please try following java code which prints the triangle of star with desired number of rows:
    Code:
    import java.io.*;
    
    class triangleDM{
      public static void main(String[] techarena)
     {
        try{
          BufferedReader obt1 = new BufferedReader(new InputStreamReader(System.in));
          System.out.println("enter number of rows");
          int a1= Integer.parseInt(object.readLine());
          for (int F=1; F<a1;F++ ){
            for (int H=1; H<=F;H++ ){
              System.out.print("*");
            }
            System.out.println("");
          }
        }
        catch(Exception e){}
      }
    }

  3. #3
    Join Date
    Mar 2010
    Posts
    2

    Re: Some java help Please

    Thanks but were not that advanced or maybe its cause im using textpad cause were suppose to be using something like:

    for(i=1;i<5;i++)
    system.out.println(i)

    and i guess a whole bunch of nested for loops

    Thank you though opaper

Similar Threads

  1. Replies: 4
    Last Post: 04-09-2013, 11:04 PM
  2. Setting Of Java to The Point At Manual Java
    By winni in forum Software Development
    Replies: 4
    Last Post: 10-01-2011, 10:05 PM
  3. Java Programming using Adventnet SNMP Java API
    By ROCKING_Suhas in forum Software Development
    Replies: 5
    Last Post: 17-07-2010, 06:52 AM
  4. Link List Example in Java Sample program in Java
    By trickson in forum Software Development
    Replies: 2
    Last Post: 04-08-2009, 08:23 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,569,149.25937 seconds with 17 queries