• java方法的使用作业-0512


    import java.util.Scanner;
    import java.util.Random;
    class zuoye 
    {
        public static void main(String[] args) 
        {
            String[] arr = {"董斌","张锐","王荣臣","韩凯","张禄","刘继勋","张维","牛攀"};
            //遍历名字
            //bl(arr);
            //随机点名
            //sj(arr);
            //库存界面
            //jm();
            //整数相加
            //System.out.println(add(1,2));
            //小数相加
            //System.out.println(add(1.6,3.5));
            //整数判断相等
            //System.out.println(pd(1,2));
            //小数判断相等
            //System.out.println(pd(1.6,3.5));
            //m行 n列的星星矩形
            //jx(3,9);
            //nn乘法表
            //cfb(3);
            //长方形求面积
            //System.out.println(cfx(5.6,5));
            //圆形求面积
            //System.out.println(yx(8));
            //打印除9以外100内的数字 一行5个
            //dys();
            //打印100内的素数 一行5个 记录个数
            //zs();
    
        }
        public static void bl(String[] arr){
            for(int i = 0;i<arr.length;i++){
                 System.out.println(arr[i]);
            }
        }
        public static void sj(String[] arr){
            Random r = new Random();
            int i = r.nextInt(8);
            System.out.println(arr[i]);
    
        }
        public static void jm(){
            System.out.println("------------------------库存管理------------------------");
            System.out.println("1.查看库存清单");
            System.out.println("2.修改商品库存数量");
            System.out.println("3.退出");
            System.out.println("请输入要执行的操作编号:");
            Scanner sc = new Scanner(System.in);
            int num = sc.nextInt();
    
            switch (num)
            {
            case 1:
                 kc();
            break;
            case 2:
                 xg();
            break;
            case 3:
                tc();
            break;
            }
        }
        public static void kc(){
            System.out.println("---------------------------"+"商城库存清单"+"-------------------------------");
            System.out.println("品牌型号"+"	"+"尺寸"+"	"+"价格"+"	"+"库存数");
            String  Product_name1 = "MacBookAir";
            String  Product_name2 = "ThinkpadT450";
            String  Product_name3 = "ASUS-FL5800";
            double  size1 = 13.3;
            double  size2 = 14.0;
            double  size3 = 15.6;
            double  price1 = 6988.88;
            double  price2 = 5999.99;
            double  price3 = 4999.5;
            int  num1 = 5;
            int  num2 = 10;
            int  num3 = 18;
            System.out.println(Product_name1+"	"+size1+"	"+price1+"	"+num1);
            System.out.println(Product_name2+"	"+size2+"	"+price2+"	"+num2);
            System.out.println(Product_name3+"	"+size3+"	"+price3+"	"+num3);
            System.out.println("------------------------------------------------------------------------");
            int anum = num1 + num2 + num3;
            double aprice = price1 + price2 + price3;
            System.out.println("总库存数:"+anum);
            System.out.println("库存商品总金额:"+aprice);
        }
        public static void xg(){
            System.out.println("请输入需要修改的商品编号");
            Scanner sc = new Scanner(System.in);
            int bh = sc.nextInt();
            System.out.println("请输入更改数量");
            int xsl = sc.nextInt();
            int num1 =5;
            int num2 =10;
            int num3 =18;
            if(bh==1){
                  num1 = xsl;
            }else if(bh==2){
                  num2 = xsl;
            }else if(bh==3){
                  num3 = xsl;
            }else{
                  System.out.println("输入有误");
            }
            System.out.println("---------------------------"+"商城库存清单"+"-------------------------------");
            System.out.println("品牌型号"+"	"+"尺寸"+"	"+"价格"+"	"+"库存数");
            String  Product_name1 = "MacBookAir";
            String  Product_name2 = "ThinkpadT450";
            String  Product_name3 = "ASUS-FL5800";
            double  size1 = 13.3;
            double  size2 = 14.0;
            double  size3 = 15.6;
            double  price1 = 6988.88;
            double  price2 = 5999.99;
            double  price3 = 4999.5;
            System.out.println(Product_name1+"	"+size1+"	"+price1+"	"+num1);
            System.out.println(Product_name2+"	"+size2+"	"+price2+"	"+num2);
            System.out.println(Product_name3+"	"+size3+"	"+price3+"	"+num3);
            System.out.println("------------------------------------------------------------------------");
            int anum = num1 + num2 + num3;
            double aprice = price1 + price2 + price3;
            System.out.println("总库存数:"+anum);
            System.out.println("库存商品总金额:"+aprice);
        }
        public static void tc(){
            return;
        }
        public static int add(int a,int b){
            
             return a + b;
        }
        public static double add(double a,double b){
            
             return a + b;
        }
        public static boolean pd(int a,int b){
             return a==b?true:false;
        }
        public static boolean pd(double a,double b){
             return a==b?true:false;
        }
        public static void jx(int m,int n){
             for(int i = 0;i<m;i++){
                for(int j = 0;j<n;j++){
                   System.out.print("*");
                }
                System.out.println();
             }
        }
        public static void cfb(int n){
              for(int i =1;i<=n;i++){
                 for(int j = 1;j<=i;j++){
                     System.out.print(j+"*"+i+"="+i*j+"	");
                 }
                 System.out.println();
              }
        }
        public static double cfx(double a,double b){
                 return a*b;
        }
        public static double yx(double r){
                 return r*r*Math.PI;
        }
        public static void dys(){
                 int j = 0;
                 for(int i = 1;i<=100;i++){    
                 if(i==9){
                   continue;
                 }else if(i%10==9){
                 continue;
                 }else if(i/10>=9 && i/10<10){
                 continue;
                 }else{
                     j++;
                     if(j<6){
                        System.out.print(i+"	");
                     }else{
                         j = 1;
                        System.out.print("
    "+i+"	");
                        
                     }
                 }
                
            }
        }
        public static void zs(){
            int k = 0;
            int n = 0;
            for(int i = 2;i <=100;i++){
                int zhishu = 1; //1表示是质数
                for (int j =2;j< i ;j++){
                    if(i%j == 0){
                        zhishu = 0;  //0表示不是质数
                    }
                }
                if(zhishu == 1){
                    k++;
                    n++;
                    if(k<6){
                         System.out.print(i+"	");
                    }else{
                         k=1;
                        System.out.print("
    "+i+"	");
                    }
                        
                }
                
            }
            System.out.println();
            System.out.println(n);
        }
    
    }
  • 相关阅读:
    C#的GroupBy方法是如何工作的
    流媒体技术探索(一)
    战争雷霆-鼠标穿透
    继承与ER图
    从零开始的文档对象模型(结束更新)
    [hackerrank] booking.com
    [lintcode][美国大公司][1.字符串处理]
    [interview] Aug. 2015
    [codility] Lesson 2 Counting Elements
    [codility] Lesson 1 Time Complexity
  • 原文地址:https://www.cnblogs.com/yelena-niu/p/9035373.html
Copyright © 2020-2023  润新知