/*各個變量的命名不規(guī)范,若要參考拄衰,請自己對各個變量進行規(guī)范命名*/
/*1、企業(yè)發(fā)放的獎金根據(jù)利潤提成饵骨。利潤低于或等于10萬元時翘悉,獎金可提10%;利潤高于10萬元居触,低于或等于20萬元時镐确,高于10萬元的部分,可提成7.5%饼煞;高于20萬,低于或等于40萬時诗越,高于20萬元的部分砖瞧,可提成5%;高于40萬嚷狞,低于或等于60萬時块促,高于40萬元的部分,可提成3%床未;高于60萬竭翠,低于或等于100萬時,高于60萬元的部分薇搁,可提成1.5%斋扰,高于100萬元時,超過100萬元的部分按1%提成啃洋,在程序中設定一個變量為當月利潤传货,求應發(fā)放獎金總數(shù)?(知識點:條件語句*/
public class CompanySalary {
public static void main(String[] args) {
int sal = 300000;
double comm = 0;
if (sal <= 100000) {
comm = sal * 0.1;
System.out.println(comm);
} else if (sal > 100000 && sal <= 200000) {
comm = 100000 * 0.1 + 0.075 * (sal - 100000);
System.out.println(comm);
} else if (sal > 200000 && sal <= 400000) {
comm = 100000 * 0.1 + 0.075 * 100000 + 0.05 * (sal - 200000);
System.out.println(comm);
} else if (sal > 400000 && sal <= 600000) {
comm = 100000 * 0.1 + 0.075 * 100000 + 200000 * 0.05 + 0.03 * (sal - 400000);
System.out.println(comm);
} else if (sal > 600000 && sal <= 1000000) {
comm = 100000 * 0.1 + 0.075 * 100000 + 200000 * 0.05 + 0.03 * 200000 + 0.015 * (sal - 600000);
System.out.println(comm);
} else {
comm = 100000 * 0.1 + 0.075 * 100000 + 200000 * 0.05 + 0.03 * 200000 + 0.015 * 400000
+ 0.01 * (sal - 1000000);
System.out.println(comm);
}
}
}
輸出:
/*2宏娄、給定一個成績a问裕,使用switch結構求出a的等級。A:90-100孵坚,B:80-89粮宛,C:70-79,D:60-69卖宠,E:0~59(知識點:條件語句switch*/
public class Scoregrade {
public static void main(String[] args) {
int a1 = 68;
int b1 = a1 / 10;
switch (b1) {
case 9:
System.out.println("優(yōu)秀");
break;
case 8:
System.out.println("良好");
break;
case 7:
System.out.println("中等");
break;
case 6:
System.out.println("及格");
break;
default:
System.out.println("不及格");
break;
}
}
}
輸出:
/*3巍杈、假設某員工今年的年薪是30000元,年薪的年增長率6%逗堵。編寫一個Java應用程序計算該員工10年后的年薪秉氧,并統(tǒng)計未來10年(從今年算起)總收入*/
/*如果對計算精度要求高的應該使用Big Decimal進行計算,Big Decimal的介紹以及程序請參考:
https://www.cnblogs.com/LeoBoy/p/6056394.html*/
public class YearSalary {
public static void main(String[] args) {
double salary = 30000;
for (int i = 0; i < 10; i++) {
salary += salary * 0.06 * i;
if (i == 9) {
System.out.println(salary);
}
}
}
}
輸出:
/*4蜒秤、猴子第一天摘下若干個桃子汁咏,當即吃了一半亚斋,還不癮,又多吃了一個攘滩,第二天早上又將剩下的桃子吃掉一半帅刊,又多吃了一個。以后每天早上都吃了前一天剩下的一半零一個漂问。到第10天早上想再吃時赖瞒,見只剩下一個桃子了。求第一天共摘了多少*/
public class MonkeyPeach {
public static void main(String[] args) {
int x4 = 1;
double all = 1;
while (x4 < 10) {
all = (all + 1) * 2;
x4++;
}
System.out.println(all);
}
}
輸出:
/*5蚤假、輸入一個數(shù)字栏饮,判斷是一個奇數(shù)還是偶數(shù)*/
public class Decidenum {
public static void main(String[] args) {
int c1 = 51;
if (c1 % 2 != 0) {
System.out.println("奇數(shù)");
} else {
System.out.println("偶數(shù)");
}
}
}
輸出:
/*6、編寫程序磷仰, 判斷一個變量x的值袍嬉,如果是1,輸出x=1灶平,如果是5伺通,輸出x=5,如果是 10逢享,輸出x=10罐监,除了以上幾個值,都輸出x=none*/
public class DecideX {
public static void main(String[] args) {
int x = 8;
if (x == 1 || x == 5 || x == 10) {
System.out.println("x=" + x);
} else {
System.out.println("x=none");
}
}
}
輸出:
/*7.判斷一個數(shù)字是否能被5和6同時整除(打印能被5和6整除)瞒爬,或只能被5整除(打印能被5整除)弓柱,或只能被6整除,(打印能被6整除)侧但,不能被5或6整除吆你,(打印不能被5或6整除)*/
public class DecideforNum {
public static void main(String[] args) {
int y = 13;
if (y % 5 == 0 && y % 6 == 0) {
System.out.println("能被5和6整除");
} else if (y % 5 == 0) {
System.out.println("能被5整除");
} else if (y % 6 == 0) {
System.out.println("能被6整除");
} else {
System.out.println("不能被5或6整除");
}
}
}
輸出:
/*8、輸入一個年份俊犯,判斷這個年份是否是閏年*/
public class InputYear {
public static void main(String[] args) {
int year = 2015;
if (year % 4 == 0 && year % 100 != 0) {
System.out.println("是閏年");
} else if (year % 400 == 0) {
System.out.println("是閏年");
} else {
System.out.println("不是閏年");
}
}
}
輸出:
/*9.輸入一個0~100的分數(shù)妇多,如果不是0~100之間,打印分數(shù)無效燕侠,根據(jù)分數(shù)等級打印A,B,C,D,E*/
public class InputNim {
public static void main(String[] args) {
int f1 = 8;
if (f1 >= 0 && f1 <= 100) {
int fi = f1 / 10;
switch (fi) {
case 9:
System.out.println("A");
break;
case 8:
System.out.println("B");
break;
case 7:
System.out.println("C");
break;
case 6:
System.out.println("D");
break;
default:
System.out.println("E");
break;
}
} else {
System.out.println("打印分數(shù)無效");
}
}
}
輸出:
/*10者祖、輸入三個整數(shù)x,y,z,請把這三個數(shù)由小到大輸出*/
import java.util.Scanner;
public class CompareNum {
public static void main(String[] args) {
Scanner v = new Scanner(System.in);
int x1 = v.nextInt();
int y1 = v.nextInt();
int z1 = v.nextInt();
if (x1 < y1 && x1 < z1 && y1 < z1) {
System.out.println(x1 + "<" + y1 + "<" + z1);
} else if (x1 < y1 && x1 < z1 && y1 > z1) {
System.out.println(x1 + "<" + z1 + "<" + y1);
} else if (x1 < y1 && x1 > z1 && y1 > z1) {
System.out.println(z1 + "<" + x1 + "<" + y1);
} else if (x1 > y1 && x1 > z1 && y1 > z1) {
System.out.println(z1 + "<" + y1 + "<" + x1);
} else if (x1 > y1 && x1 < z1 && y1 < z1) {
System.out.println(y1 + "<" + x1 + "<" + z1);
} else if (x1 > y1 && x1 > z1 && y1 < z1) {
System.out.println(y1 + "<" + z1 + "<" + x1);
}
}
}
輸出:
/*11.有一個不多于5位的正整數(shù)绢彤,求它是幾位數(shù)七问,分別打印出每一位數(shù)字*/
import java.util.Scanner;
public class Calculationnum {
public static void main(String[] args) {
Scanner m = new Scanner(System.in);
int zheng = m.nextInt();
int wan = zheng / 10000;
int qian = zheng / 1000 % 10;
int bai = zheng / 100 % 10;
int shi = zheng / 10 % 10;
int ge = zheng % 10;
if (wan != 0) {
System.out.println("五位數(shù)");
System.out.println("萬位是" + wan + "千位是" + qian + "百位是" + bai + "十位是" + shi + "個位是" + ge);
} else if (qian != 0) {
System.out.println("四位數(shù)");
System.out.println("千位是" + qian + "百位是" + bai + "十位是" + shi + "個位是" + ge);
} else if (bai != 0) {
System.out.println("三位數(shù)");
System.out.println("百位是" + bai + "十位是" + shi + "個位是" + ge);
} else if (shi != 0) {
System.out.println("二位數(shù)");
System.out.println("十位是" + shi + "個位是" + ge);
} else {
System.out.println("一位數(shù)");
System.out.println("個位是" + ge);
}
}
}
輸出:
/*12、編寫一個程序茫舶,計算郵局匯款的匯費械巡。如果匯款金額小于100元,匯費為一元,如果金額在100元與5000元之間讥耗,按1%收取匯費有勾,如果金額大于5000元,匯費為50元古程。匯款金額由命令行輸入*/
import java.util.Scanner;
public class CalculateStamp {
public static void main(String[] args) {
Scanner im = new Scanner(System.in);
int hk = im.nextInt();
double mm = 0;
if (hk < 100) {
mm = 1;
} else if (hk >= 100 && hk < 5000) {
mm = hk * 0.01;
} else {
mm = 50;
}
System.out.println("匯費為:" + mm);
}
}
輸出:
? ? ? ? /*13蔼卡、分別使用for循環(huán),while循環(huán)挣磨,do循環(huán)求1到100之間所有能被3整除的整數(shù)的和*/
public class DoWhileFor {
public static void main(String[] args) {
int sum1 = 0;
for (int i = 1; i <= 100; i++) {
if (i % 3 == 0) {
sum1 += i;
}
}
System.out.println(sum1);
int sum2 = 0;
int i12 = 1;
while (i12 <= 100) {
if (i12 % 3 == 0) {
sum2 += i12;
}
i12++;
}
System.out.println(sum2);
int sum3 = 0;
int i23 = 1;
do {
if (i23 % 3 == 0) {
sum3 += i23;
}
i23++;
} while (i23 <= 100);
System.out.println(sum3);
}
}
輸出:
? ? ? /* 14雇逞、輸出0-9之間的數(shù),但是不包括5*/
public class OutputNum {
public static void main(String[] args) {
for(int i=0;i<10;i++) {
? ? ? ? if(i==5) {
? ? ? ? continue;
? ? ? ? }
? ? ? ? System.out.println(i+" ");
? ? ? ? }
}
}
輸出:
? ? ? ? /*15.編寫一個程序茁裙,求整數(shù)n的階乘塘砸,例如5的階乘是1*2*3*4*5 */
import java.util.Scanner;
public class OutputN {
public static void main(String[] args) {
Scanner sdc = new Scanner(System.in);
int sd = sdc.nextInt();
int sdsum = 1;
for (int i = 1; i <= sd; i++) {
sdsum = sdsum * i;
}
System.out.println(sdsum);
}
}
輸出:
? ? ? ? /*16、編寫一個程序晤锥,找出大于200的最小的質數(shù)*/
public class FindNum {
public static void main(String[] args) {
int num16;
int i16;
for (num16 = 200;; num16++) {
boolean b16 = true;
for (i16 = 2; i16 < num16 / 2; i16++) {
if (num16 % i16 == 0) {
b16 = false;
}
}
if (b16) {
break;
}
}
System.out.println(num16);
}
}
輸出:
? ? ? ? /*17.由命令行輸入一個4位整數(shù)谣蠢,求將該數(shù)反轉以后的數(shù),如原數(shù)為1234查近,反轉后的數(shù)位4321 */
import java.util.Scanner;
public class Reserceses {
public static void main(String[] args) {
Scanner iny = new Scanner(System.in);
int num17 = iny.nextInt();
int n1, n2, n3, n4;
n1 = num17 / 1000;
n2 = num17 % 1000 / 100;
n3 = num17 % 1000 % 100 / 10;
n4 = num17 % 1000 % 100 % 10;
int sum17 = n4 * 1000 + n3 * 100 + n2 * 10 + n1;
System.out.println(num17 + "反轉后的數(shù)為:" + sum17);
}
}
輸出: