1/8
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai | Chat |
|---|
No analytics yet
Send a link to your students to track their progress
Initializing arrays with random values
double[] myList = new double[10];
for(int i = 0; i < myList.length; i++)
myList[i] = Math.random()*100;
printing arrays
double[] myList = new double[10];
...
for(int i = 0; i < myList.length; i++)
System.out.print(myList[i] + " "
Summing all elements
double[] myList = new double[10]; ...
double total = 0;
for(int i = 0; i < myList.length; i++)
total += myList[i];
Finding the largest element
double max = myList[0];
for(int i = 1; i < myList.length; i++)
if (myList[i] > max)
max = myList[i];
Finding the smallest element
double min = myList[0];
for(int i = 1; i < myList.length; i++)
if (myList[i] < min)
min = myList[i];
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;
}
Shifting Left
double temp = myList[0];
for (int i = 1; i < myList.length; i++) {
myList[i - 1] = myList[i];
}
myList[myList.length - 1] = temp;
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;
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; } }