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
8_murik_8 [283]
3 years ago
14

1.Write a Java program to solve the following problem using modularity. Write a method that rotates a one-dimensional array with

one position to the right in such a way that the last element becomes the first element. Your program will invoke methods to initialize the array (random values between 1 and 15) print the array before the rotation, rotate the array, and then print the array after rotation. Use dynamic arrays and ask the user for the array size. Write your program so that it will generate output similar to the sample output below:
Computers and Technology
1 answer:
Westkost [7]3 years ago
6 0

Answer:

Explanation:

The following code is written in Java and it asks the user for the size of the array. Then it randomly populates the array and prints it. Next, it rotates all the elements to the right by 1 and prints the new rotated array.

import java.util.ArrayList;

import java.util.Arrays;

import java.util.Random;

import java.util.Scanner;

class Brainly {

   public static void main(String[] args) {

       Random r = new Random();

       Scanner in = new Scanner(System.in);

       System.out.println("Enter Size of the Array: ");

       int arraySize = in.nextInt();

       ArrayList<Integer> myList = new ArrayList<>();

       for (int x = 0; x < arraySize; x++) {

           myList.add(r.nextInt(15));

       }

       System.out.println("List Before Rotation : " + Arrays.toString(myList.toArray()));

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

           int temp = myList.get(myList.size()-1);

           for (int j = myList.size()-1; j > 0; j--) {

               myList.set(j, myList.get(j - 1));

           }

           myList.set(0, temp);

       }

       System.out.println("List After Rotation :  " + Arrays.toString(myList.toArray()));

   }

}

You might be interested in
Define the four basic operation of a computer ​
Alexeev081 [22]

Answer:

input, output, processing, and storage.

Explanation:

input - the transfer of information into the system. ( ex: what you type on a keyboard. )

output -  the presentation of information to the user ( example is the screen. What type of display is presented...?)

processing - obtaining  information based on what you you searched ( What search results you get after putting in the input)

Storage - Storing or saving information into files.

6 0
3 years ago
Ucf the ability to connect data in different tables in a database through a common field is sometimes referred to as a ____.
kari74 [83]
Much like humans, databases have relationships too.
4 0
3 years ago
Default tab stops are set in word every _______ inch. a. ¾ b. ½ c. 1 d. ¼
Dennis_Churaev [7]
A) 3/4 inch Meow! XD
6 0
3 years ago
Which statement about the Weather Bar in the Outlook calendar is true?
NARA [144]

Answer:

C

Explanation:

3 0
3 years ago
how to make assignment on power point plz cntct me and help me all about power point and my assignment is prime ministers of pak
masha68 [24]

i can help you make a power point but idk anything about prime ministers of pakistan

5 0
3 years ago
Other questions:
  • What is the name of the intel technology that allows a processor to handle two threads at the same time?
    6·1 answer
  • Which of the following statements is the least abstraction of the world wide web?
    6·2 answers
  • When is the bond between the actin and myosin head is broken? when an ATP molecule binds to the myosin head when an ATP molecule
    6·1 answer
  • Find functions f1 and f2 such that both f1 and f2 are O(g(n)), but f1(n) is not O(f2)
    6·1 answer
  • Students who respond promptly to e-mails are following which netiquette rule?
    13·2 answers
  • If you were infiltrating a network (10.16.0.0/16), and searching for vulnerabilities (while trying to remain undetected), why wo
    11·2 answers
  • Steve is creating a document with proper nouns, which Word continues to identify as being misspelled.
    10·1 answer
  • Puter Science (IS)
    14·1 answer
  • How does social media help?<br><br>i will give you the brainliest​
    13·2 answers
  • Put Your Zom Here If You In Zom
    6·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!