1、50道javase练习题50道javase练习题docx50道javase练习题(50道javase练习题)program 1Title: classical question: there are a pair of rabbits, born from third months after birth each month a pair of rabbits, small rabbits grow up to third months later, every month and a pair of rabbits, if the rabbit does not die,What is t
2、he total number of rabbits per month?1. program analysis: the number of rabbits1, 1, 2, 3, 5, & 13, 21 program 2Topic: determine the number of primes between 101-200, and the output of all prime numbers1. program analysis: the method of judging prime numbers: remove 2 to sqrt (a number) with a numbe
3、r, if divisible,It indicates that this number is not prime, and is a prime numberprogram 3Title: print out all the Narcissus numbers, so called narcissus number refers to a three digit number, the number of cubic and equal to the number itself. For example, 153 is a narcissus number ,Because three t
4、imes three times three times 5+3 153=1.1. program analysis: use the for cycle to control 100-999 numbers, each number decomposes a bit, ten bits, hundredsprogram 4Title: a positive integer decomposition of the quality factor For example: enter 90, print out 90=2*3*3*5Program analysis: to decompose t
5、he prime factor of N, we should first find a minimum prime number k, and then complete the following steps:(1)if the prime number is equal to N, the process of decomposing the prime factor is finished and printed out.(2)if n k, but n is divisible by K, the value of K should be printed, and divided b
6、y N K, a positive integer as a new n you repeat the first step(3)if n is not divisible by K, with k+1 as the value of K, repeat the first stepprogram 5Title: use the nesting of conditional operators to complete this question: students with academic scores =90 points are represented by A, 60-89 point
7、s are represented by B, and 60 points are represented by C1. program analysis: (a b) a:b? This is a basic example of the conditional operatorprogram 6Enter two positive integers m and N, find the greatest common divisor and least common multiple1. program analysis: using rolling methodprogram 7Title
8、: enter a line of characters, respectively, the number of English letters, spaces, numbets and other characters1. program analysis: using the while statement, for the input character is not,n.program 8Topic: s=a+aa+aaa+aaaa+aa A, where a is a number For example, 2+22+222+2222+22222 (the total sum of
9、 5 numbers), a few numbers with keyboard contro1.1. program analysis: the key is to calculate each item valueprogram 9Topic: if a number is exactly equal to the sum of its factors, this number is called end of a few. For example 6=123 programming to find all completed within 1000.program 10.Topic: a
10、 ball from a free fall height of 100 meters, each landing half anti jump back to the original height; then fall, for it in the tenth floor, how many meters? How high is the rebound for the tenth time?program 11_Title: 1, 2, 3, 4 numbers, how many different numbers can be formed without each other an
11、d three digits? How much are they?1. program analysis: can fill at 100, ten, a nu mb er is 1, 2, 3, 4. Then remove the arrangement does not meet the condition which all arrangedprogram 12_Title: corporate bonuses based on profits Profit (I) less than or equal to 10 million yuan, the bonus can be 10%
12、; profit higher than 10 million, less than 20 million, less than 10 million part of the 10% Commission, higher than 10 million, cocoa percentage betwee n 20 million to 7. 5%; 40 million, 20 mill ion higher than the part the Coinmission, 5%; 40 million higher than the part between 40 million to 60 mi
13、llion, to the Commission of 3%;between 60 million to 100 million, higher than 60 million, to the Commission of 1.5%, higher than 100 million,More than 1 million yuan part of the Commission by 1%, from the keyboard input month profit I, the total amount of bonus shouldbe awarded?1. program analysis:
14、please use a few axes to boundaries, positioning. Note that the definition needs to define integer growth bonusprogram 13.Title: an integer, plus 100, is a perfect square number, plus 168 is a complete square number, what is the number?1. program analysis: judgment in less than 100 thousand, the num
15、ber of the first and 100 after the root, then the number of plus 268 after prescribing, if after prescribing results meet the following conditions, which is the result of. Please see the concrete analysis:program 14.Enter a certain period of a day, judgment day is the first few days this year?1. pro
16、gram analysis: in March 5th, for example, should first add up the first two months, and then add 5 days, that is, the first few days of the year, special circumstances, leap year and input month is greater than 3, need to consider more than one day.program 15.Enter three integers x, y, Z, please put
17、 the three number of small to large output.1. program analysis: we try to get the smallest number on X, the first X compared with the Y, if x y will X and Y values of exchange, and then x and Z are compared, if x Z will X and Z values of exchange, so that the minimum X.program 16_Topic: the output o
18、f 9*9 formulas1. program analysis: branches and are considered a total of 9 rows 9, I control line, J contro1.program 17_The monkey eats the peach problem: the monkey takes off several peaches on the first day, eats half immediately, is not addicted, eats one more second, in the morning, will eat th
19、e peach remaining half, has eaten one more After every morning to eat the rest of the day before a Yibanlingyi. The tenth day in the morning to eat, see only a peach How much did you pick up for the first day?1. program analysis: adopt the method of reverse thinking, forward inference fromprogram 18
20、_Title: two table tennis team competition, each person three A team of a, B, C three, B teams for the X, y, Z three The list of matches has been drawn. Someone asks the players for a list of the matches A said he is not more than x, C said he did not x, Z, programmed to identify a list of three team
21、s racing1. program analysis: judge the prime number method: use a number to remove 2 to sqrt (this number), if can be divisible, it shows that this number is not prime, and vice versa is prime numberprogram 19_Title: print the following pattern (diamond)* * *TiananmenResultTiananmen* * *1. program a
22、nalysis: first, the graphics are divided into two parts to see, the first four lines of a rule, the latter three lines of a rule, the use of double for cycle, the first layer control line, the second layer control column.There is a sequence of fractions: 2/1, 3/2, 5/3, 8/5, 13/8, 21/13 And the sum o
23、f the first 20 of the series.1. program analysis: please seize the change rule between the numeratorprogram 21_Title: 1+2! +3! +. +20!1. program analysis: this procedure is to bring the cumulative become a multiplicativeprogram 22Topic: using recursive method to find 5!1. program analysis: recursive
24、 formula: fn二fn_1*4!program 23Topic: there are 5 people sit together, ask the fifth person how old? He said he was 2 years older than fourth Ask fourth people age, he said that more than third people in 2 years Ask third people, more than second people and two. Ask second people, two years older tha
25、n the first person said Finally asked the first man, he said, 10 years old. How big are fifth people?1. program analysis: using the recursive method, recursive andrecursive backstepping is divided into two stages If you want to know the age of fifth people, you need to know the age of the fourth per
26、son, and in turn, push to the first person (10 years old), and then push backprogram 24Title: give a no more than 5 positive integers, requirements: first, ask it is a few digits, two, reverse print out your figuresprogram 25Title: a 5 digit, it is not a palindrome judgment That 12321 is a palindrom
27、e, a bit and bit the same ten million, with thousands of the sameprogram 26Title: enter the first letter of the week to determine what day it is. If the first letter is the same, then continue to judge the second letter1. program analysis: using the situation statement is better, if the first letter
28、 is the same, then judge to use the situation statement or if sentence to determine the second lettersprogram 27.Title: seeking primes within 100Title: sorting 10 numbers1. program analysis: can use the selection method, from 9 months after the comparison process, select a minimum exchange with the
29、first element, the next analogy, with second elements and 8 Comparison and exchangeprogram 29Topic: find a 3*3 matrix and diagonal elements1. program analysis: use double for cycle control input two-dimensional array, and then accumulate aii outputprogram 30.Topic: a sorted array. Now enter a number
30、, according to the requirements of the original law it is inserted into the array.1. program analysis: first determine whether the number is greater than the last number, and then consider the insertion of the number of the middle, after inserting the element after the number, followed by a position
31、program 31_Title: output an array in reverse order 1. program analysis: the first and the last exchange.Topic: take an integer a from the right end of the beginning of the 4 7.Program analysis: this can be considered:(1)move a to 4 bit first(2)to set up a low of 4 for 1, the rest of the number 0. Av
32、ailable (0 4)(3)carry on the above two operationsprogram 33.Title: print Yang Hui triangle (print out 10 lines as shown below)1. program analysis:One111211464115101051 program 34Topic: enter the number 3 A, B, C, according to the sequence of output1. program analysis: using pointer methodprogram 35The input array, th
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1