Java BASIC Programming 50 questions (10-12 questions) detailed

Source: Internet
Author: User
Tags repetition

First, describe

1, a ball from the height of M-meter to fall, after each landing back to the original height of half, and then fall, to the nth landing, the total number of meters? How high is the 10th time rebound?

2, there are 1, 2, 3, 4 digits, how many can be composed of different and no repetition of the number of three digits? How much are they?

Program Analysis: Can be filled in hundreds, 10 digits, single digit numbers are 1, 2, 3, 4. But must satisfy each one on the number is different, according to the permutation combination principle altogether has the 4*3*2=24 species.

3. The bonus awarded by the Enterprise is based on the profit commission. Profit (I) less than or equal to $100,000, the bonus can be raised by 10%, the profit is higher than $100,000, less than $200,000, less than 100,000 of the portion of the 10% commission, higher than the portion of 100,000 yuan, Cocoa Commission 7.5%, 200,000 to 400,000, higher than 200,000 yuan of the portion, can commission 5% , between 400,000 and 600,000 is higher than the portion of 400,000 yuan, can commission 3%, 600,000 to 1 million, above the portion of 600,000 yuan, can be a commission of 1.5%, higher than 1 million yuan, more than 1 million yuan in the portion of 1% commission, from the keyboard input monthly profit I, the total bonus should be issued?

Program Analysis: According to the profit of the input to determine the scope of the Commission, calculated results.


Second, the source code

1. Procedure 1

Package Tong.yue.hong;import java.util.scanner;/** * A ball from the M-meter height of the free fall, each landing after jumping back to the original height of half, and then fall, to the nth landing, the total number of meters? How high is the 10th time rebound? * @author Tong * */public class Ballheight {public static void main (string[] args) {Scanner scan = new Scanner (system.in); System.out.print ("Enter the height of the ball when it lands:");d ouble height = scan.nextdouble (), if (height<0) {System.out.print ("Incorrect input data, Please re-enter the height of the ball when landing: "); height = scan.nextdouble ();} System.out.print ("Please enter the number of times the ball landed:"), int times = Scan.nextint (), if (times<0) {System.out.print ("input data is wrong, please re-enter the number of balls landed:" Times = Scan.nextint ();} Scan.close (); balldistance (height,times);} private static void Balldistance (double height, int times) {System.out.println ("Start height:" +height);//height before starting to fall, Each time after each bounce and fall is recorded as a double sum = height;for (int i=1;i<=times;i++) {height/=2.0; System.out.println ("+i+" time, the ball of the height of the bounce is: "+height),//after each landing back to the original height of half, after the distance is half the original height multiplied by 2, because there is bounce and fall sum +=2*height;} System.out.println ("+times+" times, after landing after the total distance is: "+sum+" meters. ");}}

Operation Result:



2. Procedure 2

Package tong.yue.hong;/** * There are 1, 2, 3, 4 digits, how many different and no repetition of the number of three digits? How much are they? Program Analysis: Can be filled in hundreds, 10 digits, single digit numbers are 1, 2, 3, 4. But must satisfy each one on the number is different, according to the permutation combination principle altogether has the 4*3*2=24 species. * @author Tong * */public class Pailiezuhe {public static void main (string[] args) {int count = 0;for (int i = 1; I <= 4; i++) {for (int j = 1; J <= 4; j + +) {//Bits and 10 bits cannot be the same if (j==i) {continue;} for (int k = 1; k <= 4; k++) {//Bits and hundred, 10-bit and hundred cannot be the same if (i!=k&&j!=k) {int num = i+j*10+k*100; System.out.print (num+ ""); Count++;if (count%10==0) {System.out.println ();}}}} System.out.println ("\ n total:" +count+ ");}}

Operation Result:



3. Procedure 3

Package Tong.yue.hong;import java.util.scanner;/** * The bonus awarded by the Enterprise is based on the profit commission. * Profit (I) less than or equal to $100,000, bonus may be raised by 10%; * Profit above $100,000, less than $200,000, less than 100,000 yuan of the portion of the 10% commission, higher than the portion of 100,000 yuan, can be a commission of 7.5%; * 200,000 to 400,000, higher than 200,000 yuan, can be paid 5%; 400,000 to 600,000 is higher than the portion of 400,000 yuan, can commission 3%; * 600,000 to 1 million, higher than 600,000 yuan of the portion, can be a commission of 1.5%; * Above $1 million, the portion of more than $1 million per 1% Commission * from the keyboard input monthly profit I, the total number of bonuses should be issued? Program Analysis: According to the profit of the input to determine the Commission range of the profit, calculated results * @author Tong * */public class Salary {public static void main (string[] args) {SYSTEM.OUT.P Rintln ("Please enter the monthly profit, Unit is million:"); Scanner Scanner = new Scanner (system.in);d ouble I = scanner.nextdouble (); while (i<0) {System.out.println ("Incorrect input data, Please re-enter the current month profit in Million: "); I = Scanner.nextdouble ();} Scanner.close (); Computebonus (I);} private static void Computebonus (double i) {Double bonus = 0;//profit (i) less than or equal to $100,000, bonus may be raised 10%;//profit above 100,000 yuan, less than or equal to 200,000 yuan, Less than 100,000 yuan part by 10% commission, higher than 100,000 yuan of the portion, can commission 7.5%;//20 million to 400,000, higher than 200,000 yuan of the portion, can be commission 5%;//40 million to 600,000 between the portion of higher than 400,000 yuan, can commission 3%;//60 million to 1 million, Higher than 600,000 yuan portion, can commission 1.5%;//above 1 million yuan, more than 1 million yuan part by 1% Commission if (i<=10) {bonus = i*0.1;} else if (i<=20) {bonus = 10*0.1+ (i-10) *0.075;} else if (i<=40) {bonus = 10*0.1+10*0.075+ (i-20) *0.05;} else if (i<=60) {bonus = 10*0.1+10*0.075+20*0.05+ (i-40) *0.03;} else if (i<=100) {bonus = 10*0.1+10*0.075+20*0.05+20*0.03+ (i-60) *0.015;} else {bonus = 10*0.1+10*0.075+20*0.05+20*0.03+40*0.015+ (i-100) *0.01;} SYSTEM.OUT.PRINTLN ("Your profit this month is:" +i+ "million, the resulting bonus is:" +bonus+ "million. ");}}
Operation Result:


Java BASIC Programming 50 questions (10-12 questions) detailed

Related Article

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.