arrays

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/8

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 11:15 AM on 10/1/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai
Chat

No analytics yet

Send a link to your students to track their progress

9 Terms

1
New cards

Initializing arrays with random values

double[] myList = new double[10];

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

myList[i] = Math.random()*100;

2
New cards

printing arrays

double[] myList = new double[10];

...

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

System.out.print(myList[i] + " "

3
New cards

Summing all elements

double[] myList = new double[10]; ...

double total = 0;

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

total += myList[i];

4
New cards

Finding the largest element

double max = myList[0];

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

if (myList[i] > max)

max = myList[i];

5
New cards

Finding the smallest element

double min = myList[0];

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

if (myList[i] < min)

min = myList[i];

6
New cards

Random shuffling

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

int j = (int)(Math.random() * myList.length);

double temp = myList[i];

myList[i] = myList[j];

myList[j] = temp;

}


7
New cards

Shifting Left

double temp = myList[0];

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

myList[i - 1] = myList[i];

}

myList[myList.length - 1] = temp;

8
New cards

Shifting Right

double temp = myList[myList.length - 1];

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

myList[i] = myList[i-1];

myList[0] = temp;

9
New cards

Reverse


int n = arr.length; // Loop only up to the middle point for (int i = 0; i < n / 2; i++) { // Swap element at i with the element at the mirrored index from the end int temp = arr[i]; arr[i] = arr[n - 1 - i]; arr[n - 1 - i] = temp; } }