Java basic grammar combat (50 classic examples)

50 Java basic algorithm legislative issues, the code posted much later in the Baidu search less specific code look at my blog -> all join me one to do it, there is a problem of welcome that discussion.

See Code topics Links ->

50 Java basic grammar exercises and answers

1. Analyzing the number of prime numbers between 101-200 and the outputs of all primes. Prime number called a prime number, that is, except 1 and itself, no integer number it can be divisible. That is, only two prime factors.
2. Classical problem: a pair of rabbits from the first 3 months after birth are born every month one pair of rabbits, bunnies grow up to the third month after the month gave birth to one pair of rabbits, if the rabbit is not dead, ask the total number of rabbits per month for how much?
3. Print out all the "number of Narcissus", the so-called "Narcissus number" refers to a three-digit number, which is equal to the digits of the cube and the number itself. For example: 153 is a "Narcissus number", because cubic cubic cubic +3 +5 1 = 153.
4. a positive integer decomposition of the quality factor. For example: the input 90, to print out 90 = 2 . 3 3 * 5.

(1) If the prime exactly equal to n, then the prime factor decomposition process has been completed, it can be printed out.
(2) If n <> k, n but k can be divisible should print out the value of k, and k is divided by n using, as a new positive integer n, the first step is repeatedly executed.
(3) if n is not divisible by k, k + 1 is used as the value of k, the first step is repeatedly performed.

The use of nested conditional operator to complete this question: academic> = 90 points represented by students A, B is represented by between 60-89 minutes is represented by C 60 points or less.
6. Enter two positive integers m and n, and seeking the least common multiple of the greatest common divisor.
7. The input line of characters, respectively, the statistics of the number of English letters, spaces, numbers and other characters therein.
8. find s = a + aa + aaa + aaaa + aa ... the value of a, where a is a number. E.g. 2 + 22 + 222 + 2222 + 22222 (in this case the sum total of the number 5), a control keyboard a few numbers together.
9. If a number is exactly equal to the sum of its factors, this number is called the "number of completed." E.g. 6 = 1 + 2 + 3. After programming to find all the numbers less than 1000.
10. ball free fall from a height of 100 meters, the anti-jump back after each landing half its original height; down again, find it at the 10th floor, after a total of how many meters? 10th rebound tall?
11. 1,2,3,4 figures, the number of other with no repeat of the three-digit numbers can be composed? How much are?
12. The commission bonuses based on company profits. When profit (I) is less than or equal to 10 million, 10% of the prize can be mentioned; when profit than 10 million, less than 20 million, 10 million commission portion is less than 10%, higher than 100,000 yuan part, 7.5% cocoa commission; is between 200,000 to 400,000, more than 20 million portion may commission 5%; more than 40 million portion is between 400,000 to 600,000, may be 3% commission ; is between 600,000 to 1,000,000, more than 60 million portion may commission 1.5% above 100 million, more than one million yuan portion 1% commission, from the keyboard month profit I, should seek bonuses?
13. An integer that after 100 plus is a perfect square, plus 168 is a perfect square, what is the number is how much?
14. Enter a certain period of a day, this day is judgment day of the year?
15. Enter three integers x, y, z, please these three numbers small to large outputs.
16. 9 * 9 outputs formulas.
17. Monkey eating peach issues: the monkey off his first day of a number of peach, half eaten immediately, not addiction, but also to eat the next morning a turn eaten by the remaining peach half, then eat a . After the morning before the rest of the day I eat half a zero. When the morning of the 10th day want to eat, see only one peach. Seeking first day were picked number.
18. The two table tennis team to compete, each out of three. A team of a, b, c three, Team B is x, y, z three. List of game has been determined by lot. Asking someone to the list of game players. He does not say a ratio x, c said he did not and x, z ratio, programmed to identify a list of three teams of racing.
19. A print out the following pattern (diamonds)
    *
   ***
 ******
********
 ******
  ***
   *
20. There are a fraction of the sequence: 2 / 1,3 / 2,5 / 3,8 / 5,13 / 8,21 / 13 ... and this calculated front 20 of the series.
21. seeking + 1 2! + 3! + ... + 20! And.
22. The method of recursive seeking 5 !.
23. There are five people sit together, the fifth person to ask how old? He said that 2 years older than 4 people. Asked individuals age 4, he said, is larger than 3 individuals 2 years of age. Asked a third person, said Congress two years than the second. He asked a second person, the first person to say more than two years older. Finally, ask the first man, he said, he is 10 years old. The fifth person to ask how much?
24. give a positive integer of not more than 5, the requirements: First, it is seeking few, two, reverse printing out of the digits.

25. a 5-digit, determines that it is not a palindrome. That 12321 is a palindrome, the same bits and ten thousand, ten and one thousand identical.

26. Please enter the first letter of the week to determine what day of the week, if the first letter of the same, then continue to determine the second letter.

27. inner prime number Noriyuki required 100.

10 to 28. The number of sorting.

29. seeking a 3 * 3 matrix and the diagonal elements.

30. There has been a good array row sequence. Now enter a number, required by the laws of the original insert it into the array.

31. The array of a reverse output.

32. Take an integer from 4 to 7 from the right end of a.

33. Triangle print out (printed out in claim 10 below the line)

    1
   1 1
 1 2 1
1 3 3 1

1 4 6 4 1
1 5 10 10 5 1

34. Input the number 3 a, b, c, the output order of size.

35. The input array, the first maximum switching element with minimal exchange the last element, the array output.

36. n integers, so that the front of each sequence number m set back position of the last number of the number m becomes m foremost.

37. personal circle n, Arranging order. From the first person countin (report number from 1-3), who report 3 people exit the circle, and asked who the last remaining original No. few.

38. Write a function, find a string length, the main function in the input string, and outputs its length.

39. Write a function, the input n is even, the function call request 1/2 + 1/4 + ... + 1 / n, n is an odd number when the input calling the function 1/1 + 1/3 + ... + 1 / n (the pointer function).

40. The string sorting.

There are 41 beaches on a pile of peaches, five monkeys points. The first monkey credentials this pile of peaches divided into five parts, one more, one more than the monkey thrown into the sea, took one. The second monkey and the rest of the peaches were divided into five, one more, it also put more than one thrown into the sea, took a third, fourth, fifth monkeys are doing and asked originally on the beach at least how many peaches?

42.809 * ?? + ?? * = two digits 800 9 * ?? + ?? 1 represented by wherein, * 8 ?? result of two digits, 9 * ?? result of 3 bits. ?? representatives seeking double-digit, and the result of 809 * ??.

43. The composition can seek 0-7 odd number.

44. always an even number as the sum of two primes.

45. Analyzing be a prime number divisible.

46. ​​The two strings linker.

47. 7 reads the number (1-50) is an integer value, a value for each reading, the program prints the number of * value.

48. The adoption of a public telephone data transfer, the data is an integer of four bits, are encrypted in the transmission process, the encryption rules are as follows: add 5 are each digit, and then the remainder divided by the number 10 in place, then the first and fourth exchange, the second and third exchange.

49. The neutron count the number string string appears.

50. There are five students, each student has a 3 course results, the above data entered from the keyboard (including student number, name, score three classes), calculate the grade point average, the status of the original data and the calculated average scores stored in a disk file "stud" in.

Published 22 original articles · won praise 1 · views 1435

Guess you like

Origin blog.csdn.net/weixin_44803446/article/details/104423965