Question

Write a void method called dash, which will send in a character and an integer lenth...

Write a void method called dash, which will send in a character and an integer lenth and output a dash of char length. Ie dash('*',3) is *** in JAVA

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Hi, here's the code for the above problem

import java.util.*;

import java.lang.*;

import java.io.*;

class Ideone

{

public static void main (String[] args) throws java.lang.Exception

{

dash('*',3);

}

static void dash(char c,int n)

{

for(int i=0;i<n;i++) //loop to print char c n times

System.out.print(c);

}

}
Thumbs up if this was helpful otherwise let me know in comments.

Add a comment
Know the answer?
Add Answer to:
Write a void method called dash, which will send in a character and an integer lenth...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a Java method that searches a 2-d array for a specific character. Return the index...

    Write a Java method that searches a 2-d array for a specific character. Return the index of the first location of the character. Method header: public static void play(char c, char[][]wordSearch){ Example: a e v s l g r e d k h k q s e z j c p o a t s o v a n m n l q p f o x b The character 's' appears at index 0,3.

  • Please write this in java Write one static method to print each character in the output....

    Please write this in java Write one static method to print each character in the output. There should be methods to print: H, E, L, O, (comma), W, R, D and (exclamation point). The method to print H should be called printH() and the method to print the comma should be called printComma(). Make sure to separate characters with a new line in the method (except the comma) as shown on right. Write a method called printHelloWorld() to call the...

  • Write code in static void main method class, which creates a boolean array called flags, size...

    Write code in static void main method class, which creates a boolean array called flags, size 10, and using a for loop sets each element to alternating values (true at index zero, false at index one Write code in a static void main method class, which creates a float array called sales, size 5, uses an initializer list to instantiate its elements with positive values having two decimal places (example 7.25), and using a for loop reads those values of...

  • CPS180 Fall 2018 10 pts) Write a method as described below: Method name: drawRectangle Description: Parameters:...

    CPS180 Fall 2018 10 pts) Write a method as described below: Method name: drawRectangle Description: Parameters: 4 ( draws a rectangle with given border character, width, and height. A character borderChar An integer width An integer height If the method is called by Sample output: drawRectangle(', 4, 6) the output shape (rectangle with border char", width 4, height 6) should be as shown on the right

  • I need java code for the following problem. Lab 7: Methods 1. Write a Java program called Numbers that calls the following methods and displays the returned value: Write a method called cubelt that a...

    I need java code for the following problem. Lab 7: Methods 1. Write a Java program called Numbers that calls the following methods and displays the returned value: Write a method called cubelt that accepts one integer parameter and returns the value raised to the third power as an integer. o Write a method called randominRange that accepts two integer parameters representing a range. The method returns a random integer in the specified range inclusive. 2. o Write a method...

  • Use Java to answer the question (Occurrences of a specified character) Write a method that finds...

    Use Java to answer the question (Occurrences of a specified character) Write a method that finds the number of occurrences of a special character in a string using the following header: public static int count (String str, char a) For example, count("Welcome", 'e') returns 2. Write a test program that prompts the user to enter a string followed by a character then displays the number of occurrences of the character in the string. In addition to the requirements described in...

  • In Java, write a recursive method that converts an integer to hexadecimal. The function should print...

    In Java, write a recursive method that converts an integer to hexadecimal. The function should print out the hexadecimal character instead of returning the character. Write a test program that prompts the user to enter an integer and displays its hexadecimal equivalent.

  • Let's create a void method and call it from main. Here is what to do. Write...

    Let's create a void method and call it from main. Here is what to do. Write a void method that does not take any parameters called printFavorite. It should print your name and a favorite (subject, book, movie, etc) of yours. Call the method from main. Run and test it. For IDEs: Submit your .java file and a screenshot of the output of your code.

  • WRITTEN IN JAVA Complete the method printIndices that accepts a String source and a character search,...

    WRITTEN IN JAVA Complete the method printIndices that accepts a String source and a character search, and prints the position of each occurrence of the search value in source. For example: Input: source = "String Programming in Java is fun", search = 'i' Console Output: 3 15 19 27 Template provided from question:    public static int printIndices(String source, char search)    {    }    public static void main(String[] args)    {        System.out.println("Expected printIndices() prints indices 3...

  • 3. Write a Java method (called sumOfSquares) that reads in a sequence of integer numbers using...

    3. Write a Java method (called sumOfSquares) that reads in a sequence of integer numbers using a Scanner object. As each integer is read, the method displays that integer. The method also accumulates the sum of the squares of the integers and displays the sum when all integers are read. The method reads integers until a negative integer is read. The negative integer should not be display or added to the sum of squares. The method will not return a...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT