Solved

Please check this code if it's right.

Posted on 2008-10-05
4
142 Views
Last Modified: 2013-11-23
The question is:
The output to the screen (console/terminal window) produced by the running the following code?

and the answer would be :  "****" without double quotation marks.

is this right?


public void printStars()
{
    int n = 4;
    String s = "****";
 
    for(int row = 1; row<= n; row++)
    {
        System.out.println(s);
    }
}

Open in new window

0
Comment
Question by:bt1942
  • 2
  • 2
4 Comments
 
LVL 11

Accepted Solution

by:
Gregory Miller earned 500 total points
ID: 22644327
This will print out the following will it not...

****
****
****
****

If you want a single row or four stars you need to modify this way:
public void printStars()
{
    int n = 4;
    String s = "*";
 
    for(int row = 1; row<= n; row++)
    {
        System.out.print(s);
    }
}

Open in new window

0
 

Author Comment

by:bt1942
ID: 22644394
Technodweeb//  Hi thanks for the reply, I have one more question.
                           what code makes them become 4rows?
                           Is it the int n = 4;
0
 
LVL 11

Expert Comment

by:Gregory Miller
ID: 22644402
No, use system.out.println to add a new line after the output and use system.out.print to leave the cursor at the end of the output so that the next output will be suffixed immediately after the first.
0
 

Author Closing Comment

by:bt1942
ID: 31503172
Thanks for the comment!
0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SequenceInputStream example 3 21
ejb message driven bean mdb creation steps 2 34
Selenium docs api java index 3 63
Java program running SQL query 5 46
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question