JAVA Interview Machine Test __java

Source: Internet
Author: User

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));
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.