The results of the output are referenced as follows:
List of programs:
1. Produce random number
Generate random number public
class Randomcharacter {public
static char getrandomcharacter (char Ch1,char CH2) {return
( Char) (Ch1+math.random () * (ch2-ch1+1));
}
Generates random lowercase letters public
static char Getrandomlowercaseletter () {return
getrandomcharacter (' A ', ' Z ');
}
Generates random uppercase letters public
static char Getrandomuppercaseletter () {return
getrandomcharacter (' A ', ' Z ');
}
Generates 0-9 random digits between
the public static char Getrandomdigitcharacter () {return
getrandomcharacter (' 0 ', ' 9 ');
}
public static char Getrandomcharacter () {return
getrandomcharacter (' \u0000 ', ' \uffff ');
}
2, randomly generated 100 lowercase letters, statistics 26 letters each occurrence of the number of
Randomly generates 100 lowercase letters, counts the number of occurrences of 26 letters public class Countlettersinarray {public static void main (string[] args) {char[] Ch
Ars=createarray ();
System.out.println ("The lowercase letters are:");
Displayarray (chars);
Int[] Counts=countletters (chars);
System.out.println ();
System.out.println ("The occurences of each letter are:");
Displaycounts (counts);
public static char[] Createarray () {//Generate 100 random lowercase letters char[] chars=new char[100];
for (int i=0;i<chars.length;i++) chars[i]=randomcharacter.getrandomlowercaseletter ();
return chars;
public static void Displayarray (char[] chars) {//per line 20 display letter for (int i=0;i<chars.length;i++) {if ((i+1)%20==0)
System.out.println (chars[i]+ "");
else System.out.print (chars[i]+ "");
} public static int[] Countletters (char[] chars) {//Returns the number of occurrences per letter int[] Count=new int[26];
for (int i=0;i<chars.length;i++) count[chars[i]-' a ']++;
return count; public static void Displaycounts (int[] count) {//displays 26 letters and their corresponding occurrences.10 for (int i=0;i<count.length;i++) if ((i+1)%10==0) System.out.println (count[i]+ "-" + (char) (i+ ' a ') + "") per line;
else System.out.print (count[i]+ "-" + (char) (i+ ' a ') + "");
}
}