1. Print "Narcissus number" (own practice)
The so-called "Narcissus number" refers to a three-digit number, its members of the digital cubic and equal to the number itself.
public class Daffodilnum {
public static void Main (string[] args) {
for (int i = 1; i < i++) {
for (int j = 0; J < J + +) {
for (int z = 0; z < z++) {
int num = i*100 + j*10 +z;
if (i*i*i + j*j*j + z*z*z = num) {
SYSTEM.OUT.PRINTLN (num);
}
}
}
}
}
}
2. Rabbit problem (own practice)
There are a pair of rabbits, from the 3rd month after the birth of a pair of rabbits each month, the rabbit long to the third month after the birth of a pair of rabbits each month, if the rabbit does not die, ask a month of the total number of rabbits.
Import Java.io.BufferedReader;
Import java.io.IOException;
Import Java.io.InputStreamReader;
Import Java.util.Arrays;
public class Hare {
public static void Main (string[] args) {
BufferedReader reader = new BufferedReader (new InputStreamReader (system.in));
int month = 0;
try {
month = Integer.parseint (Reader.readline ());
catch (NumberFormatException e) {
E.printstacktrace ();
catch (IOException e) {
E.printstacktrace ();
}
int[] sum = new Int[month];
Sum[0] = 1;
SUM[1] = 1;
for (int i = 2; i < month; i++) {
Sum[i] = Sum[i-1] + sum[i-2];
}
System.out.println (arrays.tostring (sum));
}
}
3. The problem of word-breaking (a company's written questions)
Splits a section of English (punctuation only with periods and commas) into words and prints the frequency of each word appearing in order from big to small
public class Statistics {
public static void Main (string[] args) {
String Source = "Both sides offered statistics to bolster their." +
"She ' s studying statistics at university.";
map<string, integer> map = new hashmap<string, integer> ();
set<string> set = new hashset<string> ();
String temp = "";
int length = Source.length ();
for (int i = 0; i < length; i++) {
String Currentchar = source.substring (i, i+1);
if ("". Equals (Currentchar) | | ",". Equals (Currentchar) | | ".". Equals (Currentchar)) {
int sizeold = Set.size ();
Set.add (temp);
if (set.size () = = Sizeold && map.size () > 0) {
Map.put (temp, map.get (temp) + 1);
} else {
Map.put (temp, 1);
}
temp = "";
} else {
Temp = temp + Currentchar;
}
}
Integer[] values = Map.values (). ToArray (New Integer[set.size ());
for (int m = 0; m < values.length; m++) {
int tempnum = values[m];
for (int n = m + 1; n < values.length; n++) {
if (Tempnum < values[n]) {
VALUES[M] = Values[n];
Values[n] = Tempnum;
}
}
}
System.out.println (arrays.tostring (values));
}