更新時(shí)間:2020-08-07 16:08:18 來源:動(dòng)力節(jié)點(diǎn) 瀏覽2416次
1.梯度計(jì)算
企業(yè)發(fā)放的獎(jiǎng)金根據(jù)利潤提成。利潤(I)低于或等于10萬元時(shí),獎(jiǎng)金可提10%;利潤高于10萬元,低于20萬元時(shí),低于10萬元的部分按10%提成,高于10萬元的部分,可可提成7.5%;20萬到40萬之間時(shí),高于20萬元的部分,可提成5%;40萬到60萬之間時(shí)高于40萬元的部分,可提成3%;60萬到100萬之間時(shí),高于60萬元的部分,可提成1.5%,高于100萬元時(shí),超過100萬元的部分按1%提成,從鍵盤輸入當(dāng)月利潤I,求應(yīng)發(fā)放獎(jiǎng)金總數(shù)?
程序分析:請利用數(shù)軸來分界,定位。注意定義時(shí)需把獎(jiǎng)金定義成長整型。
import?java.io.*;public?class?Prog12{
public?static?void?main(String[]?args){
System.out.print("請輸入當(dāng)前利潤:");
long?profit?=?Long.parseLong(key_Input());
System.out.println("應(yīng)發(fā)獎(jiǎng)金:"+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;
}
//計(jì)算獎(jiǎng)金
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ù)
一個(gè)整數(shù),它加上100后是一個(gè)完全平方數(shù),再加上168又是一個(gè)完全平方數(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.日期計(jì)算
輸入某年某月某日,判斷這一天是這一年的第幾天?
程序分析:以3月5日為例,應(yīng)該先把前兩個(gè)月的加起來,然后再加上5天即本年的第幾天,特殊情況,閏年且輸入月份大于3時(shí)需考慮多加一天。
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("請輸入當(dāng)前日期(年-月-日):");
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
以上就是動(dòng)力節(jié)點(diǎn)java培訓(xùn)機(jī)構(gòu)的小編針對“常被考的3道Java實(shí)踐練習(xí)題”的內(nèi)容進(jìn)行的回答,希望對大家有所幫助,如有疑問,請?jiān)诰€咨詢,有專業(yè)老師隨時(shí)為你服務(wù)。
相關(guān)閱讀
初級 202925
初級 203221
初級 202629
初級 203743