素数1
class su { public static void main(String [] args) { for(int a=1;a<=200;a++){ boolean flag=true; for(int b=2;b<Math.sqrt(a);b++){ if(a%b==0){ flag=false; break; } } if(flag&&a!=1){ System.out.println(a+""); } } } }
素数2
public class nb { public static void main(String[] args) { System.out.println(2); for(int c=3;c<=200;c++) { int d=0; for(int b=2;b<c;b++) { if(c%b==0) { d++; } } if(d==0) { System.out.println(c); } } }
输出包含数字1234的所有三位数并输出总个数
public class 作业2 { public static void main(String[] args) { int a,b,c,d,e,f,h; int i=0; for(a=1;a<=4;a++) { d=a*100; for(b=1;b<=4;b++) { e=b*10; for(c=1;c<=4;c++) { f=c; i++; h=d+e+f; System.out.println(h+","); } } } System.out.print("共计"+i+"个数");} }
倒序
public class paixu {public static void main(String[] args) { int [] a= {11,4,51,45,15,8,21,81}; System.out.println("排序前:"); for(int b=0;b<a.length;b++) { System.out.println(" "+a[b]);} System.out.println("排序后:"); for(int c=7;c>= 0;c--) { System.out.println(" "+a[c]); } } }
百元买百鸡
public class maiji {public static void main(String[] args) { //int a,b,c; for(int a=0;a<20;a++) for(int b=0;b<=33;b++) for(int c=0;c<300;c++) if((a*5+b*3+c*(1/3)==100)&&a*b*c!=0&&a+b+c==100) { System.out.println("共计公鸡"+a+"只"); System.out.println("共计母鸡"+b+"只"); System.out.println("共计小鸡"+c+"只"+"------"); } } }
斐波那契1
public class fq {public static void main(String[] args) { int a=0,c=1; for(int b=0;b<=20;b=b+2) { System.out.print(" "+a+" "+c); a=a+c; c=c+a; } } }
打折
public class dazhe {public static void main(String[] args) { System.out.println("请输入商品总额"); Scanner r=new Scanner(System.in); int a=r.nextInt(); double b; if(a<=200) b=a*1; if(a>200&&a<=500); b=a*0.9; if(a>500&&a<=800); b=a*0.85; if(a>800) ; b=a*0.8; System.out.println("最后价格为"+b+" "); } }
分数
import java.util.*; public class cj {public static void main(String[] args) { System.out.println("请输入你的分数"); Scanner r=new Scanner(System.in); int a=r.nextInt(); a=a/10; switch(a) { case 6 : System.out.println("你才及格,你个菜鸡"); break; case 7 : System.out.println("刚及格,你海星"); break; case 8: System.out.println("哎哟 不错偶"); break; case 9 : System.out.println("大神666"); break; default: System.out.println("还没及格 滚回家放牛吧"); } } }
斐波那契2
public class bb {public static void main(String[] args) { int a=0,b=1,c=1; while(c<=20) { System.out.print(" "+a+" "+b); a=a+b; b=a+b; c=c+2; } } }
冒泡排序
public class paixu2 {public static void main(String[] args) { int [] a= {11,4,51,45,15,8,21,81}; System.out.println("排序前:"); for(int b=0;b<a.length;b++) { System.out.println(" "+a[b]);} System.out.println("排序后:"); for(int e=1;e<a.length;e++) for(int c=0;c<a.length-e;c++) { if(a[c]<a[c+1]) { int d=a[c]; a[c]=a[c+1]; a[c+1]=d;} } for(int f=0;f<a.length;f++) { System.out.println(" "+a[f]);} } }