Create a method which follows the instructions below: The method takes 3 arguments: a String called "message", an integer called "loops", and a Boolean called "repeat". The method must throw the ArrayIndexOutOfBounds Exception. If repeat is true, the message string must be printed repeatedly a number of times equal to the value of the loops parameter, all on the same line. If repeat is false, each character from the message string must be printed on separate lines, up to a number of characters equal to the loops parameter. So if loops is 10, the first 10 characters of message should be printed all on separate lines (remember that you can get an individual character at a certain index using "charAt(index)"). If the loops parameter is longer than the length of the string, an ArrayIndexOutOfBoundsException should be thrown instead (not handled inside of the method). This only occurs if repeat was false. Below are some example parameters and their associated outputs. Example 1: message = "Hello", loops = 2, repeat = true Output: HelloHello Example 2: message Output: H e = "Hello", loops = = 2, repeat false Example 3: message "Hello", loops = 6, repeat Result: ArrayIndexOutOfBounds Exception thrown = false

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Java

 

Create a method which follows the instructions below:
The method takes 3 arguments: a String called "message", an integer called "loops",
and a Boolean called "repeat". The method must throw the
ArrayIndexOutOfBounds Exception.
If repeat is true, the message string must be printed repeatedly a number of times
equal to the value of the loops parameter, all on the same line.
If repeat is false, each character from the message string must be printed on
separate lines, up to a number of characters equal to the loops parameter. So if loops
is 10, the first 10 characters of message should be printed all on separate lines
(remember that you can get an individual character at a certain index using
"charAt(index)").
If the loops parameter is longer than the length of the string, an
ArrayIndexOutOfBounds Exception should be thrown instead (not handled inside of
the method). This only occurs if repeat was false.
Below are some example parameters and their associated outputs.
Example 1: message = "Hello", loops 2, repeat = true
Output: HelloHello
Example 2: message
Output: H
e
=
"Hello", loops
=
=
2, repeat
Example 3: message "Hello", loops = 6, repeat
Result: ArrayIndexOutOfBounds Exception thrown
= false
=
false
Transcribed Image Text:Create a method which follows the instructions below: The method takes 3 arguments: a String called "message", an integer called "loops", and a Boolean called "repeat". The method must throw the ArrayIndexOutOfBounds Exception. If repeat is true, the message string must be printed repeatedly a number of times equal to the value of the loops parameter, all on the same line. If repeat is false, each character from the message string must be printed on separate lines, up to a number of characters equal to the loops parameter. So if loops is 10, the first 10 characters of message should be printed all on separate lines (remember that you can get an individual character at a certain index using "charAt(index)"). If the loops parameter is longer than the length of the string, an ArrayIndexOutOfBounds Exception should be thrown instead (not handled inside of the method). This only occurs if repeat was false. Below are some example parameters and their associated outputs. Example 1: message = "Hello", loops 2, repeat = true Output: HelloHello Example 2: message Output: H e = "Hello", loops = = 2, repeat Example 3: message "Hello", loops = 6, repeat Result: ArrayIndexOutOfBounds Exception thrown = false = false
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 4 images

Blurred answer
Knowledge Booster
Exception Handling Keywords
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education