常被考的3道Java實踐練習題

常被考的3道Java實踐練習題

長沙牛耳教育      2022-04-15 21:35:01     8

常被考的3道Java實踐練習題,1.梯度計算企業(yè)發(fā)放的獎金根據(jù)利潤提成。利潤(I)低于或等于10萬元時,獎金可提10%;利潤高于10萬元,低于20萬元時,低于10萬元的

課程價格 請咨詢

上課時段: 授課校區(qū):

詳細介紹

1.梯度計算

企業(yè)發(fā)放的獎金根據(jù)利潤提成。利潤(I)低于或等于10萬元時,獎金可提10%;利潤高于10萬元,低于20萬元時,低于10萬元的部分按10%提成,高于10萬元的部分,可可提成7.5%;20萬到40萬之間時,高于20萬元的部分,可提成5%;40萬到60萬之間時高于40萬元的部分,可提成3%;60萬到100萬之間時,高于60萬元的部分,可提成1.5%,高于100萬元時,超過100萬元的部分按1%提成,從鍵盤輸入當月利潤I,求應(yīng)發(fā)放獎金總數(shù)?

程序分析:請利用數(shù)軸來分界,定位。注意定義時需把獎金定義成長整型。

import?java.io.*;public?class?Prog12{public?static?void?main(String[]?args){System.out.print("請輸入當前利潤:");long?profit?=?Long.parseLong(key_Input());System.out.println("應(yīng)發(fā)獎金:"+bonus(profit));}//接受從鍵盤輸入的內(nèi)容private?static?String?key_Input(){String?str?=?null;BufferedReader?bufIn?=?new?BufferedReader(new?InputStreamReader(System.in));try{str?=?bufIn.readLine();}catch(IOException?e){e.printStackTrace();}finally{try{bufIn.close();}catch(IOException?e){e.printStackTrace();}}return?str;}//計算獎金private?static?long?bonus(long?profit){long?prize?=?0;long?profit_sub?=?profit;if(profit>1000000){profit?=?profit_sub-1000000;profit_sub?=?1000000;prize?+=?profit*0.01;}if(profit>600000){profit?=?profit_sub-600000;profit_sub?=?600000;prize?+=?profit*0.015;}if(profit>400000){profit?=?profit_sub-400000;profit_sub?=?400000;prize?+=?profit*0.03;}if(profit>200000){profit?=?profit_sub-200000;profit_sub?=?200000;prize?+=?prize*0.05;}if(profit>100000){profit?=?profit_sub-100000;profit_sub?=?100000;prize?+=?profit*0.075;}prize?+=?profit_sub*0.1;return?prize;}}

2.求未知數(shù)

一個整數(shù),它加上100后是一個完全平方數(shù),再加上168又是一個完全平方數(shù),請問該數(shù)是多少?

程序分析:在10萬以內(nèi)判斷,先將該數(shù)加上100后再開方,再將該數(shù)加上268后再開方,如果開方后的結(jié)果滿足如下條件,即是結(jié)果。

public?class?Prog13{public?static?void?main(String[]?args){int?n=0;for(int?i=0;i<100001;i++){if(isCompSqrt(i+100)?&&?isCompSqrt(i+268)){n?=?i;break;}}System.out.println("所求的數(shù)是:"+n);}//判斷完全平方數(shù)private?static?boolean?isCompSqrt(int?n){boolean?isComp?=?false;for(int?i=1;i

3.日期計算

輸入某年某月某日,判斷這一天是這一年的第幾天?

程序分析:以3月5日為例,應(yīng)該先把前兩個月的加起來,然后再加上5天即本年的第幾天,特殊情況,閏年且輸入月份大于3時需考慮多加一天。

import java.util.Scanner;public class Prog14{public static void main(String[] args){Scanner scan = new Scanner(System.in).useDelimiter("D");//匹配非數(shù)字System.out.print("請輸入當前日期(年-月-日):");int year = scan.nextInt();int month = scan.nextInt();int date = scan.nextInt();scan.close();System.out.println("今天是"+year+"年的第"+analysis(year,month,date)+"天");}//判斷天數(shù)private static int analysis(int year, int month, int date){int n = 0;int[] month_date = new int[] {0,31,28,31,30,31,30,31,31,30,31,30};if((year%400)==0 || ((year%4)==0)&&((year%100)!=0))month_date[2] = 29;for(int i=0;i

以上就是長沙牛耳教育java培訓(xùn)機構(gòu)的小編針對“常被考的3道Java實踐練習題”的內(nèi)容進行的回答,希望對大家有所幫助,如有疑問,請在線咨詢,有專業(yè)老師隨時為你服務(wù)。

培訓(xùn)啦提醒您:交易時請核實對方資質(zhì),對于過大宣傳或承諾需謹慎!任何要求預(yù)付定金、匯款等方式均存在風險,謹防上當。