Write the definition of a method dashedLine, with one parameter, an int . If the parameter is negative or zero, the method does nothing. Otherwise it prints a complete line terminated by a newline to standard output consisting of dashes (hyphens) with the parameter’s value determining the number of dashes. The method returns nothing.

LANGUAGE: JAVA

CHALLENGE:

Write the definition of a method dashedLine, with one parameter, an int .

If the parameter is negative or zero, the method does nothing. Otherwise it prints a complete line terminated by a newline to standard output consisting of dashes (hyphens) with the parameter’s value determining the number of dashes. The method returns nothing.

SOLUTION:

The Bad News: The content you are trying to access is only available to members.

The Good News: You too can be a member, simply Click Here.

Already a member?

Posted in ,

7 Comments

  1. Clau on March 4, 2015 at 1:22 pm

    public static void dashedLine(int x)
    {
    if (x > 0)
    {
    while(x!=0)
    {
    System.out.print(“-“);
    x–;
    }
    System.out.println(“\n”);
    }
    }

  2. AQS on February 23, 2016 at 9:15 pm

    Just for posterity, this actually gives me a correct answer, as single characters generally use a single quote in the System.out.print class:

    public static void dashedLine(int x)
    {
    if (x > 0)
    {
    while(x!=0)
    {
    System.out.print(‘-‘);
    x–;
    }
    System.out.println(‘\n’);
    }
    }

  3. T on March 8, 2016 at 11:35 am

    public static void dashedLine(int a){
    if(a>0){
    for(int b=0; b < a; b++){
    System.out.print("-");
    }
    System.out.println("\n");
    }

    }

  4. jas on March 21, 2016 at 9:52 am

    public static void dashedLine(int x)
    {
    if (x > 0)
    {
    while(x!=0)
    {
    System.out.print(“-“);
    x –;
    }
    System.out.println(“\n”);
    }
    }

  5. Colby on June 2, 2016 at 11:15 am

    public void dashedLine (int a)

    {

    if (a>0)

    {

    int i;

    for (i=1;i<=a;i=i+1)

    {

    System.out.print("-");

    }

    System.out.println("");

    }

    }

  6. K on July 9, 2016 at 7:16 pm

    public static void dashedLine(int x)
    {
    if (x > 0)
    {
    while(x!=0)
    {
    System.out.print(“-“);
    x–;
    }
    System.out.println(“”);
    }
    }

  7. I on October 3, 2016 at 8:22 pm

    void dashedLine(int p){
    if (p>0){
    for(int i=0;i<p;i++){
    cout<<"-";
    }
    cout << endl;}
    }

Leave a Comment

You must be logged in to post a comment.