Solved

Please check this code if it's right.

Posted on 2008-10-05
4
141 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

860 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