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
In a flow chart, both the decision structure and the repetition structure use the diamond symbol to represent the condition that
leonid [27]

Answer:

Option A(True) is the correct answer for the above question.

Explanation:

  • The flowchart is used to give the solution of a problem through the diagram in a step by step processor. It helps the user to understand the solution easily. For diagram, it uses many types of symbols that are fixed for every sequence just like An oval symbol represents the start and end of the flowchart which is fixed for every flowchart.
  • So for the decisions in a flowchart, the diamond symbol is used which is to make the decisions and it has two sides-- one is true and the other is false.
  • The decisions are used also to represent the loop structure which is also called the repetition structure because the loop is controlled by the help of decisions so the diamond box is also used for the loop
  • The above question-statement says that the decisions-controlled is used for the loop and for the decisions which are true because it is also described above.
8 0
3 years ago
Every page on a website must be updated recently to consider the website updated/maintained
guajiro [1.7K]
Unmaintained. hope that helped
6 0
3 years ago
Read 2 more answers
Create a test that prompts a user to enter a 5-digit PIN in the main procedure and then calls Validate PIN procedure to validate
Pie

Answer:

See explaination

Explanation:

#include <iomanip>

#include <string>

#include <fstream>

using namespace std;

void getName(string);

void getPin(int,int);

void displayMenu(int);

string name;

int pin1, pin2, ch ;

int main()

{

cout << fixed << showpoint << setprecision(2);

getName(name);

getPin(pin1,pin2);

displayMenu(ch );

system("pause");

}

void getName(string name)

{

cout << "Enter your name: ";

cin >> name;

if (name = "AXBY") || (name != "ABGSHY"))

{

getName(name);

}

}

void getPin(int pin1, int pin2)

{

string name;

if (name == "AXBY")

{

cout << "Please Enter Pin: ";

cin >> pin1;

if (pin1 != 4433)

{

cout << "Pin incorrect please try again!";

cin >> pin1;

}

}

if (name == "ABGSHY")

{

cout << "Please Enter Pin: ";

cin >> pin2;

if (pin2 != 2849)

{

cout << "Pin incorrect please try again!";

cin >> pin2;

}

}

}

void displayMenu(int ch )

{

cout << "[1] Check your account Balance\n"

"[2] Withdraw funds\n"

"[3] Deposit funds\n"

"Please Enter Choice: ";

cin >> ch ;

if (ch != 1 || ch != 2 || ch != 3)

{

cout << "Choice is incorrect, enter choice now: ";

cin >> ch ;

}

}

4 0
3 years ago
What is the main task of the project manager
WINSTONCH [101]

Answer:

to handle day to day operations of a project A P E X

Explanation:

hope that helped

6 0
3 years ago
Read 2 more answers
How to save a file for the first time?​
White raven [17]

by typing ctrl+ s on keyboard

7 0
2 years ago
Read 2 more answers
Other questions:
  • _____ is two or more connected computers.
    8·1 answer
  • Why is it a good idea to view your HTML code in more than one web browser
    13·1 answer
  • Alternating Current or AC is better for use in ___________, while DC direct current is needed in _________ .
    15·2 answers
  • The type of database that uses fields, records, and measure as data attributes is
    7·1 answer
  • What keyword do we use when instantiating an object _________________
    15·1 answer
  • Q) CITY column of a table contains information such as Bangalore , Bangalore-64 , Bangalore-56001 , Mumbai - 400002 etc in order
    8·1 answer
  • What in the LAN for a small office, some user devices connect to the LAN using a cable, while others connect using wireless tech
    14·1 answer
  • You want to establish the validity of a test designed for computer technicians using a predictive criterion-related validation s
    9·1 answer
  • What command would you use to add a file to an e-mail message?
    15·2 answers
  • Why does Homework exist? Why is it so important?
    10·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!