
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
![```java
/*
* Array Search
*/
package int2200.week7;
import java.util.Scanner;
public class arraySearch {
public static void main(String[ ] args) {
// create and initialize an array
int[ ] numbers = {2, -9, 0, 5, 12, -25, 22, 9, 8, 12};
int key;
boolean foundit = false; // declare a variable and initialize it to false
Scanner input = new Scanner(System.in); // Create a Scanner object
System.out.println("==> Array Search program ");
System.out.print("Enter a number to search for: ");
key = input.nextInt();
// access all elements using for each loop
for (int i = 0; i< numbers.length ; i++) {
if ( key == numbers [i]){
foundit=true;
}
}
if (foundit == true){
System.out.println("found it! :)");
}else {
System.out.println("Sorry notfound it! :(");
}
System.out.println("==> End of the Search Program ");
}
}
/*
==> Array Search program
Enter a number to search for: 2
found it! :)
==> End of the Search Program
*/
```
### Explanation:
This is a Java program designed to perform a simple search within an array of integers. Below is a detailed breakdown of its components:
1. **Package and Imports:**
- The program is contained within the `int2200.week7` package.
- It imports the `java.util.Scanner` class to allow user input.
2. **Main Class (`arraySearch`):**
- The main class is named `arraySearch`.
3. **Main Method (`main`):**
- The `main` method is the entry point of the program.
- An array `numbers` is initialized with a set of integer values: `{2, -9, 0, 5, 12, -25, 22, 9, 8, 12}`.
- A boolean variable `foundit` is declared and initialized to `false` to track if the searched number is found.
4. **User Input:**
- A `Scanner` object named `input` is created to capture user input.
- The program prompts](https://content.bartleby.com/qna-images/question/2dedb04f-ec8e-4d86-87d9-6910be748f13/002f45d3-d036-4432-886a-826335dd9410/a3rqwt_thumbnail.png)
Transcribed Image Text:```java
/*
* Array Search
*/
package int2200.week7;
import java.util.Scanner;
public class arraySearch {
public static void main(String[ ] args) {
// create and initialize an array
int[ ] numbers = {2, -9, 0, 5, 12, -25, 22, 9, 8, 12};
int key;
boolean foundit = false; // declare a variable and initialize it to false
Scanner input = new Scanner(System.in); // Create a Scanner object
System.out.println("==> Array Search program ");
System.out.print("Enter a number to search for: ");
key = input.nextInt();
// access all elements using for each loop
for (int i = 0; i< numbers.length ; i++) {
if ( key == numbers [i]){
foundit=true;
}
}
if (foundit == true){
System.out.println("found it! :)");
}else {
System.out.println("Sorry notfound it! :(");
}
System.out.println("==> End of the Search Program ");
}
}
/*
==> Array Search program
Enter a number to search for: 2
found it! :)
==> End of the Search Program
*/
```
### Explanation:
This is a Java program designed to perform a simple search within an array of integers. Below is a detailed breakdown of its components:
1. **Package and Imports:**
- The program is contained within the `int2200.week7` package.
- It imports the `java.util.Scanner` class to allow user input.
2. **Main Class (`arraySearch`):**
- The main class is named `arraySearch`.
3. **Main Method (`main`):**
- The `main` method is the entry point of the program.
- An array `numbers` is initialized with a set of integer values: `{2, -9, 0, 5, 12, -25, 22, 9, 8, 12}`.
- A boolean variable `foundit` is declared and initialized to `false` to track if the searched number is found.
4. **User Input:**
- A `Scanner` object named `input` is created to capture user input.
- The program prompts

Transcribed Image Text:### Java Program Exercise: Implementing a Do-While Loop
**Task:**
Modify the following Java program to achieve the specified output using a do-while loop.
**Requirements:**
- **Provide:**
- Detailed documentation and the exact output as described.
**Hint:**
A do-while loop is required for this task.
**Expected Program Output:**
```
==>> Array Search program
Enter a number to search for: 2
found it! :)
Enter any number to continue or number 0 to exit: 5
==>> Array Search program
Enter a number to search for: 6
Sorry not found it! :(
Enter any number to continue or number 0 to exit: 0
==>> End of the Search Program!
```
This task will help you understand the use of the do-while loop in a Java program. Make sure to provide the complete program with necessary comments explaining the logic for full understanding.
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution
Trending nowThis is a popular solution!
Step by stepSolved in 3 steps with 2 images

Knowledge Booster
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.Similar questions
- Fix the errors and send the code please // Application allows user to enter a series of words // and displays them in reverse order import java.util.*; public class DebugEight4 { public static void main(String[] args) { Scanner input = new Scanner(System.in); int x = 0, y; String array[] = new String[100]; String entry; final String STOP = XXX; StringBuffer message = new StringBuffer("The words in reverse order are\n"); System.out.println("Enter any word\n" + "Enter + STOP + when you want to stop"); entry = input.next(); while(!(entry.equals(STOP))) { array[x] = entry; ++x; System.out.println("Enter another word\n" + "Enter " + STOP + " when you want to stop"); entry = input.next(); } for(y = x - 1; y > 0; ++y) { message.append(array[y]); message.append("\n"); } System.out.println(message) }arrow_forwardDon't copy from other website Unique answer plzzarrow_forwardpublic int binarySearch(int[]array, int num) {int low = 0;//low rangeint high = array.length -1; //high range int mid; //mid rangewhile () //while low is less than or equal to high{mid = ; //set middle range to be (low + high) /2if () { //if the array in the middle range = input number//return mid range }elseif () { //if the array in the middle range > input number//set the high value to be the mid value minus 1 }else{//set low value to be mid value plus one } }//return -1 here because that would mean that the number is not found in the loop}arrow_forward
- using System; class main { publicstaticvoid Main(string[] args) { Random r = new Random(); string[] ROYGBIV; ROYGBIV = new string[7] {"Red", "Orange", "Yellow", "Green", "Blue", "Indigo", "Violet"}; int randNo= r.Next(0,6); Console.Write("Hi, my name is Stevie. I am thinking of Rainbow colors.\nGuess which color I am thinking of? "); string guessedColor = Console.ReadLine(); do { if(guessedColor != ROYGBIV[randNo]) { Console.WriteLine("Your guess is NOT correct.Please enter another color"); guessedColor = Console.ReadLine(); } if(guessedColor == ROYGBIV[randNo]) { Console.WriteLine("You guessed correctly!"); } }while(guessedColor != ROYGBIV[randNo]); } } Hello! This program is written in C# to play a guessing game with the user but instead of numbers its with the colors of the rainbow. How can it be changed to the letters of the entire alphabet instead?arrow_forwardpublic class Test { } public static void main(String[] args) { String str = "Salom"; System.out.println(str.indexOf('t)); }arrow_forwardMethod Details getCountInRange public static int getCountInRange(int[] array, int lower, int upper) Returns the number of values in the range defined by lower (inclusive) and upper (inclusive) Parameters: array - integer array lower - lower limit upper - upper limit Returns: Number of values found Throws: java.lang.IllegalArgumentException - if array is null or lower is greater than upper Any error message is fine (e.g., "Invalid parameters(s)")arrow_forward
- StringFun.java import java.util.Scanner; // Needed for the Scanner class 2 3 /** Add a class comment and @tags 4 5 */ 6 7 public class StringFun { /** * @param args not used 8 9 10 11 12 public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.print("Please enter your first name: "); 13 14 15 16 17 18 System.out.print("Please enter your last name: "); 19 20 21 //Output the welcome message with name 22 23 24 //Output the length of the name 25 26 27 //Output the username 28 29 30 //Output the initials 31 32 33 //Find and output the first name with switched characters 34 //All Done! } } 35 36 37arrow_forwardPlease help with this java problemarrow_forward8) Now use the Rectangle class to complete the following tasks: - Create another object of the Rectangle class named box2 with a width of 100 and height of 50. Note that we are not specifying the x and y position for this Rectangle object. Hint: look at the different constructors) Display the properties of box2 (same as step 7 above). - Call the proper method to move box1 to a new location with x of 20, and y of 20. Call the proper method to change box2's dimension to have a width of 50 and a height of 30. Display the properties of box1 and box2. - Call the proper method to find the smallest intersection of box1 and box2 and store it in reference variable box3. - Calculate and display the area of box3. Hint: call proper methods to get the values of width and height of box3 before calculating the area. Display the properties of box3. 9) Sample output of the program is as follow: Output - 1213 Module2 (run) x run: box1: java.awt. Rectangle [x=10, y=10,width=40,height=30] box2: java.awt.…arrow_forward
- public class Program7 { publicstaticvoidmain(String[]args){ int[]numbers=newint[100]; String[]names={"Maria","Aris","Galin","Galena"}; double[]balances=newdouble[]{2,56,12.57,36.57,57.89}; //length System.out.println(numbers.length); System.out.println(names.length); System.out.println(balances.length); //modifying names[3]="Celine Dion"; System.out.println("__________________________"); //looping for(inti=0;i<names.length;i++){ System.out.println(names[i]); } System.out.println("__________________________"); for(Stringname:names){ System.out.println(name); } //modifying array System.out.println("__________________________"); for(inti=0;i<names.length;i++){ names[i]=names[i]+" Annan"; System.out.println(names[i]); } System.out.println("__________________________"); doubletotal=0.0; for(inti=0;i<balances.length;i++){ total+=balances[i]; } System.out.println("Total Balance: "+ total); } } //calculate the average of the total balancearrow_forwardfor the class ArrayAverage write a code that calculates the average of the listed numbers with a double result for the class ArrayAverageTester write a for each loop and print out the resultarrow_forward
arrow_back_ios
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education

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)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON

Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education