Solved

Please check this code if it's right.

Posted on 2008-10-05
4
139 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
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:Technodweeb
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
compre toata in where clue oracle 4 57
maven project error 5 48
HSSFWorkbook cannot be resolved error 10 50
Apps blocked by Java 9 64
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…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
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 …

862 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

29 Experts available now in Live!

Get 1:1 Help Now