第一次实训作业

判断奇偶数:
1 package javaApplication; 2 import java.util.*; 3 public class Odevity 4 { 5 public static void main(String[] args) 6 { 7 Scanner scanner=new Scanner(System.in); 8 int x; 9 System.out.println("请输入一个数:"); 10 x=scanner.nextInt(); 11 if(x%2==0) 12 { 13 System.out.println("这个数是偶数"); 14 } 15 else 16 { 17 System.out.println("这个数是奇数"); 18 } 19 scanner.close(); 20 } 21 }

求圆的面积:

1 package javaApplication;
 2 import java.util.*;
 3 public class Circle1 
 4 {
 5     final static double PI=3.14159;
 6     public static void main(String[] args)
 7     {
 8         Scanner scanner=new Scanner(System.in);
 9         int r;
10         double s=0;
11         System.out.println("请输入半径:");
12         r=scanner.nextInt();
13         
14         s=PI*r*r;
15         System.out.printf("面积为:%.2f",s);
16         scanner.close();    
17     }
18 }

加密处理:

 1 package javaApplication;
 2 import java.util.Scanner;
 3 public class Encipher
 4 {
 5     public static void main(String[] args)
 6     {
 7         Scanner scanner=new  Scanner(System.in);
 8         System.out.println("请输入要加密的数:");
 9         int x=scanner.nextInt();
10         int y=(int)((x*10+5)/2+3.14159);
11         System.out.println("加密后为:"+y);
12         scanner.close();
13     }
14 }

公鸡,母鸡,小鸡问题:

 1 package javaApplication;
 2 
 3 public class Chicken
 4 {
 5     public static void main(String[] args) 
 6     {
 7         System.out.println("可能的方案为:");
 8         for(int i=0;i<20;i++) //i表示公鸡
 9         {
10             for(int j=0;j<33;j++) //j表示母鸡
11             {
12                 for(int l=0;l<100;l+=3) //l表示小鸡
13                 {
14                     if((i*5+j*3+l/3.0==100)&&(j+i+l==100))
15                     {
16                         System.out.printf("公鸡%d只   母鸡%d只   小鸡%d只",i,j,l);
17                         System.out.println();
18                     }
19                 }
20             }
21         }    
22     }
23 }

不同且不重复的三位数:

1 package javaApplication;
 2 
 3 public class ThreeDigitNumber 
 4 {
 5     public static void main(String[] args)
 6     {
 7         
 8         int n=0;
 9         for(int i=1;i<=4;i++) //i表示百位
10         {
11             for(int j=1;j<=4;j++) //j表示十位
12             {
13                 if(i==j)
14                 {
15                     continue;
16                 }
17                 for(int l=1;l<=4;l++) //l表示各个位
18                 {
19                     if(l==j||l==i) 
20                     {
21                         continue;
22                     }
23                     n++;
24                     System.out.print((i*100+j*10+l)+" ");
25                     if(n%6==0)
26                     {
27                         System.out.println();
28                     }    
29                 }
30             }
31         }
32         System.out.println("共有"+n+"个不同的三位数。");    
33     }
34 
35 }

 

转载于:https://www.cnblogs.com/pamper/p/10996771.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值