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
Write a program that reads a sentence as input and converts each word to "Pig Latin". In one version of Pig Latin, you convert a
OLga [1]

Answer:

The program statement will be written using Microsoft Visual C# Console

string val,vall;

Console.Write("Enter Sentence :");

vall = Console.ReadLine();

val = vall.ToUpper();

string[] words = val.Split(' ');

string[] word = new string[words.Length];

int kount = 0;

string newword = string.Empty;

for (int i = 0; i < words.Length; i++)

{

if (words[i].Length > 1)

{

char[] ch = words[i].ToCharArray();

for (int j = 1; j < words[i].ToCharArray().Length; j++)

{

newword += ch[j];

}

newword += ch[0] + "AY ";

word[kount] = newword;

kount++;

}

else

{

newword += words[i] + "AY ";

kount++;

}

}

Console.WriteLine(newword);

Console.ReadLine();

Explanation:

The first line declares two variables of string data-type

Line 2 prints "Enter Sentence" without the quotes

Line 3 accepts the sentence to be converted to Latin

Line 4 converts the sentence to uppercase

Line 5 splits the sentence word by word

Line 6 creates an array variable

Line 7 creates and initialise a variable kount to 0

Line 8 creates another variable newword,this variable would be used as output variable

Line 9 creates an iterative process

Line 11 checks if the length of a particular word in the sentence is a greater than one

If yes,

Line 13 to 20 Moves the first letter to the last then appends AY then saved in newword variable

If no,

Line 24 - 25 appends AY directly to the word currently in the iteration then saved in newword variable

Line 28 prints the Latin word equivalent of the input sentence.

6 0
3 years ago
Various types of mouse pointer<br>​
g100num [7]

Answer:

Text Pointer

Busy Pointer

Link Pointer

Precision Pointer

Standard Pointer

Help Pointer

Background Busy Pointer

4 0
2 years ago
What is a data type?
kvasek [131]

Answer:

Data type is an attribute of the data in the computer science. It basically guide the compiler and interpreter about the data utilization in the program. Data type basically define the operation, which can be done on given data.

There are different types of data types are as follow:

Integer data type: This type if data type basically represent the integer type of data value from largest to smallest order.

For example: int p = 10;

Real data type: This type of data type is used to represent the real type of number from largest to smallest range.

For example: float b = 17.6;

7 0
3 years ago
Kim is writing a sql query that will pull a list of customers with outstanding orders and the sales rep for each order. What sho
Step2247 [10]

What the phrase should say in Kim's SQL Query is;  WHERE Customer = Sales Rep

<h3>What is SQL Query?</h3>

Structured Query Language (SQL) is defined as a standardized programming language that is used to manage relational databases and perform various operations on the data in them.

Now in SQL Query, when one SQL query is embedded in another SQL query to simulate a join, the second SQL query is embedded in the "WHERE" of the first query.

Since the query will pull a list of customers with outstanding orders and the sales rep for each order. Then, the where phrase will be;

WHERE Customer = Sales Rep

Read more about SQL Query at; brainly.com/question/10097523

6 0
3 years ago
Select all that apply
My name is Ann [436]

Answer:

social change and cultural change i hope this help you

8 0
3 years ago
Other questions:
  • An___ is a rectangular work area in the desk top that contains a program, text, files, it other data and tools.
    5·1 answer
  • What can you search on Microsoft Word or Powerpoint Clipart or Google (Clip art) to find more pictures like the ones below but w
    7·1 answer
  • Which is most likely a presentation file?
    8·1 answer
  • What does the regular expression [a-z0-9\-] mean?
    8·1 answer
  • Which function is going to find the lowest value in a range of numbers? MIN MAXAVERAGE COUNT
    5·1 answer
  • When you build a computer from parts, you usually start by deciding on which processor and motherboard you will use?
    11·1 answer
  • Setting up a desktop computer for anAutoCADspecialist who needs a minimum of 125 GBram which operating system would be the best
    5·1 answer
  • Anyone know the friends song by Marshmello? It's stuck in my head.
    12·2 answers
  • What is another name for control structure <br> Object<br> Sequence<br> Loop<br> Decision
    8·1 answer
  • Write getfirstroot and getsecondroot to return the first and second roots. return a domain_error is there is no first or second
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!