//下面是之前做的一些基本的java编程
/*
/*【程序7】 题目:输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。 * 正则表达式不会,下面使用ascii码进行编程*/ /* public class JavaTest{ public static void main(String[] args) { Scanner scanner=new Scanner(System.in); String string=scanner.nextLine();//使用nextLine输入一行以回车结束,next只能获取输入的第一段以空格结束 int a=0,b=0,c=0,d=0; char[] array; array=string.toCharArray(); for (int i = 0; i < array.length; i++) { int asciima=array[i];//根据ascii码判断 if ((asciima>=65&&asciima<=90)||(asciima>=97&&asciima<=122)) {//英文字母 a++; } else if (asciima==32) {//空格 b++; } else if (asciima>=48&&asciima<=57) {//数字 c++; } else { d++; } } System.out.println(a+" "+b+" "+c+" "+d); } } */ /*【程序18】 题目:两个乒乓球队进行比赛,各出三人。甲队为a,b,c三人,乙队为x,y,z三人。 * 已抽签决定比赛名单。有人向队员打听比赛的名单。a说他不和x比,c说他不和x,z比, * 请编程序找出三队赛手的名单。*/ /* public class JavaTest{ public static void main(String[] args) { int a=1,b=2,c=3; int x,y,z; boolean breakoff=false;//减少循环,匹配跳出循环 for ( z = 1; z < 4; z++) { for ( y = 1; y < 4; y++) { for (x = 1; x< 4; x++) { if (x!=1&&x!=3&&z!=3&&x!=y&&x!=z&&y!=z) { breakoff=true; //System.out.println(x+" "+y+" "+z); int[] array=new int[3]; array[0]=x; array[1]=y; array[2]=z; for (int i = 0; i < array.length; i++) { if (array[i]==1) { if(i==0) System.out.println("a和x同组"); if(i==1) System.out.println("a和y同组"); if(i==2) System.out.println("a和z同组"); } if (array[i]==2) { if(i==0) System.out.println("b和x同组"); if(i==1) System.out.println("b和y同组"); if(i==2) System.out.println("b和z同组"); } if (array[i]==3) { if(i==0) System.out.println("c和x同组"); if(i==1) System.out.println("c和y同组"); if(i==2) System.out.println("c和z同组"); } } break; } } if (breakoff) { break; } } if (breakoff) { break; } } } } */ /*【程序34】 题目:输入3个数a,b,c,按大小顺序输出。*/ /* public class JavaTest{ public static void main(String[] args) { //将abc放入一个数组中 System.out.println("please input the value of a:"); Scanner scanner1Scanner=new Scanner(System.in); int a=scanner1Scanner.nextInt(); System.out.println("please input the value of b:"); Scanner scanner2Scanner=new Scanner(System.in); int b=scanner2Scanner.nextInt(); System.out.println("please input the value of c:"); Scanner scanner3Scanner=new Scanner(System.in); int c=scanner1Scanner.nextInt(); int[] d=new int[3]; d[0]=a; d[1]=b; d[2]=c; int min=0,max=0; for (int i = 0; i < d.length; i++) { if (d[i]>d[max]) { max=i; } if (d[i]<d[min]) { min=i; } } //System.out.println(d[max]); //System.out.println(d[min]); int change=0; for (int i = 0; i < d.length; i++) { if ((d[i]!=d[min])&&(d[i]!=d[max])) { change=d[i]; } } System.out.println(d[min]); System.out.println(change); System.out.println(d[max]); } } */ /*【程序35】 题目:输入数组,最大的与第一个元素交换,最小的与最后一个元素交换,输出数组。*/ /* public class JavaTest{ public static void main(String[] args) { System.out.println("please input the count of array:"); Scanner scanner=new Scanner(System.in); int a=scanner.nextInt(); System.out.println("please input an array:"); Scanner scanner1=new Scanner(System.in); int[] b=new int[a]; for (int i = 0; i < b.length; i++) { if (scanner1.hasNext()) { b[i]=scanner1.nextInt(); } } //int[] c=b;//这样赋值,似乎跟C的语法差不多,c指向的是b的地址,b中数值改变c也改变 int[] c=new int[a]; for (int i = 0; i < b.length; i++) { c[i]=b[i]; } Arrays.sort(b);//应用该方法将数组b重新排序了 int max=0,min=0; max=b[a-1]; min=b[0]; for (int i = 0; i < c.length; i++) { System.out.print(c[i]+" "); } System.out.println(); for (int i = 0; i < c.length; i++) { if (c[i]==max) { c[i]=c[0]; c[0]=max; } if (c[i]==min) { c[i]=c[a-1]; c[a-1]=min; } } for (int i = 0; i < c.length; i++) { System.out.print(c[i]+" "); } } } */ /*【程序36】 题目:有n个整数,使其前面各数顺序向后移m个位置,最后m个数变成最前面的m个数 ,这里利用特例来模拟 * n=10、m=4*/ /* public class JavaTest{ public static void main(String[] args) { int[] a={1,2,3,4,5,6,7,8,9,10}; int b=0; for (int i = 0; i < 4; i++) { b=a[9]; for (int j = 9; j > 0; j--) { a[j]=a[j-1]; } a[0]=b; } for (int i = 0; i < a.length; i++) { System.out.println(a[i]); } } } */ /*【程序37】题目:有n个人围成一圈,顺序排号。从第一个人开始报数(从1到3报数),凡报到3的人退出圈子,问最后留下的是原来第几号的那个人。 /* public class JavaTest{ public static void main(String[] args) { System.out.println("请输入一共有多少人"); Scanner scanner=new Scanner(System.in); int n=scanner.nextInt(); boolean[] a=new boolean[n]; System.out.println(n); for (int i = 0; i < a.length; i++) { a[i]=true; } int m=0,o=0; for (int i = 0;i<a.length ; i++) { if (a[i]==true) { m++; if (m==3) { a[i]=false; o++; m=0; } } //System.out.println(a[i]+"和 "+i); if(o==(a.length-1)){ for (int j = 0; j < a.length; j++) { if(a[j]==true){ //System.out.println(a[j]+"和 "+j); System.out.println(++j); break; } } break; } if(i==a.length-1) i=0-1; } } } */ /*【程序41】题目:编写一个函数,输入n为偶数时,调用函数求1/2+1/4+...+1/n,当输入n为奇数时,调用函数1/1+1/3+...+1/n */ /* public class JavaTest{ public double oushu(int a) { double s=0f; for (int i = 1; i <= a/2; i++) { s+=(double)1/(2*i); } return s; } public double jishu(int a) { double s=0f; for (int i = 0; i < (a+1)/2; i++) { s+=(double)1/(2*i+1); } return s; } public static void main(String[] args) { System.out.println("请输入偶数或者奇数"); Scanner scanner=new Scanner(System.in); int a=scanner.nextInt(); JavaTest javaTest=new JavaTest(); if (a<=0) { System.out.println("输入有误"); }else { if (a%2==0) { System.out.println(javaTest.oushu(a)); }else { System.out.println(javaTest.jishu(a)); } } } } */ /*【程序38】题目:写一个函数,求一个字符串的长度,在main函数中输入字符串,并输出其长度。 */ /* public class JavaTest{ public static void main(String[] args) { System.out.println("请输入字符串:"); Scanner scanner=new Scanner(System.in); String string=scanner.next(); int a=string.length(); System.out.println(a); } } */ /*【程序39】 题目:字符串排序 */ /* public class JavaTest{ public static void main(String[] args) { System.out.println("请输入即将输入的字符串数,否则无法排序"); Scanner scanner1Scanner=new Scanner(System.in); int a=scanner1Scanner.nextInt(); System.out.println("请输入字符串:"); Scanner scanner=new Scanner(System.in); String[] string=new String[a]; for (int j = 0; j < string.length; j++) { string[j]=scanner.next(); } Arrays.sort(string); for (int i = 0; i < string.length; i++) { System.out.println(string[i]); } } } */ /*【程序40】 题目:海滩上有一堆桃子,五只猴子来分。第一只猴子把这堆桃子凭据分为五份, * 多了一个,这只猴子把多的一个扔入海中,拿走了一份。第二只猴子把剩下的桃子又平均分成五份, * 又多了一个,它同样把多的一个扔入海中,拿走了一份,第三、第四、第五只猴子都是这样做的, * 问海滩上原来最少有多少个桃子? */ /* public class JavaTest{ public static void main(String[] args) { for (int i = 1; i < 1000; i++) {//数比较大,i值相对 double s=i*5+1; for (int j = 1; j < 5; j++) { s=s*5/4+1; } int s1=(int)s; //System.out.println(s); //System.out.println(s1); if ((s-s1)==0) { System.out.println(i); System.out.println(s1); break; } } } } */ /*【程序33】 题目:打印出杨辉三角形(要求打印出10行如下图) 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1 1 5 10 10 5 1 */ /* public class JavaTest{ public static void main(String[] args) { int[][] a =new int[10][10];//二维数组声明分配内存 for (int i = 0; i < 10; i++) { a[i][0]=1; } for (int i = 1; i < 10; i++) { for (int j = 1; j <= i; j++) { if (i==j) { a[i][j]=1; }else { a[i][j]=a[i-1][j-1]+a[i-1][j]; } } } for (int i = 0; i < 10; i++) { for (int j = 0; j <= i; j++) { System.out.print(a[i][j]+" "); } System.out.println(); } } } */ /*【程序32】 题目:取一个整数a从右端开始的4~7位。 */ /* public class JavaTest{ public static void main(String[] args) { System.out.println("输入一个最少7位数的整数:"); Scanner scanner=new Scanner(System.in); int a=scanner.nextInt(); String string; char[] b; if (a<1000000) { System.out.println("输入有误"); }else { string=String.valueOf(a); b=string.toCharArray(); System.out.println("整数a从右端开始的4~7位分别是:"); for (int i = b.length-1-3; i >= b.length-4-3; i--) { System.out.println(b[i]); } } } } */ /*【程序31】 题目:将一个数组逆序输出。*/ /* public class JavaTest{ public static void main(String[] args) { int[] a={61,345,427,498,583,630,692,719,827,987}; for (int i = 0; i < a.length; i++) { System.out.println(a[a.length-i-1]); } } } */ /*【程序30】 题目:有一个已经排好序的数组。现输入一个数,要求按原来的规律将它插入数组中。*/ /* public class JavaTest{ public static void main(String[] args) { int[] a={93,82,76,54,46,32,21,16,0};//将数组扩展一位,方便插入数字 int b,c,d,e; System.out.println("请输入一个数字"); Scanner scanner=new Scanner(System.in); b=scanner.nextInt(); c=a.length-2; if (a[0]>a[c]) { System.out.println("降序排列"); for (int i = 0; i < c; i++) { if (a[0]<b) { d=a[0]; a[0]=b; for (int j = 1; j < a.length; j++) { e=a[j]; a[j]=d; d=e; } break; } if(a[c]>b){ a[c+1]=b; break; } if(a[i]>=b&&a[i+1]<=b){ d=a[i+1]; a[i+1]=b; for (int j = i+2; j < a.length; j++) { e=a[j]; a[j]=d; d=e; } break; } } } else { System.out.println("升序排列"); for (int i = 0; i < c; i++) { if (a[0]>b) { d=a[0]; a[0]=b; for (int j = 1; j < a.length; j++) { e=a[j]; a[j]=d; d=e; } break; } if(a[c]<b){ a[c+1]=b; break; } if(a[i]<=b&&a[i+1]>=b){ d=a[i+1]; a[i+1]=b; for (int j = i+2; j < a.length; j++) { e=a[j]; a[j]=d; d=e; } break; } } } for (int i = 0; i < a.length; i++) { System.out.print(a[i]+" "); } } } */ /*【程序29】 题目:求一个3*3矩阵对角线元素之和 */ /* public class JavaTest{ public static void main(String[] args) { System.out.println("请输入3*3矩阵第一行"); Scanner scanner1=new Scanner(System.in); int[] a1=new int[3]; for (int i = 0; i < a1.length; i++) { a1[i]=scanner1.nextInt(); } System.out.println("请输入3*3矩阵第二行"); Scanner scanner2=new Scanner(System.in); int[] a2=new int[3]; for (int i = 0; i < a1.length; i++) { a2[i]=scanner1.nextInt(); } System.out.println("请输入3*3矩阵第三行"); Scanner scanner3=new Scanner(System.in); int[] a3=new int[3]; for (int i = 0; i < a1.length; i++) { a3[i]=scanner1.nextInt(); } int s=0; s=a1[0]+a2[1]+a3[2]; System.out.println(s); } } */ /*【程序28】 题目:对10个数进行排序,从大到小*/ /* public class JavaTest{ public static void main(String[] args) { System.out.println("请输入10个数字"); Scanner scanner=new Scanner(System.in); int[] a=new int[10]; for (int i = 0; i < a.length; i++) { a[i]=scanner.nextInt(); } //Arrays.sort(a);//接口排序从小到大 int b;//冒泡排序 for (int i = 0; i < a.length; i++) { for (int j = 1; j < a.length-i; j++) { if (a[i]<a[i+j]) { b=a[i]; a[i]=a[i+j]; a[i+j]=b; } } } for (int i = 0; i < a.length; i++) { System.out.print(a[i]+" "); } } } */ /*【程序27】 题目:求100之内的素数*/ /* public class JavaTest{ public static void main(String[] args) { boolean is=true; for (int i = 1; i < 101; i++) { is=true;//每次判别的时候,都将其置为true,否则如果不重新赋值,其值变为false后将一直为false for (int j = 2; j < i; j++) { if (i%j==0) { is=false; break; } } if (is) { System.out.println(i+"是素数"); } } } } */ /*【程序26】 题目:请输入星期几的第一个字母来判断一下是星期几,如果第一个字母一样,则继续 判断第二个字母。*/ /* public class JavaTest{ public static void main(String[] args) { System.out.println("请输入星期几的第一个字母"); Scanner scanner=new Scanner(System.in); char[] a=scanner.next().toCharArray(); if(a.length>1) System.out.println("输入有误"); else { if (a[0]=='m') { System.out.println("星期一"); }else if (a[0]=='w') { System.out.println("星期三"); }else if (a[0]=='f') { System.out.println("星期五"); }else if (a[0]=='t') { System.out.println("请输入星期几的第二个字母"); Scanner scanner1=new Scanner(System.in); char[] b=scanner1.next().toCharArray(); if(b.length>1) System.out.println("输入有误"); else{ if (b[0]=='u') { System.out.println("星期二"); }else if (b[0]=='h') { System.out.println("星期四"); }else { System.out.println("输入有误"); } } }else if (a[0]=='s') { System.out.println("请输入星期几的第二个字母"); Scanner scanner2=new Scanner(System.in); char[] b=scanner2.next().toCharArray(); if(b.length>1) System.out.println("输入有误"); else { if (b[0]=='a') { System.out.println("星期六"); }else if (b[0]=='u') { System.out.println("星期日"); }else { System.out.println("输入有误"); } } }else { System.out.println("输入有误"); } } } } */ /*【程序25】 题目:一个5位数,判断它是不是回文数。即12321是回文数,个位与万位相同,十位与千位相同。*/ /* public class JavaTest{ public static void main(String[] args) { System.out.println("请给出一个五位数:"); Scanner scanner=new Scanner(System.in); int a=scanner.nextInt(); if (a<=10000||a>99999) { System.out.println("输入有误"); }else { String string=String.valueOf(a); char[] b=new char[5]; b=string.toCharArray(); if (b[0]==b[4]) { if (b[1]==b[3]) { System.err.println(a+"是回文"); } else { System.err.println(a+"不是回文"); } } else { System.err.println(a+"不是回文"); } } } } */ /*【程序24】 题目:给一个不多于5位的正整数,要求:一、求它是几位数,二、逆序打印出各位数字。*/ /* public class JavaTest{ public static void main(String[] args) { System.out.println("请输入不多于5位的正整数:"); Scanner scanner=new Scanner(System.in); int a=scanner.nextInt(); if (a<0||a>100000) { System.out.println("输入有误"); } String string=String.valueOf(a); char[] aa;//对于未知位数的数组,不要声明其位数,否则会造成数组越位等问题 aa=string.toCharArray(); System.out.println(aa.length); for (int j = 0; j < aa.length; j++) { System.out.println(aa[4-j]); } } } */ /*【程序23】 题目:有5个人坐在一起,问第五个人多少岁?他说比第4个人大2岁。问第4个人岁数,他说比第3个人大2岁。 * 问第三个人,又说比第2人大两岁。问第2个人,说比第一个人大两岁。最后问第一个人,他说是10岁。请问第五个人多大?*/ /* public class JavaTest{ public static void main(String[] args) { JavaTest javaTest=new JavaTest(); System.out.println(javaTest.age(5)); } public int age(int i) { int a=0; if (i==1) { a=10; }else { a+=age(i-1)+2; } return a; } } */ /*【程序22】 题目:利用递归方法求5!。 */ /* public class JavaTest{ public static void main(String[] args) { System.out.println(digui(5)); } public static int digui(int i) { int a=0; if (i==1) { return 1; } a=i*digui(i-1); return a; } } */ /*【程序21】 题目:求1+2!+3!+...+20!的和*/ /* public class JavaTest{ public static void main(String[] args) { int s=0,s1=1; for (int i = 1; i < 21; i++) { s1*=i; s+=s1; } System.out.println(s); } } */ /*【程序20】题目:有一分数序列:2/1,3/2,5/3,8/5,13/8,21/13...求出这个数列的前20项之和。*/ /* public class JavaTest{ public static void main(String[] args) { float[] fenmu = new float[20]; float[] fenzi = new float[20]; float[] fenshu =new float[20]; float s=0f; for (int i = 0; i < 20; i++) {//所有数组的下标都是从0开始的,否则造成数组越界 fenmu[i]=leijia1(i); System.out.println(fenmu[i]); fenzi[i]=leijia1(i+1); System.out.println(fenzi[i]); fenshu[i]=fenzi[i]/fenmu[i];//统一数据的类型,如果将fenmu和fenzi声明为int型,得到的fenshu会变为整除的数据 System.out.println(fenshu[i]); s+=fenshu[i]; } System.out.println(s); } public static int leijia1(int i) { if (i==0) { return 1; } if (i==1) { return 2; } return leijia1(i-1)+leijia1(i-2); } } */ /*【程序19】题目:打印出如下图案(菱形) * *** ****** ******** ****** *** * */ /* public class JavaTest{ public static void main(String[] args) { for (int i = 1; i < 8; i++) { int a=0; if(i==1||i==2) a=2*i-1; if(i==3||i==4) a=2*i; if(i==5) a=i+1; if (i==6) a=i-3; if (i==7) a=i-6; for (int j = 0; j < a; j++) { System.out.print("*"); } System.out.println(); } } } */ /*【程序17】题目:猴子吃桃问题:猴子第一天摘下若干个桃子,当即吃了一半,还不瘾,又多吃了一个 第二天早上又将剩下的桃子吃掉一半, 又多吃了一个。以后每天早上都吃了前一天剩下的一半零一个。到第10天早上想再吃时,见只剩下一个桃子了。求第一天共摘了多少。*/ /* public class JavaTest{ public static void main(String[] args) { int s=1; for (int i = 1; i < 10; i++) { s=(s+1)*2; } System.out.println(s); } } */ /*【程序16】题目:输出9*9口诀。*/ /* public class JavaTest{ 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+"="+i*j+"; "); } System.out.println(); } } } */ /*【程序13】 题目:一个整数,它加上100后是一个完全平方数,加上168又是一个完全平方数,请问该数是多少?*/ /* public class JavaTest{ public static void main(String[] args) { for (int i = 1; i < 100001; i++) {//Math.floor()取整,可以将一些开放为小数的数都去除掉 if(Math.floor(Math.sqrt(i+100))==Math.sqrt(i+100) &&Math.floor(Math.sqrt(i+168))==Math.sqrt(i+168)) System.out.println(i); } } } */ /*【程序12】题目:企业发放的奖金根据利润提成。利润(I)低于或等于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%提成,从 键盘输入当月利润I,求应发放奖金总数?*/ /* public class JavaTest{ public static void main(String[] args) { System.out.println("请输入当月的利润:(输入为正整数,1代表一万元)"); Scanner scanner=new Scanner(System.in); int count=scanner.nextInt(); double s=0; if (count<0) { System.out.println("输入有误"); }else { if (count<=10) { s=count*0.1; } else { if (count<=20) { s=(count-10)*0.075+1; } else { if (count<=40) { s=(count-20)*0.05+1.75; } else { if (count<=60) { s=(count-40)*0.03+2.75; } else { if (count<=100) { s=(count-60)*0.015+3.35; } else { s=(count-100)*0.01+3.95; } } } } } System.out.println("发放奖金数是"+s+"万元"); } } } */ /*【程序11】题目:有1、2、3、4个数字,能组成多少个互不相同且无重复数字的三位数?都是多少?*/ /* public class JavaTest{ public static void main(String[] args) { int count=0; int a,b,c; for (int i = 100; i < 1000; i++) { a=i%10; b=i/10%10; c=i/100; if ((a==1||a==2||a==3||a==4)&& (b==1||b==2||b==3||b==4)&& (c==1||c==2||c==3||c==4)&&(a!=b&&a!=c&&c!=b)) { System.out.println(i); count++; } } System.out.println(count); } }*/ /*【程序10】题目:一球从100米高度自由落下,每次落地后反跳回原高度的一半;再落下,求它在第10次落地时,共经过多少米?第10次反弹 多高?*/ /*public class JavaTest{ public static void main(String[] args) { int m=100; double s=0; s=100; double count=100; for (int i = 1; i < 11; i++) { s=s/2; if (i==10) { count=s+count; } else{ count=2*s+count;} } System.out.println("第10次落地时,共经过"+count+"米"); System.out.println("第10次反弹"+s+"米"); } } */ /*【程序9】题目:一个数如果恰好等于它的因子之和,这个数就称为 "完数 "。例如6=1+2+3.编程找出1000以内的所有完数。*/ /* public class JavaTest{ public static void main(String[] args) { int a=0; for (int i = 2; i < 1001; i++) { a=0;//需要在每次进行累加时将其初始化为0 for (int j = 1; j <=i; j++) { if((i%j==0)&&(i!=j)){ a+=j; } } if(i==a) System.out.println(i); } } } */ /*【程序8】题目:求s=a+aa+aaa+aaaa+aa...a的值,其中a是一个数字。例如2+22+222+2222+22222(此时共有5个数相加),几个数相 加有键盘控制。*/ /* public class JavaTest{ public static void main(String[] args) { System.out.println("请输入a值"); Scanner scanner=new Scanner(System.in); int a=scanner.nextInt(); if (a<=0) { System.out.println("输入的值有误"); } Scanner scanner2=new Scanner(System.in); int count=scanner2.nextInt(); if(count<=0) System.out.println("输入的个数有误"); else { int s=0,s1=0; for (int i = 1; i <= count; i++) { s=10*s+1; s1+=s; } s1=s1*a; System.out.println("结果"+s1); } } } */ /*【程序6】题目:输入两个正整数m和n,求其最大公约数和最小公倍数。*/ /* public class JavaTest{ public static void main(String[] args) { System.out.println("请输入两个正整数"); Scanner scanner=new Scanner(System.in); int m=scanner.nextInt(); int n=scanner.nextInt(); int a; if (m<0||n<0) { System.out.println("请输入正整数"); } else { if(m>n){ a=m; m=n; n=a; } for (int i = n; i > 0; i--) { if(m%i==0&&n%i==0){ System.out.println("最大公约数"+i); break; } } for (int i = 1; i <=n; i++) { if(n*i%m==0){ System.out.println("最小公倍数"+n*i); break; } } } } } */ /*【程序5】题目:利用条件运算符的嵌套来完成此题:学习成绩> =90分的同学用A表示,60-89分之间的用B表示,60分以下的用C表示。*/ /* public class JavaTest{ public static void main(String[] args) { System.out.println("请输入学习成绩:"); Scanner scanner=new Scanner(System.in); int a=scanner.nextInt(); if(a<0||a>100) System.out.println("输入有误"); else { if (a>=90) { System.out.println("成绩为A"); } else { if (a>=60&&a<89) { System.out.println("成绩为B"); } else { System.out.println("成绩为C"); } } } } } */ /*【程序4】题目:将一个正整数分解质因数。例如:输入90,打印出90=2*3*3*5。*/ /*public class JavaTest{ public static void main(String[] args) { Scanner scanner=new Scanner(System.in); int m=scanner.nextInt(); int n=m; boolean isZx=false; System.out.print(m+"="); for (int i = 0; i < n; i++) { for (int j = 2; j <=m ; ++j) { if(m%j==0){ System.out.print(j); if(m!=j) System.out.print("*"); m=m/j; break; } } } } } */ /* * *【程序3】题目:打印出所有的 "水仙花数 ",所谓 "水仙花数 "是指一个三位数,其各位数字立方和等于该数本身。例如:153是一个 "水仙花 数 ",因为153=1的三次方+5的三次方+3的三次方。 */ /* public class JavaTest{ public static void main(String[] args) { int m,n,o; for (int i = 100; i < 1000; i++) { n=i%10; m=i/10%10; o=i/100; if (i==(n*n*n+m*m*m+o*o*o)) { System.out.println(i); } } } }*/ /*【程序2】题目:判断101-200之间有多少个素数,并输出所有素数。程序分析:判断素数的方法: * 用一个数分别去除2到sqrt(这个数),如果能被整除,则表明此数不是素数,反之是素数。 */ /* public class JavaTest{ public static void main(String[] args) { int i=0; boolean m=false; for (int j = 101; j < 201; j++) { for (int j2 = 2; j2 < j-1; j2++) { if (j%j2==0) { break; } if(j2==j-2) m=true; if(m==true){ i++; System.out.println(j); m=false; } } } System.out.println(i); } } */ /*【程序1】题目:古典问题:有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔子长到第四个月后每个月又生一对兔子,假如兔子都不 死,问每个月的兔子总数为多少?斐波那契数列*/ /*public class JavaTest{ public static void main(String[] args) { int n; Scanner scanner=new Scanner(System.in); n=scanner.nextInt(); System.out.println("第"+n+"天一共有"+2*fix(n)+"个兔子"); } public static int fix(int n) { int count; if(n==1||n==2) return 1; else { count=fix(n-1)+fix(n-2); } return count; } } */ /*【程序15】题目:输入三个整数x,y,z,请把这三个数由小到大输出。*/ /*public class JavaTest { public static void main(String[] args) { Scanner scanner=new Scanner(System.in); int a=scanner.nextInt(); int b=scanner.nextInt(); int c=scanner.nextInt(); int d; if (a>b) { d=a; a=b; b=d; } if (b>c) { d=b; b=c; c=d; } if(a>b){ d=a; a=b; b=d; } System.out.println(a+"、"+b+"、"+c); } } */ /*【程序14】输入某年某月某日,判断这一天是这一年的第几天?*/ /*public class JavaTest { public static void main(String[] args) { Scanner scanner=new Scanner(System.in); int year=scanner.nextInt();//获取输入的年份 int mouth=scanner.nextInt();//获取输入的月份 int day=scanner.nextInt();//获取输入的日 int daycount=0;//总天数 boolean input=true;//是否输出daycount的标志 boolean runyear=false;//闰年标志 if (year<0||mouth<=0||mouth>=13){ System.out.println("input is error"); input=false; } if((year%4==0&&year%100!=0)||year%400==0) runyear=true; switch (mouth) { case 1: if(day<=0||day>=32) { System.out.println("input is error"); input=false; } daycount=day; break; case 2: if(runyear==false){ if(day<=0||day>=29) { System.out.println("input is error"); input=false; } daycount=day+31; }else { if(day<=0||day>=30) { System.out.println("input is error"); input=false; } daycount=day+31; } break; case 3: if(day<=0||day>=32) { System.out.println("input is error"); input=false; } daycount=day+31+28; break; case 4: if(day<=0||day>=31) { System.out.println("input is error"); input=false; } daycount=day+31*2+28; break; case 5: if(day<=0||day>=32) { System.out.println("input is error"); input=false; } daycount=day+31*2+28+30; break; case 6: if(day<=0||day>=31) { System.out.println("input is error"); input=false; } daycount=day+31*3+28+30; break; case 7: if(day<=0||day>=32) { System.out.println("input is error"); input=false; } daycount=day+31*3+28+30*2; break; case 8: if(day<=0||day>=32) { System.out.println("input is error"); input=false; } daycount=day+31*4+28+30*2; break; case 9: if(day<=0||day>=31) { System.out.println("input is error"); input=false; } daycount=day+31*5+28+30*2; break; case 10: if(day<=0||day>=32) { System.out.println("input is error"); input=false; } daycount=day+31*5+28+30*3; break; case 11: if(day<=0||day>=31) { System.out.println("input is error"); input=false; } daycount=day+31*6+28+30*3; break; case 12: if(day<=0||day>=32) { System.out.println("input is error"); input=false; } daycount=day+31*6+28+30*4; break; default: break; } if(runyear==true&&mouth>=3) daycount+=1; if (input==true) { System.out.println(daycount); } } } */