Java流程控制语句习题

/*各个变量的命名不规范,若要参考,请自己对各个变量进行规范命名*/

/*1、企业发放的奖金根据利润提成。利润低于或等于10万元时,奖金可提10%;利润高于10万元,低于或等于20万元时,高于10万元的部分,可提成7.5%;高于20万,低于或等于40万时,高于20万元的部分,可提成5%;高于40万,低于或等于60万时,高于40万元的部分,可提成3%;高于60万,低于或等于100万时,高于60万元的部分,可提成1.5%,高于100万元时,超过100万元的部分按1%提成,在程序中设定一个变量为当月利润,求应发放奖金总数?(知识点:条件语句*/

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("优秀");

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年后的年薪,并统计未来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、输入一个数字,判断是一个奇数还是偶数*/

public class Decidenum {

public static void main(String[] args) {

int c1 = 51;

if (c1 % 2 != 0) {

System.out.println("奇数");

} else {

System.out.println("偶数");

}

}

}

输出:

/*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.判断一个数字是否能被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的分数,如果不是0~100之间,打印分数无效,根据分数等级打印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("打印分数无效");

}

}

}

输出:

/*10、输入三个整数x,y,z,请把这三个数由小到大输出*/

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位的正整数,求它是几位数,分别打印出每一位数字*/

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("五位数");

System.out.println("万位是" + wan + "千位是" + qian + "百位是" + bai + "十位是" + shi + "个位是" + ge);

} else if (qian != 0) {

System.out.println("四位数");

System.out.println("千位是" + qian + "百位是" + bai + "十位是" + shi + "个位是" + ge);

} else if (bai != 0) {

System.out.println("三位数");

System.out.println("百位是" + bai + "十位是" + shi + "个位是" + ge);

} else if (shi != 0) {

System.out.println("二位数");

System.out.println("十位是" + shi + "个位是" + ge);

} else {

System.out.println("一位数");

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循环,while循环,do循环求1到100之间所有能被3整除的整数的和*/

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之间的数,但是不包括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.编写一个程序,求整数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的最小的质数*/

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位整数,求将该数反转以后的数,如原数为1234,反转后的数位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 + "反转后的数为:" + sum17);

}

}

输出:

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 194,670评论 5 460
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 81,928评论 2 371
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 141,926评论 0 320
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 52,238评论 1 263
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 61,112评论 4 356
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 46,138评论 1 272
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 36,545评论 3 381
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 35,232评论 0 253
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 39,496评论 1 290
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 34,596评论 2 310
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 36,369评论 1 326
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 32,226评论 3 313
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 37,600评论 3 299
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 28,906评论 0 17
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,185评论 1 250
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 41,516评论 2 341
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 40,721评论 2 335

推荐阅读更多精彩内容

  • 【程序1】 题目:古典问题:有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔子长到第三个月后每个月又生一对兔...
    开心的锣鼓阅读 3,302评论 0 9
  • Java经典问题算法大全 /*【程序1】 题目:古典问题:有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔子...
    赵宇_阿特奇阅读 1,835评论 0 2
  • 50道经典Java编程练习题,将数学思维运用到编程中来。抱歉哈找不到文章的原贴了,有冒犯的麻烦知会声哈~ 1.指数...
    OSET我要编程阅读 6,812评论 0 9
  • ORACLE自学教程 --create tabletestone ( id number, --序号usernam...
    落叶寂聊阅读 1,055评论 0 0
  • (1.编写一个计算各种形状的面积和周长的程序。 要求:父类Shape2D为一个抽象类,其中包含计算周长和计算面积两...
    盼旺阅读 1,966评论 0 1