Question

2. Write the statements to do the following tasks. • Create an array of 10 integers and initialize the array by 10 users inp
image.png
0 0
Add a comment Improve this question Transcribed image text
Answer #1

ANSWER : HERE IS THE ANSWER FOR YOUR QUESTION:

NOTE: SINCE, IT IS A MULTI-PART QUESTION , I WILL DO THE JAVA PROGRAM FOR QUESTION 2 ACCORDING TO HOMEWORKLIB RULES AND GUIDELINES

----------------------------------------------------------------------------------------------------------------

JAVA CODE:

import java.util.*;

public class Main
{
   public static void main(String[] args) {
  
   //PART A-------------------------------------------->
       Scanner input = new Scanner(System.in);
       // defining the array for 10 numbers
       int arr[]= new int[10];
       int count=0;
      
       System.out.println("Enter 10 values in the array: ");
      
       // getting the 10 integer value from the user
       for(int i=0;i<10;i++)
       {
       arr[i]=input.nextInt();
      
       }
      
       //PART B-------------------------------------->
       int min=arr[0];
      
       for(int i=1;i<10;i++)
       {
      
       if (arr[i]<min)
       min=arr[i];
       }
  
      
       //PART C------------------------------------------------->
       // counting how many times the minimum value occurs in the array
       for(int i=0;i<10;i++)
       {
       if(arr[i]==min)
       count++;
       }
      
      
       // printing the minimum value in the array
       System.out.println("Smallest number in the array is: " + min);
       // printing the total occurences of mimimum value in the array
System.out.println("Smallest number in the array is repeated: " + count + "times");
  
      
      
   }
}

----------------------------------------------------------------------------------------------------------------

SNIPPET:

----------------------------------------------------------------------------------------------------------------

OUTPUT:

----------------------------------------------------------------------------------------------------------------

I hope this would help you out.

If you like my answer , please upvote

If you have any doubt, you can provide comment /feedback below the answer

Thanks

Add a comment
Know the answer?
Add Answer to:
2. Write the statements to do the following tasks. • Create an array of 10 integers...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • write a MIPS program that does the following Create an array of 10 INTEGERS.  Create procedures to...

    write a MIPS program that does the following Create an array of 10 INTEGERS.  Create procedures to find the largest, and find the smallest. Create another procedure called range, which is the difference between largest and smallest (range should call findLargest and findSmallest) Convert your find largest procedure to be recursive

  • Must use Array. Must be in JAVA. Write a program that uses a Scanner object to...

    Must use Array. Must be in JAVA. Write a program that uses a Scanner object to read in a sequence of integers. The first number in the sequence represents the number of integers in the sequence (i.e., do NOT include the first number as part of the sequence). Create an array of integers that is the same size as the number of integers. Then the program will read each integer and place it in the array. Print the content of...

  • Write a program that will create an array of ten integers, allow the user to enter...

    Write a program that will create an array of ten integers, allow the user to enter those integers, and eventually search through the array based on index position: 1. Declare the array. You cannot assign elements to an array until it has first been created. 2. Next, run a for loop so that the user can enter an integer to save in each index position of the array. Since you this array holds ten elements , the index position starts...

  • Write a MATLAB code to generate an array of 100 random integers between 1 and 10...

    Write a MATLAB code to generate an array of 100 random integers between 1 and 10 using the command “randi”. Using “if” statement, impose the condition that if a number in the array is greater than 5, the number is modified as, number = number – 11. Find the sum of the array and store it. Repeat this exercise for 10, 1000 and 100000 trials and plot the following: (a) Sums obtained vs trails number (b) Histogram of the sum...

  • (C++) Write a function, remove, that takes three parameters: an array of integers, the number of...

    (C++) Write a function, remove, that takes three parameters: an array of integers, the number of elements in the array, and an integer (say, removeItem). The function should find and delete the first occurrence of removeItem in the array. (Note that after deleting the element, the number of elements in the array is reduced by 1.) Assume that the array is unsorted. Also, write a program to test the function. Your program should prompt the user to enter 10 digits...

  • In Java, Implement a class MyArray as defined below, to store an array of integers (int)....

    In Java, Implement a class MyArray as defined below, to store an array of integers (int). Many of its methods will be implemented using the principle of recursion. Users can create an object by default, in which case, the array should contain enough space to store 10 integer values. Obviously, the user can specify the size of the array s/he requires. Users may choose the third way of creating an object of type MyArray by making a copy of another...

  • Exercise 2: Write array methods that carry out the following tasks for an array of integers...

    Exercise 2: Write array methods that carry out the following tasks for an array of integers by creating and completing the “ArrayMethods” class below. Add documentation comments for each method. Provide a test program called 'Lab5_yourID.java” that test methods of ArrayMethods class. In your test program, use random class to generate array values. public class ArrayMethods { private int[ ] values; //declare instant variables public ArrayMethods (int[] initialValues) {values = initialValues;} //constructor public void shiftRight() { } public Boolean adjacentDuplicate()...

  • Write a java program that has a method called sameArrayBackwards. The method takes an array of...

    Write a java program that has a method called sameArrayBackwards. The method takes an array of integers, and checks if the numbers in the array are the same going forward as going backwards and will return a boolean (true or false) depending on the result. You can assume that there is at least one element in the array. Method Header: public static boolean sameArrayBackwards (int [] arr) You will test your method in the main method of your program by...

  • I am told to create a fillArray method that will read integers from the file "data.txt"...

    I am told to create a fillArray method that will read integers from the file "data.txt" and store them in the array. I'm told to assume that the file has no more than 100 items in it. This is what I have so far: public void fillArray() { int curVal;    Scanner input = null; try { input = new Scanner(new File("data.txt")); // set the current number of items in the array to zero while (input.hasNextInt()) { curVal = input.nextInt();...

  • 1. Create List 2. Create Random integers 3. Search List Write a program that gets random...

    1. Create List 2. Create Random integers 3. Search List Write a program that gets random integers and populates a list, then searches the list 1. Write a program that creates an empty list 2. Populate the list with 100 random integers 3. After creating the list, print the length of elements in the list 4. Select a range of numbers as 10 – 20 5. Find out the number of times ‘15’ appears in the list and print it...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT