更新時間:2020-08-07 16:08:18 來源:動力節點 瀏覽2333次
1.梯度計算
企業發放的獎金根據利潤提成。利潤(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,求應發放獎金總數?
程序分析:請利用數軸來分界,定位。注意定義時需把獎金定義成長整型。
import?java.io.*;public?class?Prog12{
public?static?void?main(String[]?args){
System.out.print("請輸入當前利潤:");
long?profit?=?Long.parseLong(key_Input());
System.out.println("應發獎金:"+bonus(profit));
}
//接受從鍵盤輸入的內容
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.求未知數
一個整數,它加上100后是一個完全平方數,再加上168又是一個完全平方數,請問該數是多少?
程序分析:在10萬以內判斷,先將該數加上100后再開方,再將該數加上268后再開方,如果開方后的結果滿足如下條件,即是結果。
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("所求的數是:"+n);
}
//判斷完全平方數
private?static?boolean?isCompSqrt(int?n){
boolean?isComp?=?false;
for(int?i=1;i
3.日期計算
輸入某年某月某日,判斷這一天是這一年的第幾天?
程序分析:以3月5日為例,應該先把前兩個月的加起來,然后再加上5天即本年的第幾天,特殊情況,閏年且輸入月份大于3時需考慮多加一天。
import java.util.Scanner;public class Prog14{
public static void main(String[] args){
Scanner scan = new Scanner(System.in).useDelimiter("\\D");//匹配非數字
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)+"天");
}
//判斷天數
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培訓機構的小編針對“常被考的3道Java實踐練習題”的內容進行的回答,希望對大家有所幫助,如有疑問,請在線咨詢,有專業老師隨時為你服務。
0基礎 0學費 15天面授
有基礎 直達就業
業余時間 高薪轉行
工作1~3年,加薪神器
工作3~5年,晉升架構
提交申請后,顧問老師會電話與您溝通安排學習