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
Aleksandr [31]
3 years ago
11

Write a program with a main method that asks the user to enter an array of 10 integers. Your main method then calls each of the

three methods described below and prints out the results of the two methods which return values (see format below).
Computers and Technology
1 answer:
Kay [80]3 years ago
8 0

Answer:

The remaining part of the question is given as follows:

printReverse - a void method that reverses the elements of the array and prints out all the elements in one line separated by commas (see sample output below).

getLargest - an int method that returns the largest value in the array.

computeTwice- a method that returns an array of int which contains 2 times of all the numbers in the array (see the sample output below).

Explanation:

// Scanner class is imported to allow the program receive

// user input

import java.util.Scanner;

// Arrays class is imported to allow the program display the array

// in a pretty way

import java.util.Arrays;

//The class definition

public class Solution {

   // main method is defined which signify beginning of program

  // execution

   public static void main(String[ ] args) {

       // an array is initialized with a size of 10

       int[] array =new int[10];

       // Scanner object scan is defined

       Scanner scan =new Scanner(System.in);

       // A loop is initiated to receive 10 user input to fill the array

       for(int i=0; i < 10; i++){

           System.out.print("Please enter number: ");

           array[i]=scan.nextInt();

       }

       

       // A blank line is print

       System.out.println();

       // printReverse method is called with the received array as

      // argument

       printReverse(array);

       // A blank line is print

       System.out.println();

       // The largest number is printed

       System.out.println("The largest number is: " + getLargest(array));

       // computeTwice method is called to display the array after

      // multiplying each element by 2

       computeTwice(array);

       System.out.println( "The values of the computed twice array is: " );

       // Arrays class is used to print the array in form of a string

      // not object

       System.out.println(Arrays.toString(array));

   }

   

   //printReverse method declared with inputArray as parameter.

   // It has no return type

   public static void printReverse(int[] inputArray){

       System.out.print("Here is the arrray in reverse order: ");

       // A loop goes through the array starting from the end

       // and display each element

       for(int i = (inputArray.length - 1); i >= 0; i--){

           if(i == 0){

               // If the last element, do not append comma

               System.out.print(inputArray[i]);

           } else {

               // If not the last element, do append a comma

               System.out.print(inputArray[i] + ", ");

           }

       }

   }

   

   // getLargest method is declared with inputArray as parameter

   //  it compare each element in the array and return the largest

   public static int getLargest(int[] inputArray){

       // The first element is assumed to be the largest before the

      // loop begin

       int max = inputArray[0];

       for(int i = 1; i < inputArray.length; i++){

           if (inputArray[i] > max){

               max = inputArray[i];

           }

       }

       return max;

   }

   

   // computeTwice is declared with inputArray as parameter

   // it loop through the array and multiply each element by 2

   // it then return a modified array

   public static int[] computeTwice(int[] inputArray){

       for(int i = 0; i < inputArray.length; i++){

           inputArray[i] *= 2;

       }

       return inputArray;

   }

}

You might be interested in
Four differences between general and special purpose conputer in points.......
cupoosta [38]

Explanation:

hope this helps to uhh...

4 0
2 years ago
What is output by the following code?
Inessa05 [86]
When numbers are divided, the integer portion is kept and the remainder is disregarded (meaning 10/9 would return 1). Following this format, we get the answer of <span>6 6 6 3 7 7 9 5 8 8. 
I also see that this program can be optimized because you use the same for loop twice, and both of them manipulate list elements in some way. A more optimized program would be:

</span><span>int a [] = {64 , 66 , 67 , 37 , 73 , 70 , 95 , 52 , 81 , 82};

for (int i = 0; i < a.length; i++) {
  a[i] = a[i] / 10;
  </span>System.out.print(a[i] + " ");<span>
}

Or maybe you don't need to store the list values for later on. You could do:

</span>for (int i = 0; i < a.length; i++) {
  System.out.print(a[i] / 10 + " ");
}

In any situation, your answer is choice 2.
8 0
2 years ago
What is your robloz?​
ira [324]

Answer:

my Ro.b.l.o.x is cookiefunny232

Explanation:

5 0
2 years ago
When you exit an office app, if you have made changes to a file since the last time the file was saved, the office app displays
Lubov Fominskaja [6]
<span>Yes, it is true that if we exit an office app we prompted by one dialog box that we want to save the changes to the file or not.It is one of the good option in Microsoft office product if we close the file accidentally it will display the dialog box to choose the options.In that dialog box if we click save changes button it will save the changes what we made new into the file.Then if we click don't save changes button it won;t make any new changes into the file.If we click cancel button it will return to the page we are working on it.</span>
4 0
3 years ago
Economics is the study of how we acquire our unlimited wants and needs with very limited resources. Which option below best desc
ale4655 [162]
A. If we desire more of something than we can have.
7 0
3 years ago
Other questions:
  • You would like to arrange the records alphabetically. You should _____.
    7·2 answers
  • Given the following code, what is output by the method call, mystery(6 * 8)?
    8·1 answer
  • What is master slide and tell about master slide
    6·1 answer
  • _________ are represented using diamonds linked withparticipant ETs
    6·1 answer
  • Vghfthcnbvhghvngjgjvjgkb, kcnjc cnnfjdhd mc Dan Jfhjc cm. Cm n n hdjfjocnkcnd
    10·2 answers
  • When working with arrays, most programming languages perform ________, which means they do not allow programs to use invalid sub
    5·1 answer
  • Elsa wants to save her work at the office to be continued at home either on a pen drive or CD. Outline three reasons why she wil
    6·1 answer
  • Which of the following words best describes the word icon ​
    14·2 answers
  • The hexadecimal eqquivalent of (80)10 is
    11·1 answer
  • The entities on which data are collected are _____.
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!