Related questions
Concept explainers
for beginners java,
1. Write the method that reverses the array passed in the argument and returns this array. Hint: your method may need the array size as a parameter.
2. Write a test program that prompts the user to enter a list of numbers until the user enters -999. Store these numbers in an array (max size = 40) and invokes the above method to reverse the numbers, and displays the numbers. You need to keep track of how many numbers the user enters, you can not use array length because the length is always 40.
1. Start the program.
2. Initialize an integer array `numbers` with a size of 40 to store the numbers.
3. Initialize an integer variable `count` to keep track of the number of elements entered by the user.
4. Create a `Scanner` object to read input from the user.
5. Create a loop to repeatedly prompt the user for numbers until -999 is entered:
1. Display a prompt to the user to enter a number.
2. Read an integer from the user and store it in the `input` variable.
3. Check if the `input` is not equal to -999.
4. If the input is not -999:
- Store the `input` in the `numbers` array at index `count`.
- Increment the `count` by 1.
6. Create a method `reverseArray` that takes an integer array `arr` and its size `size` as parameters:
- Define an integer variable `left` and set it to 0.
- Define an integer variable `right` and set it to `size - 1`.
- While `left` is less than `right`, do the following:
1. Swap the elements at index `left` and `right` in the `arr` array.
2. Increment `left` by 1.
3. Decrement `right` by 1.
8. Call the `reverseArray` method with the `numbers` array and `count` as arguments to reverse the array.
9. Display the reversed numbers:
10. End the program.
Step by stepSolved in 3 steps with 1 images
- Task 2: Write a static method which takes an ArrayList of Strings and an integer and changes the ArrayList destructively to remove all Strings whose length is less than the integer argument. So if the integer argument is 4 and the ArrayList is: tomato cheese chips fruit butter tea buns pie The output tomato cheese chips fruit butter is:arrow_forwardcan you plz write it in java.util.scanner formarrow_forwardWrite a class method named countOccurences that returns the number of times a particular integer occurs in an array of integers. The integer and the array will both be parameters.arrow_forward
- Please write a java code using the photo below. The second photo is the output of my program that I am writingarrow_forwardIn Java: Write a method that multiplies all elements in the array by 3 and returns it to the main method.arrow_forwardProblem: Write a method that will determine whether a given value can be made given an array of coin values. For example, each value in the array represents a coin with that value. An array with [1, 2, 3] represents 3 coins with the values, 1, 2, and 3. Determine whether or not these values can be used to make a desired value. The coins in the array are infinite and can only be used as many times as needed. Return true if the value can be made and false otherwise. Dynamic Programming would be handy for this problem. Data: An array containing 0 or more coin values and an amount. Output: Return true or false. Sample Data ( 1, 2, 3, 12, 5 ), 3 ( 4, 15, 16, 17, 1 ), 21 ( 1 ), 5 ( 3 ), 7 Sample Output true true true falsearrow_forward
- You are given an array of n integers. Write a java method that splitsthe numbers of the array into two equal groups so that the GCD of all numbers in the second group is equal to one and the GCD of all numbers in the first group is not one. After splitting the numbers display the resulting groups as shown in the sample run below. Note: 1. The array has even size. 2. All elements of the array are less than 100. You are not allowed to define new arrays. 3. 4. You are not allowed to definenew methods or use methods from java libraries. Sample run of the method: Inputarray: (6,7,9,4,3,2} Output Group two: (7,9,3} Group one: (2,4,6} I Ignore Order of numbers. Order is not important //Ignore Order of numbers. Order is not importantarrow_forwardin javaarrow_forwardjava a. A method named contains exists that takes an array of Strings and a single String, in that order, as arguments and returns a boolean value that is true if the array contains the given String. Assume that an array of Strings named names is already declared and initialized. Call the method to see if the array contains the name "Fred", and save the result in a new variable named fredIsHere. b. Given a method named printMessage that takes a String argument and returns nothing, call the method to print out "I love Java!".arrow_forward
- Text book imageDatabase System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationText book imageStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONText book imageDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- Text book imageC How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONText book imageDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningText book imageProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education