Q BgQuestion:

      
Pupil
Karma Points: 55
Respect (99%):
posted by  Ruger_Mk2 on 11/3/2009 4:25:04 PM  |  status: Closed  |  Earned Karma: 55

Java Question Help PLZ!!! ASAP

Course Textbook Chapter Problem Needs by
N/A N/A N/A N/A 11/3/2009 at 11:00:00 PM
Question Details:
Write a program to print the pattern below to the screen.  Remember to use
descriptive variable names.  You will not need to take input from the user.  Use loops
and as few System.out statements as possible to accomplish the print of the pattern.  
Name the .java file Lab7_Ex3.
 
*
**
***
****
*****
 
Bonus Point Alert! Earn +15 additional karma points for helping this platinum member.

AAnswers:

Answer Question Ask for clarification
Pupil
Karma Points: 74
posted by noo on 11/3/2009 6:23:54 PM  |  status: Live
Asker's Rating: Helpful   
Response Details:
public class lab7_Ex3{
 
  public static void main(String[]args){
    for (int i=1; i <=5; i++){
      for (int j=1; j<=i; j++){
        System.out.print("*");
      }
      System.out.println();
    }
  }
}
Oracle
Karma Points: 18,830
posted by Marth on 11/3/2009 6:27:15 PM  |  status: Live
Asker's Rating: Lifesaver   
Response Details:
Let us write a helper method to print the star picture with a given height:


public static void printStars(int height)
{
      for(int row = 0; row < height; row++)
      {
            for(int col = 0; col <= row; col++)
            {
                  System.out.print('*');
            }
            // newline
            System.out.println();
      }
}


The height in the example is 5 - so we will use that in our main method.

public static void main(String[] args)
{
      printStars(5);
}


Thank you for rating my response. Feel free to PM me if you have further questions.

Java Genius

"Lois Lane is falling, accelerating at an initial rate of 32ft per second per second. Superman swoops down to save her by reaching out two arms of steel. Ms. Lane, who is now traveling at approximately 120 miles per hour, hits them, and is immediately sliced into three equal pieces." - Sheldon
Answer Question Ask for clarificarion

Join Cramster's Community

Cramster.com brings together students, educators and subject enthusiasts in an online study community. With around-the-clock expert help and a community of over 100,000 knowledgeable members, you can find the help you need, whenever you need it. Join for free today » How Cramster is different from tutoring »