Java编程题练习(二)

来源:互联网 发布:网络现在做什么挣钱 编辑:程序博客网 时间:2024/06/02 05:16

private static void test1() {// TODO Auto-generated method stubString flag = null;do {Scanner sc = new Scanner(System.in);System.out.println("输入课程代号:");int num = sc.nextInt();switch (num) {case 1:System.out.println("使用Java语言理解程序逻辑");flag = sc.nextLine();break;case 2:System.out.println("使用HTML语言开发商业站点");flag = sc.nextLine();break;case 3:System.out.println("使用SQL Server管理和查询数据");flag = sc.nextLine();break;case 4:System.out.println("使用C#开发数据库应用程序");flag = sc.nextLine();break;default:System.out.println("你输入的课程代号有误");break;}System.out.println("是否需要继续输入y/n:");flag = sc.nextLine();} while (flag.equals("y"));}

private static void test2() {// TODO Auto-generated method stubint money = 10000;double ray = 0.03;double sum = 0;for (int i = 1; i <= 5; i++) {sum = money * ray + money + sum;}System.out.println("本金为:" + sum);}


private static void test3() {// TODO Auto-generated method stubint sum = 0;for (int i = 1; i <= 100; i++) {if ((i % 10 == 3) || (i == 3)) {continue;}sum += i;}System.out.println("和为:" + sum);}

private static void test4() {// TODO Auto-generated method stubScanner sc = new Scanner(System.in);System.out.println("输入打印的行数:");int n = sc.nextInt();for (int i = 0; i < n; i++) {for (int j = 5; j > i; j--) {System.out.print(" ");}// System.out.println();for (int j = 0; j < 2 * i + 1; j++) {System.out.print("*");}System.out.println();}}



private static void test5() {int number = (int) (Math.random() * 10);System.out.println("随机数为"+number);int counter = 0;Scanner sc = new Scanner(System.in);for (int i = 1; i <= 20; i++) {System.out.println("第" + i + "次猜,请输入你的答案:");int num = sc.nextInt();System.out.println("你输入的数字为:" + num);// int flag=num>number?1:2;if (num > number) {System.out.println("太大");counter++;//continue;} else if (num < number) {System.out.println("太小");counter++;//continue;} else{if (counter>=2&&counter<=6) {System.out.println("这么快就猜出来了,很聪明么!");break;}else if (counter>7) {System.out.println("小同志,尚需努力啊! ");break;}else if (counter==1) {System.out.println("很厉害");break;}}}}

private static void tsst6() {// TODO Auto-generated method stubfor (int i = 1; i <= 9; i++) {for (int j = 1; j <= i; j++) {System.out.print(j + "*" + i + "=" + j * i + "\t");}System.out.println();}}

private static void test7() {// TODO Auto-generated method stubScanner sc = new Scanner(System.in);System.out.println("请输入四位整数:");int num = sc.nextInt();System.out.println("你输入的四位整数位:" + num);int qian = num / 1000;int bai = num % 1000 / 100;int shi = num % 1000 % 100 / 10;int ge = num % 1000 % 100 % 10;qian = (qian += 5) % 10;bai = (bai += 5) % 10;shi = (shi += 5) % 10;ge = (ge += 5) % 10;int result = qian * 1000 + bai * 100 + shi * 10 + ge;System.out.println("和除以10的余数:" + result);}