Solved

Please check this code if it's right.

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
split53 challenge 7 96
servlet requestdispatcher include and forward differences 1 30
jdbc error in jsp application 20 45
eclipse apache tomcat admin console 52 97
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
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…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

777 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