目录
03:随机产生一个1-100之间的整数,看能几次猜中。要求:猜的次数不能超过7次,每次猜完之后都要提示“大了”或者“小了”。
04:写一个方法,此方法实现输出100-999之间的水仙花数。
09:打印出1000-2000年中所有的闰年,并以每行四个数的形式输出
10:定义两个整数a、b,a、b的取值范围在0-9之间,给出所有符合a+b=12的组合。
11:A、B、C、D分别为0——9之间的整数,求出满足AB+CD=DA条件的数。
12:随机生成一个五位以内的数,然后输出该数共有多少位,每位分别是什么
15:实现双色球的彩票功能。规则:从36个红球中随机选择不重复的6个数,从15个篮球中随机选择1个组成一注彩票。可以选择买多注。
19:随机产生一个字母,如果是大写字母则输出“yes”,否则输出“no”
20:随机产生一个字符,判断:如果为大写字母则输出“大写字母”;如果为小写字母则输出“小写字母”;否则怎输出“其他字符”;
21:求100到1000之间的所有能被5和6整除的整数,每行显示5个
22:求和:1/3+3/5+5/7+7/9+………..+97/99
24:山上有一口缸可以装50升水,现在有15升水。老和尚叫小和尚下山挑水,每次可以挑5升。问:小和尚要挑几次水才可以把水缸挑满?通过编程解决这个问题。
25:李白无事街上走,提壶去买酒。遇店加一倍,见花喝一斗,五遇花和店,喝光壶中酒,试问李白壶中原有多少斗酒?(使用for循环结构编程实现)
29:将100元兑换为1元、5元、10元的零钱,请问有多少种兑换方法?
30:用100元人民币兑换10元,5元,1元的纸币(每种都要有)共50张,计算有多少种兑换方案
31:设计Java程序,假设有50瓶饮料,喝完3个空瓶可以换一瓶饮料,依次类推,请问总共喝了多少瓶饮料?
package com.textday002;
public class WorkBook{
????public static void main(String[] args) {
// ???????01:求10以内的偶数的和。
????????int sum=0;
????????for(int i=0;i<=10;i++ ){
????????????if(i%2==0)
????????????????sum+=i;
????????}
????????System.out.println("10以内的偶数的和:"+sum);
????}
}
(素数:一个大于1的自然数,除了1和它本身外,不能被其他自然数整除)
package com.textday002;
public class WorkBook{
????public static void main(String[] args) {
// ?????02:求100以内的所有素数
// ????(素数:一个大于1的自然数,除了1和它本身外,不能被其他自然数整除)
????????int i,j,count=0;
????????for(i=2;i<=100;i++){
????????????for(j=2;j<=i/2;j++){
????????????????if(i%j==0){
????????????????????break;
????????????????}
????????????}
????????????if(j>i/2){
????????????????count++;
????????????????System.out.println(i+"是素数");
????????????}
????????}
????????System.out.println("素数共有:"+count+"个");
????}
}
package com.textday002;
import java.util.Scanner;
public class WorkBook{
????public static void main(String[] args) {
// ????03:随机产生一个1-100之间的整数,看能几次猜中。
// ????要求:猜的次数不能超过7次,每次猜完之后都要提示“大了”或者“小了”。
????????System.out.println("你猜的次数不能超过7次");
????????int number= (int) (Math.random()*100+1);
????????Scanner scan= new Scanner(System.in);
????????int number1;
????????int i;
????????for(i=1;i<=7;i++){
????????????System.out.print("请输入你第"+i+"次猜的数:");
????????????number1=scan.nextInt();
????????????if(number == number1){
????????????????System.out.println("恭喜你第"+i+"次猜中了");break;
????????????}else if(number>number1){
????????????????System.out.println("小了");
????????????}else{
????????????????System.out.println("大了");
????????????}
????????}
????????if(i==7)
????????????System.out.println("很遗憾你7次都没猜中");
????????System.out.println("程序结束");
????}
}
package com.textday002;
public class WorkBook{
????public static void main(String[] args) {
// ????04:写一个方法,此方法实现输出100-999之间的水仙花数。
????????for(int i=100;i<1000;i++){
????????????int ge=i%10,shi =i/10%10,bai = i/100%10;
????????????if(Math.pow(ge,3)+Math.pow(shi,3)+Math.pow(bai,3)==i){
????????????????System.out.println(i+"是水仙花数");
????????????}
????????}
????}
}
package com.textday002;
import static java.lang.System.*;
public class WorkBook{
????public static void main(String[] args) {
// ????05:输出小写的a-z以及大写的在Z—A
????????char lower= 'a';
????????for(int i=0;i<26;i++)
????????????System.out.print((char)(lower+i)+" ?");
????????char upper = ?'Z';
????????System.out.println();
????????for(int i=0;i<26;i++)
????????????System.out.print((char)(upper-i)+" ?");
????}
}
package com.textday002;
public class WorkBook{
????public static void main(String[] args) {
// ????06:求出1-3+5-7+9-…..101的和
????????//用tag作为标记是+或者-
????????int sum=0,tag = 1;
????????for(int i =1;i<=101;i++){
????????????if(tag == 1){
????????????????sum+=i;
????????????}else{
????????????????sum-=i;
????????????}
????????????if(tag==1){
????????????????tag=0;
????????????}else{
????????????????tag=1;
????????????}
????????}
????????System.out.println("1-3+5-7+9-...101="+sum);
????}
}
package com.textday002;
public class WorkBook{
????public static void main(String[] args) {
????????// 07:求出1-1/2+1/3-1/4…..1/100的和
????????double sum=0;
????????for(int i=1;i<=100;i++){
???????????if(i%2==1){ ?//分母是奇数是+
???????????????sum+=1.0/i;
???????????}else{
???????????????sum-=1.0/i;
???????????}
????????}
????????System.out.println("1-1/2+1/3-1/4+...1/100="+sum);
????}
}
package com.textday002;
public class WorkBook{
????public static void main(String[] args) {
????????// 08:输出20-80之间能被3整除的整数,每5个一行
????????int i=20,count=0;
????????while(i<81){
????????????if( i%3 == 0){
????????????????System.out.print(i+" ?");
????????????????count++;
????????????}
????????????if(count%5==0){
????????????????System.out.println();
????????????}
????????????i++;
????????}
????}
}
package com.textday002;
public class WorkBook{
????public static void main(String[] args) {
????????// 09:打印出1000-2000年中所有的闰年,并以每行四个数的形式输出
????????int count=0;
????????for(int i=1000;i<=2000;i++){
????????????if((i%4==0&&i/100!=0)||i%400==0){
????????????????System.out.print(i+" ?");
????????????????count++;
????????????}
????????????if(count%5==0){
????????????????System.out.println();
????????????}
????????}
????}
}
package com.textday002;
public class WorkBook{
????public static void main(String[] args) {
????????// 10:定义两个整数a、b,a、b的取值范围在0-9之间,给出所有符合a+b=12的组合。
????????int a,b;
????????for(a=0;a<10;a++){
????????????for(b=0;b<10;b++){
????????????????if(a+b==12){
????????????????????System.out.print(a+"+"+b+"=12 ??");
????????????????}
????????????}
????????}
????}
}
????例如:90+09=99
package com.textday002;
public class WorkBook{
????public static void main(String[] args) {
????????// 11:A、B、C、D分别为0——9之间的整数,求出满足AB+CD=DA条件的数。
????????// ???例如:90+09=99
????????int A,B,C,D;
????????for(A=0;A<10;A++){
????????????for(B=0;B<10;B++){
????????????????for(C=0;C<10;C++){
????????????????????for(D=9;D<10;D++)
????????????????????????if((A*10+B)+(C*10+D)==(D*10+A))
????????????????????????????System.out.println((A*10+B)+"+"+(C*10+D)+"="+(D*10+A));
????????????????}
????????????}
????????}
????}
}
package com.textday002;
public class WorkBook{
????public static void main(String[] args) {
????????// 12:随机生成一个五位以内的数,然后输出该数共有多少位,每位分别是什么
????????int number=(int)(Math.random()*10000);
????????System.out.print("该五位数是:"+number+"\n");
????????int count=0,j=0;
????????for(int i=0;i<5;i++){
????????????j = number%10;
????????????number /=10;
????????????count++;
????????????if(count==1){
????????????????System.out.println("个位是:"+j);
????????????} else if (count==2) {
????????????????System.out.println("十位是:"+j);
????????????}else if(count==3){
????????????????System.out.println("百位是:"+j);
????????????}else if(count==4){
????????????????System.out.println("千位是:"+j);
????????????}else if(count==5){
????????????????System.out.println("万位是:"+j);
????????????}
????????????if(number == 0){
????????????????break;
????????????}
????????}
????????System.out.println("共有"+count+"位");
????}
}
package com.textday002;
public class WorkBook{
????public static void main(String[] args) {
????????// 13:输出九九乘法表
????????for(int i=1;i<=9;i++){
????????????for(int j=1;j<=i;j++){
????????????????System.out.print(i+"*"+j+"="+i*j+" ???");
????????????}
????????????System.out.println();
????????}
????}
}
package com.textday002;
public class WorkBook{
????public static void main(String[] args) {
????????// 14 使用Java实现输出如下图形。
????????//外层循环控制行数
????????for (int i = 1; i <= 3; i++) {
????????????//输出每一行前面的空格“ ”
????????????for (int j = 3 - i; j > 0; j--) {
????????????????System.out.print(" ");
????????????}
????????????//输出每一行的“*”
????????????for (int k = 2 * i - 1; k > 0; k--) {
????????????????System.out.print("*");
????????????}
????????????//换行
????????????System.out.println();
????????}
????}
}
package com.textday002;
public class WorkBook{
????public static void main(String[] args) {
????????// 14 使用Java实现输出如下图形。
????????//行h
????????for(int h = 1; h <=5; h++){
????????????//空格k
????????????for(int k =1; k <= 6-h ; k++){
????????????????System.out.print(" ");
????????????}
????????????//*
????????????for(int m = 1; m <= 2*h+4; m++){
????????????????System.out.print("*");
????????????}
????????????System.out.println();
????????}
????????for(int h2 = 6; h2 >= 1; h2--){
????????????//空格k
????????????for(int k2 = 1; k2 <= 6-h2 ; k2++){
????????????????System.out.print(" ");
????????????}
????????????//*
????????????for(int m2 = 1; m2 <= 2*h2+4; m2++){
????????????????System.out.print("*");
????????????}
????????????System.out.println();
????????}
????}
}
package com.textday002;
public class WorkBook{
????public static void main(String[] args) {
????????//上半截图形:外层循环控制行数
????????System.out.println(" ???????*");
????????for (int i = 1; i <= 8; i++) {
????????????//输出每一行前面的空格“ ”
????????????for (int j = 8-i; j >0; j--) {
????????????????System.out.print(" ");
????????????}
????????????//输出“*”
????????????System.out.print("*");
????????????//输出空格“ ”
????????????for (int k = 2*i-1; k >0; k--) {
????????????????System.out.print(" ");
????????????}
????????????//输出“*”
????????????System.out.println("*");
????????}
????????//下半截图形:外层循环控制行数
????????for (int i = 1; i <= 7; i++) {
????????????//输出每一行前面的空格“ ”
????????????for (int j = i; j >0; j--) {
????????????????System.out.print(" ");
????????????}
????????????//输出“*”
????????????System.out.print("*");
????????????//输出空格“ ”
????????????for (int k = 15-2*i; k >0; k--) {
????????????????System.out.print(" ");
????????????}
????????????//输出“*”
????????????System.out.println("*");
????????}
????????System.out.println(" ???????*");
????}
}
package com.textday002;
public class WorkBook{
????public static void main(String[] args) {
????????//外层循环控制行数
????????System.out.println("***************");
????????for (int i = 1; i <= 7; i++) {
????????????//输出每一行前面的“*”
????????????for (int j = 8-i; j >0; j--) {
????????????????System.out.print("*");
????????????}
????????????//输出每一行的空格“ ”
????????????for (int k = 2*i-1; k >0; k--) {
????????????????System.out.print(" ");
????????????}
????????????//输出每一行后面的“*”
????????????for (int m = 8-i; m >0;m--) {
????????????????System.out.print("*");
????????????}
????????????//换行
????????????System.out.println();
????????}
????}
}
package com.textday002;
import java.util.Scanner;
public class WorkBook{
????public static void main(String[] args) {
// ?15:实现双色球的彩票功能。规则:
// ?从36个红球中随机选择不重复的6个数,
// ?从15个篮球中随机选择1个组成一注彩票。可以选择买多注。
????????//创建Scanner类对象,用来获取从键盘输入的数据
????????Scanner sc = new Scanner(System.in);
????????System.out.println("输入你要购买的彩票注数:");
????????int num = sc.nextInt();
????????for (int i = 1; i <= num; i++) {
????????????//随机获取一个[num1,num2)之间的int类型的数(num2>num1):(int)(Math.random()*(num2-num1)+num1);
????????????// 输出蓝球,蓝球只需要一个[1,17)
????????????int blueBall = (int) (Math.random() * 16 + 1);
????????????// 输出红球,红球需要6个[1,34)
????????????int redBall1 = (int) (Math.random() * 33 + 1);
????????????int redBall2 = 0;
????????????int redBall3 = 0;
????????????int redBall4 = 0;
????????????int redBall5 = 0;
????????????int redBall6 = 0;
????????????while (true) {
????????????????int redBall = (int) (Math.random() * 33) + 1;
????????????????if (redBall6 != 0) {// redBall6不等于0说明redBall6已经获得值了
????????????????????break;// redBall6获得值了就退出循环
????????????????}
????????????????if (redBall != redBall1 && redBall2 == 0) {
????????????????????redBall2 = redBall;
????????????????} else if (redBall != redBall1 && redBall != redBall2
????????????????????????&& redBall3 == 0) {
????????????????????redBall3 = redBall;
????????????????} else if (redBall != redBall1 && redBall != redBall2
????????????????????????&& redBall != redBall3 && redBall4 == 0) {
????????????????????redBall4 = redBall;
????????????????} else if (redBall != redBall1 && redBall != redBall2
????????????????????????&& redBall != redBall3 && redBall != redBall4
????????????????????????&& redBall5 == 0) {
????????????????????redBall5 = redBall;
????????????????} else if (redBall != redBall1 && redBall != redBall2
????????????????????????&& redBall != redBall3 && redBall != redBall4
????????????????????????&& redBall != redBall5 && redBall6 == 0) {
????????????????????redBall6 = redBall;
????????????????}
????????????}
????????????System.out.println(redBall1 + " " + redBall2 + " " + redBall3 + " "
????????????????????+ redBall4 + " " + redBall5 + " " + redBall6 + "---"
????????????????????+ blueBall);
????????}
????????sc.close();
????}
}
package com.textday002;
public class WorkBook{
????public static void main(String[] args) {
// ???????16:输出1-100之间的不能被5整除的数,每5个一行。
????????int count=0;
????????for(int i =1;i<=100;i++){
????????????if(i%5!=0){
????????????????count++;
????????????????System.out.print(i+"\t");
????????????}
????????????if(count%5==0)
????????????????System.out.println();
????????}
????}
}
package com.textday002;
public class WorkBook{
????public static void main(String[] args) {
// ???????17:输出斐波那契数列数列的前20项
????????int num[] = new int[20];
????????num[0]=0;
????????num[1]=1;
????????System.out.println("斐波那契数列前20项的值如下:");
????????System.out.print(num[0]+" "+num[1]+" ");
????????for(int i = 2; i < 20; i++){
????????????num[i] = num[i - 1] + num[i - 2];
????????????System.out.print(num[i]+" ");
????????}
????}
}
package com.textday002;
import java.util.Scanner;
public class WorkBook{
????public static void main(String[] args) {
// ???????18:输出一个整数的二进制数、八进制数、十六进制数。
????????Scanner scan=new Scanner(System.in);
????????System.out.print("输入一个整数:");
????????int n=scan.nextInt(); //输入15
????????System.out.println("n的十进制="+n);
????????System.out.println("n的二进制="+Integer.toBinaryString(n));
????????System.out.println("n的八进制="+Integer.toOctalString(n));
????????System.out.println("n的十六进制="+Integer.toHexString(n));
????}
}
package com.textday002;
public class WorkBook{
????public static void main(String[] args) {
// ???????19:随机产生一个字母,如果是大写字母则输出“yes”,否则输出“no”
????????int number = (int) (Math.random()*58+65);
????????if(number>=65&&number<=90){
????????????System.out.println("Yes");
????????????System.out.println((char)number);
????????}else{
????????????System.out.println("No");
????????????System.out.println((char)number);
????????}
????}
}
package com.textday002;
public class WorkBook{
????public static void main(String[] args) {
// ??20:随机产生一个字符,判断:如果为大写字母则输出“大写字母”;
// ??如果为小写字母则输出“小写字母”;否则怎输出“其他字符”
// ???????a-z:97~122
// ???????A~Z:65~90
????????int number = (int) (Math.random()*58+65);
????????if(number>=65&&number<=90){
????????????System.out.println("大写字母");
????????????System.out.println((char)number);
????????}else if(number>=97&&number<=122){
????????????System.out.println("小写字母");
????????????System.out.println((char)number);
????????}else{
????????????System.out.println("其他字符");
????????????System.out.println((char)number);
????????}
????}
}
package com.textday002;
public class WorkBook{
????public static void main(String[] args) {
// ??21:求100到1000之间的所有能被5和6整除的整数,每行显示5个
????????int count=0;
????????for(int i =100;i<=1000;i++){
????????????if(i%5==0 && i%6==0){
????????????????System.out.print(i+" ??");
????????????????count++;
????????????????if(count%5==0){
????????????????????System.out.print("\n");
????????????????}
????????????}
????????}
????}
}
package com.textday002;
public class WorkBook{
????public static void main(String[] args) {
// ??22:求和:1/3+3/5+5/7+7/9+………..+97/99
????????double sum=0;
????????for(double i = 1;i<=97;i+=2){
????????????sum+=(i/(i+2));
????????}
????????System.out.print("1/3+3/5+5/7+7/9+………..+97/99="+sum);
????}
}
package com.textday002;
public class WorkBook{
????public static void main(String[] args) {
// ??23:输出100以内的所有素数,每行显示5个;并求和。
// ???????素数只能被1和自己整除的数;1不是素数。
????????int count=0,sum=0,i,j;
????????for(i=2;i<=100;i++){
????????????for(j=2;j<=i;j++){
????????????????if(i%j==0)
????????????????????break;
????????????}
????????????if(i==j){
????????????????count++;
????????????????sum+=i;
????????????????System.out.print(i+"\t");
????????????????if(count%5==0)
????????????????????System.out.println();
????????????}
????????}
????}
}
提示:
(1) 用整型变量water表示水缸里的水“int water = 15;”。
(2) 用整型变量l表示小和尚下山挑水的次数“int l = 0;”。
(3) 分析循环条件(水少于50升),循环操作(水增加5升,挑水次数增加1)。
(4) 套用while循环(或do-while循环)写出代码。
package com.textday002;
public class WorkBook{
????public static void main(String[] args) {
// ??24:山上有一口缸可以装50升水,现在有15升水。老和尚叫小和尚下山挑水,每次可以挑5升。问:小和尚要挑几次水才可以把水缸挑满?通过编程解决这个问题。
//提示:
//(1) 用整型变量water表示水缸里的水“int water = 15;”。
//(2) 用整型变量l表示小和尚下山挑水的次数“int l = 0;”。
//(3) 分析循环条件(水少于50升),循环操作(水增加5升,挑水次数增加1)。
//(4) 套用while循环(或do-while循环)写出代码。
????????int water=15;
????????int l=0,sum=water;
????????while(sum<50){
????????????l++;
????????????sum+=5;
????????}
????????System.out.println("小和尚要挑"+l+"次水,水缸最后水:"+sum);
????}
}
提示:采用逆向思维分析问题。
??
?package com.textday002;
public class WorkBook{
????public static void main(String[] args) {
// ?25:李白无事街上走,提壶去买酒。
// ?遇店加一倍,见花喝一斗,五遇花和店,喝光壶中酒,试问李白壶中原有多少斗酒?(使用for循环结构编程实现)
//提示:采用逆向思维分析问题。
// ???????//最后喝光壶中酒可见最后一次是见花,喝了一斗酒
// ???????// ??1 ?????0.5
// ???????// ??1.5 ???0.75
// ???????// ??1.75 ??1.75/2
????????double surplus=0;
????????//逆推 ,最后是遇花喝一斗 之后变成0斗
????????for(int i=0;i<5;i++){
????????????surplus+=1; ??//先加1
????????????surplus/=2; ??//加一倍之前是喝完所剩的酒,遇店加一倍
????????}
????????System.out.println("李白壶中原有"+surplus+"斗酒");
????}
}
package com.textday002;
import java.util.Scanner;
public class WorkBook{
????public static void main(String[] args) {
// ?26:开发一个标题为“FlipFlop”的游戏应用程序。
// ?它从1计数到100,遇到3的倍数就替换为单词“Flip”,
// ?5的倍数就替换为单词“Flop”,既为3的倍数又为5的倍数则替换为单词“FlipFlop”。
????????System.out.println("这是一款‘FlipFlop’游戏应用程序");
????????for(int i=1;i<=100;i++){
????????????if(i%3==0&&i%5==0){
????????????????System.out.print("FlipFlop\n");
????????????}else if(i%3==0){
????????????????System.out.print("Flip\t");
????????????}else if(i%5==0){
????????????????System.out.print("Flop\n");
????????????}else{
????????????????System.out.print(i+"\t"+"\t");
????????????}
????????}
????}
}
Ean-13码规则:第十三位数字是前十二位数字经过计算得到的校验码。
例如:690123456789
计算其校验码的过程为:
@前十二位的奇数位和6+0+2+4+6+8=26
@前十二位的偶数位和9+1+3+5+7+9=34
@将奇数和与偶数和的三倍相加26+34*3=128
@取结果的个位数:128的个位数为8
@用10减去这个个位数10-8=2
所以校验码为2
(注:如果取结果的个位数为0,那么校验码不是为10(10-0=10),而是0)
实现方法ean13()计算验证码,输入12位条码,返回带验证码的条码。
例:输入:692223361219输出:6922233612192
package com.textday002;
import java.util.Scanner;
public class WorkBook{
????public static void main(String[] args) {
// ?27:生成13位条形码
????????Scanner scan = new Scanner(System.in);
????????int[] arr = new int[13];
????????System.out.print("请输入12个0~9之间的数字,例如(6 9 2 2 2 3 3 6 1 2 1 9):");
????????for(int i=0;i<(arr.length-1);i++){
????????????arr[i] = scan.nextInt();
????????}
????????//oddnum 为奇数和,evennum 为偶数和
????????int oddnum =0,evennum=0;
????????//计算奇数偶数和
????????for(int i=0;i<12;i++){
????????????if(i%2==0){
????????????????oddnum+=arr[i];
????????????}else if(i%2 ==1){
????????????????evennum+=arr[i];
????????????}
????????}
????????System.out.println("奇数和:"+oddnum);
????????System.out.println("偶数和"+evennum);
????????int threetimes ?= oddnum+evennum*3;
????????int ge = threetimes%10;
????????int checkcode;
????????if(ge==0){
????????????checkcode = 0;
????????}else{
????????????checkcode = 10-ge;
????????}
????????arr[12]=checkcode;
????????System.out.println("验证码的条码为:");
????????for(int i=0;i<arr.length;i++){
????????????System.out.print(arr[i]);
????????}
????}
}
package com.textday002;
import java.util.Scanner;
public class WorkBook{
????public static void main(String[] args) {
// ??28:求两个整数的最大公约数和最小公倍数
????????System.out.print("请输入两个整数:");
????????Scanner scan = new Scanner(System.in);
????????int x = scan.nextInt();
????????int y = scan.nextInt();
????????int temp=0,m=x,n=y;
????????if(x<y){
????????????temp = x;x=y;y=temp;
????????}
????????while(x%y!=0){
????????????temp = x%y;
????????????x=y;
????????????y=temp;
????????}
????????System.out.println("最大公约数:"+y);
????????System.out.println("最小公倍数"+m*n/y);
????}
}
package com.textday002;
import java.util.Scanner;
public class WorkBook{
????public static void main(String[] args) {
// ?29:将100元兑换为1元、5元、10元的零钱,请问有多少种兑换方法?
????????//这里题目没有要求每种都要有一张票,默认每种都可以有0张
????????//x 是1 元 ?y 代表 5 元 ?z 代表10元
????????int x=1,y=5,z=10,count=0;
????????for(int i=0;i<=100;i++){
????????????for(int j=0;j<=20;j++){
????????????????for(int k=0;k<=10;k++){
????????????????????if(i*x+j*y+k*z == 100){
????????????????????????count++;
????????????????????????System.out.println(i+"*"+x+"+"+j+"*"+y+"+"+k+"*"+z+"="+100);
????????????????????}
????????????????}
????????????}
????????}
????????System.out.println("共有"+count+"种方法");
????}
}
package com.textday002;
import java.util.Scanner;
public class WorkBook{
????public static void main(String[] args) {
// ?30:用100元人民币兑换10元,5元,1元的纸币(每种都要有)共50张,计算有多少种兑换方案
????????int x=1,y=5,z=10,count=0;
????????for(int i=1;i<=100;i++){
????????????for(int j=1;j<=20;j++){
????????????????for(int k=1;k<=10;k++){
????????????????????if(i*x+j*y+k*z == 100 && i+j+k==50 ){
????????????????????????count++;
????????????????????????System.out.println(i+"*"+x+"+"+j+"*"+y+"+"+k+"*"+z+"="+100);
????????????????????}
????????????????}
????????????}
????????}
????????System.out.println("共有"+count+"种方法");
????}
}
package com,textday002;
import java.util.Scanner;
public class WorkBook{
????public static void main(String[] args) {
// ?31:设计Java程序,假设有50瓶饮料,喝完3个空瓶可以换一瓶饮料,
// ?依次类推,请问总共喝了多少瓶饮料?
???????// -3 +1 ?-3 ?+1
????????// ?n 喝三瓶换一瓶
????????int sum=50,n=0;
????????while(true){
????????????sum-=3;
????????????n++;
????????????sum+=1;
????????????if(sum<3){
????????????????System.out.println("一共喝了"+(50+n)+"瓶");
????????????????break;
????????????}
????????}
????}
}