Question

4.12 School's punishment Back in the days, punishments at school used to be very different. Before,...

4.12 School's punishment

Back in the days, punishments at school used to be very different. Before, teachers used to assign extra work to students that misbehaved during class time. One of the common practices was to ask to write n number of times a specific statement that was according to the specific issue. For example, some times, the teacher asked the student to write 100 times the sentence “I don’t have to write on the class’ table”. Nowadays, students may get around that writing a program that will write those sentences for them. Consequently, write a program that will ask for an integer number and a sentence. The program then outputs n number of times the sentence that was just input.

IN JAVA.

Homework Answers

Answer #1

Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. Thanks

EDIT: updated answer as per your test program. change System.out.println(sentence); to System.out.println(sentence.trim()); if you don't want extra white space appearing before the sentence.

// Main.java

import java.util.Scanner;

public class Main {
   public static void main(String[] args) {
       // defining a Scanner to read user input
       Scanner scanner = new Scanner(System.in);
       // reading the number of times to repeat
       int n = scanner.nextInt();//Integer.parseInt(scanner.nextLine());
       // reading sentence
       String sentence = scanner.nextLine();

       // looping for n times
       for (int i = 0; i < n; i++) {
           // printing sentence
           System.out.println(sentence);
       }
   }
}

Know the answer?
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
Similar Questions
Description: Programming can be used to assist users in completing complex calculations very quickly. As seen...
Description: Programming can be used to assist users in completing complex calculations very quickly. As seen in class practices, we were able to calculate the area of geometric shapes, figure out the amount of calories in cookies, and even calculate a restaurant bill. For this assignment, you will take input from the user to provide interactive messages and to solve the following word problem: Engineers often need to convert between different types of units to perform calculations that follow standard...
Item 1 In the case below, the original source material is given along with a sample...
Item 1 In the case below, the original source material is given along with a sample of student work. Determine the type of plagiarism by clicking the appropriate radio button. Original Source Material Student Version In the 1986 soccer World Cup final, the Argentine star Diego Maradona did not score a goal but his passes through a ring of West German defenders led to two Argentine goals. The value of a star cannot be assessed only by looking at his...
What tools could AA leaders have used to increase their awareness of internal and external issues?...
What tools could AA leaders have used to increase their awareness of internal and external issues? ???ALASKA AIRLINES: NAVIGATING CHANGE In the autumn of 2007, Alaska Airlines executives adjourned at the end of a long and stressful day in the midst of a multi-day strategic planning session. Most headed outside to relax, unwind and enjoy a bonfire on the shore of Semiahmoo Spit, outside the meeting venue in Blaine, a seaport town in northwest Washington state. Meanwhile, several members of...
In narrative essay format, I want you to address a business/organization case study using multiple concepts...
In narrative essay format, I want you to address a business/organization case study using multiple concepts from class. The case question and case text begin on page 5 of this document. You need to demonstrate their best understanding of management and organizational behavior theory, and the application of those ideas to improve the understanding of various issues. You need to clearly identify at least 3 distinct, substantive issues. For each issue you need to 1), identify evidence from the case...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT