1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Readme [11.4K]
3 years ago
11

TASK: Write a static method called repeatString that takes as input a String parameter word followed by an int parameter num. It

should return a String that would be the result of repeating word exactly num times. If num is 0 or negative, the method should output an empty string.
HINT: Don't print out anything! Your method should return a string, not print it. print the output of your method behind the scenes to check that your method returns the right string; if you add your own print statements then the output won't be correct.


HINT: Make use of String concatenation!
Computers and Technology
1 answer:
leva [86]3 years ago
6 0

Answer:

Follows are the method definition to this question:

public static String repeatString(String word, int num)//defining a String method repeatString that takes two parameters

{

   String Val= "";//defining String variable Val

   for(int x = 0;x<num;x++)//defining for loop to calculate number of string

   {

       Val=Val+word;//hold calculated value in Val

   }

   return Val;//return Val value

}

Explanation:

Follows are the full code to this question:

import java.util.*;//import package for user input

public class Main//defining class Main

{

   public static String repeatString(String word, int num)//defining a String method repeatString that takes two parameters

{

   String Val= "";//defining String variable Val

   for(int x = 0;x<num;x++)//defining for loop to calculate number of string

   {

       Val=Val+word;//hold calculated value in Val

   }

   return Val;//return Val value

}

public static void main(String[] ar)//defining main method

{

   int num;//defining integer variable

   String word; //defining String variable

   Scanner on=new Scanner(System.in);//creating Scanner class Object

   System.out.print("Enter numeric value: ");//print message

   num=on.nextInt();//input value

   System.out.print("Enter String value: ");//print message

   word=on.next();//input value

   System.out.print(repeatString(word,num));//call method and print its return value

}

}

Output:

Enter numeric value: 3

Enter String value: data

datadatadata

Description:

Inside the main class,  a static string method "repeatString" is defined that accepts two parameters "word and num", in which one is a string and one is an integer.

Inside the method, the string variable "Val" is defined, which uses the "for" loop to calculate the number of string and store its value in the variable.

In the main class, the above two variables are defined, that uses the Scanner class object for input the value and pass into the method and print its value.

You might be interested in
You are setting up your Windows computer to connect to the Internet and notice that when you type www.microsoft, the browser doe
Harrizon [31]

Answer:

Check your DNS settings

Explanation:

Different errors may occur when setting up your computer to connect to the internet, one of which is described in the question above.

The DNS (Domain Name System) is responsible for redirecting domain names to their physical IP address. Instead of remembering every IP address of sites you visit frequently, domain names are used for easy remembrance, the DNS makes the matching of domain names to IP addresses possible.

To change your DNS setting follow these steps:

  1. Click settings from your start menu
  2. Click on Network and Internet
  3. Look to the bottom of the main page and click on "Network and Sharing Center"
  4. On the left tab, click "Change adapter settings"
  5. Right Click on the current network you are using and select properties
  6. Left-click on the "Internet Protocol Version 4 (TCP/IPv4) and click on properties.
  7. Check to see if "Obtain DNS server address automatically" is selected, if it is selected,
  8. Click on the radio button under it "Use the following DNS server address"
  9. Enter the DNS address you want to use
  10. Click Ok and close the window.

The problem should be resolved.

4 0
3 years ago
If the list [8,1,4,2,10,0] is sorted with the selection sort algorithm, what is the list at the 4th step of the algorithm?
Savatey [412]

Answer:

The answer to this question is given below in the explanation section.

Explanation:

The selection sort algorithm step started from 0, and continue till the sorting is done.

The correct answer after selection sort algorithm at the 4th step is:D

[0,1,2,4,8,10].

The complete detail of step by step execution is shown in the attached document file.

Download docx
5 0
2 years ago
Why won't my ads load brainly? Is anyone else having this problem? Brainly company or whoever you are that is running this websi
djverab [1.8K]

No I have not had that do that to me before It has always loaded my ads and sent me right back to the answer

7 0
3 years ago
Read 2 more answers
Please help me with these short questions &gt;..
Thepotemich [5.8K]

Answer:

bmjcmbbobnkpkkjkbk

Explanation:

vuvkopbbkvkhovjlplbkp

6 0
2 years ago
Which of the following is false? A. The last element of an array has position number one less than the array size. B. The positi
Veseljchak [2.6K]

Answer:

C.A subscript cannot be an expression

Explanation:

The option C (A subscript cannot be an expression) is false

3 0
3 years ago
Other questions:
  • Software license infringement is also often called software __________.
    11·2 answers
  • How does an employer judge a candidate?<br> The employer judge's the candidate's ? for a job.
    12·1 answer
  • Each computer or device on a network is called a(n) ______.
    7·1 answer
  • What is VoIP?
    5·1 answer
  • When performing actions between your computer and one that is infected with a virus, which of the following offers NO risk of yo
    11·2 answers
  • Define a class, addresstype, that can store a street address, city, state, and zip code. use the appropriate functions to print
    11·1 answer
  • Which programming element is used by a game program to track and display score information
    12·2 answers
  • Partes de la ventana principal de Microsoft excel 2013 con sus respectivas funciones
    14·1 answer
  • In what decade was photography invented? the 1800s the 1820s the 1840s the 1860s
    15·1 answer
  • 7. Suppose that a RISC machine uses 5 register windows. a. How deep can the procedure calls go before registers must be saved in
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!