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]
4 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]4 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
Should a waiting thread receive priority over a thread first attempting to enter a monitor? What priority scheme, if any, should
nadezda [96]

Answer:

Yes, thread should have a priority level. Threads are scheduled to run based on their scheduling priority. Each thread is assigned a scheduling priority. The priority levels range from zero (lowest priority) to 31.

Explanation:

Threads generally are given different kinds of priorities based on the types of work the threads will be used for. This is normally known as scheduling and it is a vital procedure in thread prioritization. The standard priority levels for every thread is from the lowest priority which is typically '0' and the highest priority which is approximately 31.

6 0
3 years ago
Changes in computer technology have an effect on _____. computer scientists only people who work with computers only everybody p
luda_lava [24]
Changes in computer technology have an effect on <span>everybody.</span>
6 0
4 years ago
Read 2 more answers
What type of selection can be used in leu of switch/case?
tankabanditka [31]
An if or else statement can be
7 0
3 years ago
Read 2 more answers
What happens if two functions are defined with the same name, even if they are in different arguments within the same .py files?
yan [13]

Answer:

Following are the code to this question:

def data(a):#defining method data that accepts parameter

   print (a)#print parameter value

def data(b):#defining method data that accepts parameter

   print (b)#print parameter value

x=input("enter value: ")#defining variable x that5 input value from user

print(data(x))#call method data

Output:

enter value: hello..

hello..

None

Explanation:

  • As the above code, it is clear defines that python doesn't support the method overloading because More than one method can't be specified in a python class with the same name and python method arguments have no type.
  • The single argument method may be named using an integer, a series, or a double value, that's why we can say that it is not allowed.
7 0
3 years ago
Computer designers have concentrated on technology using gallium arsenide instead of silicon because silicon:
cestrela7 [59]

Answer: cannot emit light and has speed limitations

Explanation:

Silicon is usually used in computer chips and solar cells but Gallium arsenide is regarded as a better alternative even though it's costly than silicon.

Gallium arsenide has technical advantages over silicon as its electrons

move through it faster than they move through silicon. Also, cannot emit light and has speed limitations.

Gallium arsenide is used in manufacturing devices like infrared light-emitting diodes, solar cells, optical windows, etc.

7 0
3 years ago
Other questions:
  • Create an application for a library and name it FineForOverdueBooks. TheMain() method asks the user to input the number of books
    9·1 answer
  • How to hack the school system
    13·1 answer
  • One of the most common causes of fires in the home and workplace is: a. All of the answer choices b. Arson c. Candle d. Faulty e
    6·1 answer
  • Write a program that asks the user for the name of their dog, and then generates a fake DNA background report on the pet dog. It
    11·1 answer
  • What invention in the past do you think had a significant impact on our culture/ lifestyle? What do you think will be invented/
    11·1 answer
  • From which latin word the word computer is derived​
    7·1 answer
  • NO THIS ISNT ANY HOMEWORK!
    11·2 answers
  • PORFA AYUDAAAA DOY CORONA (solo si puedo) ES DE TECNOLOGÍA
    12·1 answer
  • The ________ networks operate close to the legitimate free hotspots and typically provide stronger signals
    8·1 answer
  • Bad Directions You are driving to your friend’s house and are using your smartphone for directions. While approaching your desti
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!