Solved

Please check this code if it's right.

Posted on 2008-10-05
4
138 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:
Technodweeb earned 500 total points
Comment Utility
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
Comment Utility
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:Technodweeb
Comment Utility
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
Comment Utility
Thanks for the comment!
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
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.

762 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now