have been self-taught Java has no method, in addition to work in a small amount of contact, after reading the grammar, do not know how to progress, helpless ah, had to stick to brush exercises, hoping to accumulate and understand.
Title: Generate 100 random integers from 0 to 99, find the largest and smallest of them, and count the number of integers greater than 50, sort the array, and go back
Import Java.util.HashSet;
Import Java.util.Set;
public class Randomnum {
public static void Main (string[] args) {
int randomnum[] = new INT[100];
int gt50record = 0;
int maxnum = 0;
int minnum = 100;
System.out.print ("Original array Value:");
for (int i = 0; i < randomnum.length; i++) {
100 random integers between 0-99
Randomnum[i] = (int) math.round (* math.random ());
System.out.print (Randomnum[i] + "");
Number of integers greater than 50
if (Randomnum[i] > 50) {
gt50record++;
}
New Max Max, read the new value compared to the original value, if it is greater than the original value, replace the original value with the new value
if (Randomnum[i] > Maxnum) {
Maxnum = Randomnum[i];
}
if (Randomnum[i] < Minnum) {
Minnum = Randomnum[i];
}
The values in the array are evaluated one by one, and the new value is compared to each value in the new group, and the elements in the new array continue to be compared to the next element, if less than the position of the element is swapped.
for (int j = 0; J < i; J + +) {
if (Randomnum[i] < randomnum[j]) {
int tmp;
TMP = Randomnum[j];
RANDOMNUM[J] = Randomnum[i];
Randomnum[i] = tmp;
}
}
}
System.out.println ("\ n");
SYSTEM.OUT.PRINTLN ("GT Intnum has" + Gt50record);
System.out.println ("max number is:" + maxnum);
System.out.println ("min number is:" + minnum);
System.out.print ("Under Is Order Result:");
for (int i = 0; i < randomnum.length; i++) {
System.out.print (Randomnum[i] + "");
}
Go heavy
set<integer> uniq = new hashset<integer> ();
for (Integer i:randomnum) {
Uniq.add (i);
}
System.out.println ("\ n" + "Uniq:");
for (Integer I:uniq) {
System.out.print (i + "");
}
}
}
Java daily exercise (i)