• 作业0508


    题目一:打印出所有的 "水仙花数 ",所谓 "水仙花数 "是指一个三位数,其各位数字立方和等于该数本身。例如:153是一个 "水仙花数 ",因为153=1的三次方+5的三次方+3的三次方。

    public class Shuixianhua {
    
        public static void main(String[] args) {
            // TODO 自动生成的方法存根
    
            //三位数 100-999;各位数字立方和等于自身
            
            
            for(int x=1;x<=9;x++)
            {
                
                for(int y=0;y<=9;y++)
                {
                    
                    for(int z=0;z<=9;z++)
                    {
                        int sum=x*x*x+y*y*y+z*z*z;
                        if(sum==x*100+y*10+z)
                        {
                            System.out.println(sum);
                        }
                    }
                }
                
                
                
            }
            

    运行结果:

     

    题目二:我国古代数学家张邱建在《算经》中出了一道“百钱买百鸡”的问题,题意是这样的:5文钱可以买一只公鸡,3文钱可以买一只母鸡,1文钱可以买3只雏鸡。现在用100文钱买100只鸡,那么各有公鸡、母鸡、雏鸡多少只?请编写程序实现。

    public class Chicken {
    
        public static void main(String[] args) {
            // TODO 自动生成的方法存根
    
            //5文 公鸡  3文 母鸡  1文  3小鸡   用100文买100只鸡  各有多少
            
            for(int x=0;x<=20;x++)
            {
                
                for(int y=0;y<=33;y++)
                {
                    
                    for(int z=0;z<=300;z++)
                    {
                        
                        if(5*x+3*y+z/3==100 && x+y+z==100 &&z%3==0)
                        {
                            System.out.println("公鸡有"+x+"只,"+"母鸡有"+y+"只,"+"小鸡有"+z+"只"+"	");
                            
                        }
                                                                    
                                            
                    }
                    
                }                        
                            
            }
                                                                                                                    
            
        }
    
    }

    运行结果:

    题目三:这是经典的"百马百担"问题,有一百匹马,驮一百担货,大马驮3担,中马驮2担,两只小马驮1担,问有大,中,小马各几匹?

    public class Horse {
    
        public static void main(String[] args) {
            // TODO 自动生成的方法存根
    
            
            
            for(int x=0;x<=34;x++)
            {
                for(int y=0;y<=50;y++)
                {
                    for(int z=0;z<=200;z++)
                    {
                        if(x+y+z==100 && 3*x+2*y+z/2==100 && z%2==0)
                        {
                            
                            System.out.println("大马有"+x+"匹,"+"中马有"+y+"匹,"+"小马有"+z+"匹");
                            
                        }
                        
                        
                        
                    }
                    
                    
                }
                
                
            }
                                                                            
        }
    
    }

    运行结果:

    题目四:控制台输出九九乘法表

    public class Chengfabiao {
    
        public static void main(String[] args) {
            // TODO 自动生成的方法存根
    
            //for循环测试
            
            for(int i=1;i<=9;i++)
            {
                for(int j=1;j<=i;j++)
                {
                    
                    System.out.print(j+"*"+i+"="+i*j+"	");
                    
                    
                }
                System.out.println();
                
            }                                                        
            
        }
                    
            
    }

    运行结果:

    五、输出菱形

    public class Lingxing {
    
        public static void main(String[] args) {
            // TODO 自动生成的方法存根
             for (int i = 0; i <= 9; i++)
              {
                  for (int k = 0; k < 9-i; k++)
                  {
                      System.out.print(" ");
                  }
                  for (int j = 0; j < i; j++)
                  {
                      System.out.print("* ");
                  }
                  System.out.println();
              }
    
            for(int i=0;i<=8;i++)
            {
                for(int x=0;x<=i;x++)
                {
                    System.out.print(" ");
                }
                
                for(int y=1;y<=8-i;y++)
                {
                    System.out.print("* ");
                }
                
                System.out.println();
                
            }
            
            
            
            
            
            
            
        }
    
    }

    运行结果:

  • 相关阅读:
    卡巴斯基呼吁通过国际立法打击网络犯罪 狼人:
    服务流量论Google的那些服务
    字符数组hdu 4552
    方法说明JAVA复习笔记前言:第一节:从注释开始
    新特性版本Impala各版本新特性
    通知准时为什么讲座时间在通知中提前了半个小时
    集合objectjava_collection
    android对象巧用Android网络通信技术,在网络上直接传输对象
    ejb对象2013年 最新面试题
    提示系统启动关于误更改/var下诺干的权限问题,导致系统启动提示The System is running in lowgraphics mode问题解决 By ACReaper
  • 原文地址:https://www.cnblogs.com/miss123/p/5469773.html
Copyright © 2020-2023  润新知