1.奇偶数
package DY1; public class Jioushu { public static void main(String[] args) { int a=5; if(a%2==0) { System.out.println("偶数"); } else { System.out.println("奇数"); } } }
2.圆面积
package DY1; import java.util.*; public class Syuan { public static void main(String[] args) { Scanner in =new Scanner(System.in); int r=in.nextInt(); double s; final double Pai=3.14; s=Pai*r*r; System.out.println(s); } }
3.加密
package DY1; import java.util.*; public class Jiami { public static void main(String[] args) { Scanner in=new Scanner(System.in); int a=in.nextInt(); double b; b=(a*10+5)/2+3.14159; int i=(int)b; System.out.println(i); } }
4.公鸡
package DY1; public class Gongji { public static void main(String[] args) { int gong,mu,xiao,count=0; for(gong=0;gong<20;gong++) { for(mu=0;mu<33;mu++) { for(xiao=0;xiao<100;xiao++) { if(xiao%3==0) { if((gong+mu+xiao==100)&&gong*5+mu*3+xiao/3==100) count ++; System.out.println("公鸡:"+gong+"只,母鸡"+mu+"只,小鸡"+xiao+"只"); } } } } System.out.println("一共"+count+"种买法"); } }
5.数字组合
package DY1; public class shuzi { public static void main(String[] args) { int i,j,k,s=0; for(i=1;i<=4;i++) { for(j=1;j<=4;j++) { for(k=1;k<=4;k++) { if(i!=j&&j!=k&&k!=i) { s=s+1; System.out.println(i*100+j*10+k); } } } } } }
6.素数
package DY1; import java.util.*; public class Sushu { public static void main(String[] args) { Scanner in=new Scanner(System.in); int a=in.nextInt(); if(a<2) { System.out.println("不是素数"); } for(int i=1;i<a;i++) { if(a%i==0) { if(a==i) System.out.println("是素数"); } else if(i!=1) { System.out.println("不是素数"); break; } } } }