Ask Question
16 December, 12:48

Write a complete program that declares an array of 1000 integers and initializes each element in the array to have a value equal to the index of that element. That is, the value at index 0 should be 0, the value at index 1 should be 1, the value at index 2 should be 2, and so on. Then, ask the * user for a single integer input. Triple the value of each element in the * array whose value is divisible by that user input. You do not need to print out the array or anything else except for the user input prompt. You can assume that the user will input an integer when prompted.

+1
Answers (1)
  1. 16 December, 14:02
    0
    see explaination

    Explanation:

    import java. util. Scanner;

    class Main

    {

    public static void main (String[] args)

    {

    int []A = new int[1000]; / / Declaration of array which will store 1000 integers

    for (int i = 0; i<1000; i++)

    A[i] = i; / / will initialise elements of array equal to their index

    System. out. print ("Enter a value: ");

    Scanner sc = new Scanner (System. in);

    int num = sc. nextInt (); / / Prompts the user to enter value

    for (int i = 0; i<1000; i++)

    {

    if (A[i]%num==0) / /checks if the element is divisible by the entered value

    A[i] = 3*A[i]; / / Triples the value and reassigns to the same element

    }

    }

    }
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Write a complete program that declares an array of 1000 integers and initializes each element in the array to have a value equal to the ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers