目录:

  • java编程题【11-30】
    • 程序11 :排列组合问题
    • 程序12 :分段函数求取提成问题
    • 程序13 :方程求解问题
    • 程序14 :判断日期是一年当中的第几天
    • 程序15 :三个数字之间的排序
    • 程序16 :9*9 乘法表
    • 程序17 :猴子吃桃问题
    • 程序18 :条件约束性比赛名单
    • 程序19 :打印半个菱形
    • 程序20 :斐波那契相关数列求和
    • 程序21 :递归求5的阶乘
    • 程序22 :计算10-15阶乘之和
    • 程序23 :求1-20的阶乘之和
    • 程序24 :逆序输出整数
    • 程序25 :回文数
    • 程序26 :星期几?
    • 程序27 :求素数的算法改进
    • 程序28 :冒泡排序
    • 程序29 :矩阵对角线之和
    • 程序30 :折半法数组排序
  • java编程题【1-10】
  • java编程题【31-40】

java编程题【11-30】

程序11 :排列组合问题

题目描述:
有1、2、3、4四个数,能组成多少个互不相同且无重复数字的三位数,都是多少
代码:

public class Programming11 {public static void main(String[] args) {int count = 0;for (int i = 1; i <= 4; i++) {for (int j = 1; j <= 4; j++) {for (int k = 1; k <= 4; k++) {if (k != i && k != j && i != j) {int num = i * 100 + j * 10 + k;count++;System.out.print(num + "\t");}}}}System.out.println("\n共能组成" + count + "个数");}
}

程序12 :分段函数求取提成问题

题目描述:
企业发放的奖金按照利润提成。利润低于或等于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%提成,从键盘输入当月利润,求应发放奖金总数
代码:

public class Programming12 {public static void main(String[] args) {System.out.println("请输入公司利润:");Scanner scanner = new Scanner(System.in);int profits = scanner.nextInt();double w = 0;if (profits <= 10) {w = profits * 0.1;} else if (profits > 10 && profits <= 20) {w = 10 * 0.1 + (profits - 10) * 0.075;} else if (profits > 20 && profits <= 40) {w = 10 * 0.1 + 10 * 0.075 + (profits - 20) * 0.05;} else if (profits > 40 && profits <= 60) {w = 10 * 0.1 + 10 * 0.075 + 20 * 0.05 + (profits - 40) * 0.03;} else if (profits > 60 && profits <= 100) {w = 10 * 0.1 + 10 * 0.075 + 20 * 0.05 + 20 * 0.03 + (profits - 60) * 0.015;} else if (profits > 100) {w = 10 * 0.1 + 10 * 0.075 + 20 * 0.05 + 20 * 0.03 + 40 * 0.015 + (profits - 100) * 0.01;}System.out.println("公司利润为:" + profits + "万");System.out.println("公司应当发放的奖金总数为:" + w + "万");}
}

程序13 :方程求解问题

题目描述:
一个整数加上100之后是一个完全平方数,加上168之后也是一个完全平方数,求这个数是多少?
代码:
计算机更擅长的是一个一个试出答案

public class Programming13 {public static void main(String[] args) {for (int i = -100; i < 1600; i++) {if (Math.sqrt(i + 100) % 1 == 0 && Math.sqrt(i + 168) % 1 == 0) {System.out.println(i);}}}
}

程序14 :判断日期是一年当中的第几天

题目描述:
输入某年某月某日,判断这一天是这一年的第几天
代码:

public class Programming14 {public static void main(String[] args) {Scanner scanner = new Scanner(System.in);System.out.println("请输入年份:");int year = scanner.nextInt();System.out.println("请输入月份:");int month = scanner.nextInt();System.out.println("请输入 日:");int day = scanner.nextInt();int sum = 0;for (int i = 1; i < month; i++) {int num = 0;switch (i) {case 1:case 3:case 5:case 7:case 8:case 10:case 12:num = 31;break;case 4:case 6:case 9:case 11:num = 30;break;case 2:if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)) {num = 29;} else {num = 28;}break;}sum = sum + num;}sum = sum + day;System.out.println(year + "年" + month + "月" + day + "日 是" + year + "年的第 " + sum + " 天,祝您开心度过每一天!");}}

程序15 :三个数字之间的排序

题目描述:
将x,y,z三个整数从小到大输出
代码:

public class Programming15 {public static void main(String[] args) {Scanner scanner = new Scanner(System.in);System.out.println("请输入第一个整数");int x = scanner.nextInt();System.out.println("请输入第二个整数");int y = scanner.nextInt();System.out.println("请输入第三个整数");int z = scanner.nextInt();int min = x;if (x > y) {min = y;if (y > z) {min = z;System.out.println(z + " " + y + " " + x);} else {if (x < z) {System.out.println(y + " " + x + " " + z);} else {System.out.println(y + " " + z + " " + x);}}} else {if (x > z) {min = z;System.out.println(z + " " + x + " " + y);} else {if (z < y) {System.out.println(x + " " + z + " " + y);} else {System.out.println(x + " " + y + " " + z);}}}f(8, 3, 5);}public static void f(int x, int y, int z) {/*** @description:考虑使用数组排序实现* @param x* @param y* @param z* @createDate: 2020/7/6 15:03* @return: void*/int arr[] = {x, y, z};Arrays.sort(arr);System.out.println(arr[0] + " " + arr[1] + " " + arr[2]);}}

程序16 :9*9 乘法表

题目描述:
规范输出9*9乘法表
代码:

public class Programming16 {public static void main(String[] args) {for (int i = 1; i < 10; i++) {for (int j = 1; j <= i; j++) {System.out.print(j + "*" + i + "=" + j * i + "\t");}System.out.println();}}
}

程序17 :猴子吃桃问题

题目描述:
猴子第一天摘下若干个桃子,当即吃了一半,还不过瘾,又多吃了一个,第二天早上又将剩下的桃子吃了一半,又多吃了一个。以后的每一天早上都吃了前一天剩下桃子数目的一半零一个。到第十天早上想再吃时,只剩下一个桃子了。求第一天共摘了多少个桃子。
代码:

public class Programming17 {public static void main(String[] args) {int x = 1;for (int i = 1; i <= 9; i++) {x = (x + 1) * 2;}System.out.println("猴子在第一天摘了 "+x+" 个桃子。");}
}

程序18 :条件约束性比赛名单

题目描述:
两个乒乓球队进行比赛,各出三人。甲队为a,b,c三人,乙队为x,y,z三人。已抽签决定比赛名单。有人向队员打听比赛的名单。a说他不和x比赛,c说他不和x,z比,编写程序找出三队赛手的名单。
代码:

public class Programming18 {public static void main(String[] args) {char arr1[] = {'a', 'b', 'c'};char arr2[] = {'x', 'y', 'z'};for (int i = 0; i < arr1.length; i++) {for (int j = 0; j < arr2.length; j++) {if (arr1[i] == 'a' && arr2[j] == 'x') {continue;} else if (arr1[i] == 'c' && (arr2[j] == 'x' || arr2[j] == 'z')) {continue;} else if (arr1[i] == 'a' && arr2[j] == 'y') {continue;} else if (arr1[i] == 'b' && arr2[j] == 'y') {continue;} else if (arr1[i] == 'b' && arr2[j] == 'z') {continue;} else {System.out.println(arr1[i] + " VS " + arr2[j]);}}}}
}

程序19 :打印半个菱形

题目描述:
打印以下图形:

代码:

public class Programming19 {public static void main(String[] args) {int count = 0;for (int i = 5; i >= 1; ) {for (int j = 1; j <= 5; j++) {if (j < i) {System.out.print(" ");} else {System.out.print("*");}}System.out.println();count++;if (count < 5) {i--;} else if (count < 10) {i++;} else {break;}}}}

程序20 :斐波那契相关数列求和

题目描述:
求数列 2/1 3/2 5/3 8/5 13/8 21/13 …的前20项和
代码:

public class Programming20 {public static void main(String[] args) {double x = 1, y = 2, sum = y / x, a;for (int i = 1; i < 20; i++) {a = x;x = y;y = a;sum = sum + y / x;}System.out.println("该数列的前20项之和为:" + sum);}
}

程序21 :递归求5的阶乘

题目描述:
利用递归求5的阶乘
代码:

public class Programming21 {public static void main(String[] args) {System.out.println(jc(5));}public static int jc(int num) {int res = 1;if (num == 1) {res = num;return res;} else {return jc(num - 1) * num;}}}

程序22 :计算10-15阶乘之和

题目描述:
计算10-15阶乘之和
分析:只要计算10的阶乘即可,其余迭代
代码:

public class Programming22 {public static void main(String[] args) {int res = 1;for (int i = 1; i <= 10; i++) {res = res * i;}int factorial10 = res;int factorial11 = factorial10 * 11;int factorial12 = factorial11 * 12;int factorial13 = factorial12 * 13;int factorial14 = factorial13 * 14;int factorial15 = factorial14 * 15;int sum = factorial10 + factorial11 + factorial12 + factorial13 + factorial14 + factorial15;System.out.println(sum);}}

程序23 :求1-20的阶乘之和

题目描述:
求1-20的阶乘之和
代码:

public class Programming23 {public static void main(String[] args) {int sum = 0;int fac = 1;for (int i = 1; i <= 20; i++) {fac = fac * i;sum = sum + fac;}System.out.println("1-20的阶乘之和为:" + sum);}
}

程序24 :逆序输出整数

题目描述:
给一个不低于5位的整数,输出其位数并逆序打印其数字 使用长整型最多输入18位
代码:

public class Programming24 {public static void main(String[] args) {Scanner scanner = new Scanner(System.in);long num = scanner.nextLong();int n = 0;for (long i = num; i != 0; i = i / 10) {n++;System.out.print(i % 10 + " ");}System.out.println("\n输入的整数是" + n + "位数");}}

程序25 :回文数

题目描述:
输入一个五位数,判断其是否为回文数
回文数:将其数字反向排列的数与其本身相同。如12321,14541是回文数
代码:

public class Programming25 {public static void main(String[] args) {Scanner scanner = new Scanner(System.in);int n = scanner.nextInt();int num = n;int a = num % 10;num = num / 10;int b = num % 10;num = num / 10;num = num / 10;int d = num % 10;num = num / 10;int e = num % 10;if (a == e && b == d) {System.out.println(n + "是一个回文数");} else {System.out.println(n + "不是一个回文数");}String s = Integer.toString(n);char arr[] = s.toCharArray();boolean res = true;for (int i = 0; i < arr.length; i++) {if (arr[i] == arr[arr.length - 1 - i]) {continue;} else {res = false;}}if (res) {System.out.println(n + "是一个回文数");} else {System.out.println(n + "不是一个回文数");}}
}

程序26 :星期几?

题目描述:
输入星期的第一个字母来判断是星期几,如果第一个字母一样则接着判断第二个
代码:

public class Programming26 {public static void main(String[] args) {Scanner scanner = new Scanner(System.in);System.out.println("请输入第一个字母:");String s = scanner.nextLine();String res = "";switch (s) {case "M":res = "星期一";break;case "T":System.out.println("请输入第二个字母:");String s1 = scanner.nextLine();if (s1 == "u") {res = "星期二";} else {res = "星期四";}break;case "W":res = "星期三";break;case "F":res = "星期五";break;case "S":System.out.println("请输入第二个字母:");String s2 = scanner.nextLine();if (s2 == "a") {res = "星期六";} else {res = "星期日";}break;}System.out.println(res);}
}

程序27 :求素数的算法改进

题目描述:
求100以内的素数的另一种算法 效率高但通行率低
代码:

public class Programming27 {public static void main(String[] args) {int a[] = {2, 3, 5, 7};boolean res = true;for (int j = 0; j < 4; j++) {System.out.print(a[j] + " ");}for (int i = 11; i < 100; i++) {for (int j = 0; j < 4; j++) {if (i % a[j] == 0) {res = false;break;}}if (res) {System.out.print(i + " ");}res = true;}}
}

程序28 :冒泡排序

题目描述:
对十个数进行数字排序
代码:

public class Programming28 {public static void main(String[] args) {Scanner scanner = new Scanner(System.in);int arr[]=new int[10];System.out.println("请输入十个数:");for (int i = 0; i < arr.length; i++) {arr[i] = scanner.nextInt();}for (int i = 0; i < arr.length; i++) {for (int j = i+1; j < arr.length; j++) {if (arr[i] > arr[j]) {int t = arr[i];arr[i] = arr[j];arr[j] = t;}}}for (int i = 0; i < arr.length; i++) {System.out.print(arr[i]+" ");}}
}

程序29 :矩阵对角线之和

题目描述:
求一个3*3矩阵对角元素之和
代码:

public class Programming29 {public static void main(String[] args) {Scanner scanner = new Scanner(System.in);int arr[][] = new int[3][3];for (int i = 0; i < 3; i++) {for (int j = 0; j < 3; j++) {int a = scanner.nextInt();arr[i][j] = a;}}for (int i = 0; i < 3; i++) {for (int j = 0; j < 3; j++) {System.out.print(arr[i][j]+" ");}System.out.println();}int sum = 0;for (int i = 0; i < 3; i++) {sum = sum + arr[i][i];}System.out.println("其对角线之和为: "+sum);}
}

程序30 :折半法数组排序

题目描述:
将一个数字插入到一个已经排好序的数组中
代码:

public class Programming30 {public static void main(String[] args) {Scanner scanner = new Scanner(System.in);while (true) {int n = scanner.nextInt();int arr[] = {1, 4, 10, 18, 23, 36, 41, 56};int res[] = new int[arr.length + 1];int a = 0, b = arr.length - 1, index = 0;//折半法找到数组应该插到的位置indexfor (int i = 0; i <= 8; i++) {if (arr[(b + a) / 2] > n) {b = (b + a) / 2;} else if (arr[(b + a) / 2] == n) {index = (b + a) / 2;break;} else {a = (b + a) / 2;}if (b - a == 1) {index = b;break;}}if (arr[arr.length - 1] <= n) {index = arr.length;}if (arr[0] >= n) {index = 0;}//下标index的数组值的复制res[index] = n;//下标index前的数组的复制for (int j = 0; j < index; j++) {res[j] = arr[j];}//下标index后的数组的复制for (int j = res.length - 1; j > index; j--) {res[j] = arr[j - 1];}//遍历输出新数组int num = 0;for (int each : res) {if (num == res.length - 1) {System.out.print(each);} else {System.out.print(each + ",");}num++;}}}
}

java编程题【1-10】

java编程题【31-40】

非常经典的java编程题全集-共50题(11-30)相关推荐

  1. 质量不同的球java编程_荐非常经典的java编程题全集-共50题(1-10)...

    非常经典的java编程题 程序1:斐波那契数列问题 题目概述: 古典问题: 有一对兔子,从出生第三个月起每月都生一对兔子,小兔子长到第三个月后每个月又生一对兔子,假如兔子都不死,问每个月的兔子总数为多 ...

  2. java编程50_荐非常经典的java编程题全集-共50题(1-10)...

    非常经典的java编程题 程序1:斐波那契数列问题 题目概述: 古典问题: 有一对兔子,从出生第三个月起每月都生一对兔子,小兔子长到第三个月后每个月又生一对兔子,假如兔子都不死,问每个月的兔子总数为多 ...

  3. java经典50道_50道经典的JAVA编程题(41-45)

    50道经典的JAVA编程题(41-45),苦逼的程序猿,晚上睡不着了编程吧~今天坚持做10道题!发现编程能是我快乐...O(∩_∩)O哈哈~能平静我烦乱的心,剩下5道题留到考试完了再做吧!该睡觉了.. ...

  4. 《剑指 Offer I》刷题笔记 41 ~ 50 题

    <剑指 Offer I>刷题笔记 41_50 排序(中等) 41. 最小的k个数# _解法1:排序 API + 数组复制 API 42. 数据流中的中位数 _解法1:暴力 搜索和回溯算法( ...

  5. 非常经典的JAVA编程题全集

    [程序1] TestRabbit.java 题目:古典问题:有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔子长到第三个月后每个月又生一对兔子,假如兔子都不死,问每个月的兔子总数为多少?  1. ...

  6. java编程题全集及答案_名师精品JAVA编程题全集(100题及答案)

    1.Java程序设计总复习题1.编写一个Java程序在屏幕上输出"你好!".(p13,例1-1)/pYogYammenameHellowoYld.javapublicclassHe ...

  7. 非常经典的JAVA编程题(素数)

    代码下载:https://github.com/IsResultXaL/Algorithm/blob/master/src/FindPrimeNumber.java 有更好的方案请在评论里分享! 题目 ...

  8. 非常经典的JAVA编程题(水仙花数)

    代码下载:https://github.com/IsResultXaL/Algorithm/blob/master/src/FindDaffodilNumber.java 有更好的方案请在评论里分享! ...

  9. Java练习、每日一题、共100题

    Java每日一题:1   编写一个 Java 程序, 用 if-else 语句判断某年份是否为闰年. * 经查阅资料:年分为闰年和平年. * 闰年的判断方法: *              公历年份是 ...

  10. Java分段函数选择结构,编程流程作业选择结构(50题)

    单分支选择 1.输入一个整数x,判断它是否为3的倍数,如果是则输出它. 2.输入整数a和b,若a2+b2<100,则输出a2+b2的各位上的数字. 3.输入一个字符,如果是数字字符,则转换成其对 ...

最新文章

  1. 知识图谱前沿跟进,看这篇就够了,Philip S. Yu 团队发布权威综述,六大开放问题函待解决!...
  2. C++编程思想重点笔记(下)
  3. 成功解决ValueError: `bins` must be positive, when an integer
  4. Spring-data-redis入门
  5. 人脸变形算法——MLS
  6. 程序=数据结构+算法
  7. LeetCode刷题实战(13):Roman to Integer
  8. 单片机led闪烁代码_单片机驱动LED发光二极管的电路以及编程
  9. MySQL实战—更新过程
  10. 彻底理解 Cookie、Session、Token
  11. 欧氏空间内积定义_三、n维空间简介(6)矢量平移和测地线
  12. 更新失败 连接超时_苹果发布 iOS iPadOS 更新 修复蓝牙连接失败等错误
  13. windows 通过 bat 脚本后台启动 jar 包,通过 jps 找到 pid,然后停止指定 jar 包,附 linux shell 脚本启停脚本
  14. arduino的串口缓冲区_C#无法从串口Arduino读取完整缓冲区
  15. i5双线程_新老系统多项测试:多线程运算谁更靠谱
  16. python 步数_用python如何修改微信和支付宝每天走路的步数
  17. Linux这些年经历了什么?
  18. CV之IE之Inception:基于TF框架利用Inception模型+GD算法的某层网络图像生成不同尺寸和质量的Deep Dream幻觉梦境图片(特征可视化实现图像可解释性)—五个架构设计思维导图
  19. java怎么把数据返回给客户端_java 服务器怎样给客户端传输数据
  20. mysql按 结束不了语句_每一条 mysql 命令必须以( )结束,否则系统判断语句尚未结束,暂不执行_大学计算机A1重修答案_学小易找答案...

热门文章

  1. QT编程ARM下摄像头无法使用怎么办
  2. thinkphp——登录界面
  3. php html ubb,PHP写的UBB代码转换HTML代码
  4. unity webPlayer
  5. jmeter压力测试
  6. pta冒泡排序c语言_PTA 冒泡排序
  7. DEVC编译器快捷键大全
  8. 四款常见IT自动化运维工具简单介绍-行云管家
  9. python五子棋游戏代码实现
  10. mysql游标嵌套怎么写,mysql游标和嵌套游标