欢迎光临散文网 会员登陆 & 注册

java

2023-02-24 13:03 作者:Eagertofly  | 我要投稿

package test3; //0.03mm对折超过8848.13m

public class Duizhe {

    public static void main(String[] args) {

        double houdu = 0.08;

        int cishu = 0;

        while (houdu<=8848130){

            houdu=houdu*2;

            cishu++;

        }

        System.out.println("需要对折:"+cishu+"次");

    }

}

package test3; //java作业 c语言作业

public interface Demo{

    void javazy();

    void czy();

}

public class Jk implements Demo {

    @Override

    public void javazy(){

        //TODO Auto-generated method stub

        System.out.println("java作业完成");

}

@Override

public void czy(){

        //TODO Auto-generated method stub

        System.out.println("c语言作业完成");

}

public static void main(String[] args){

        Jk jk = new Jk();

        jk.javazy();

        jk.czy();

    }

}

package test3; //定义集合储存五个学生名字

import java.util.Scanner; //控制台输入名字

public class Jihe {   //判断是否在集合内

 public static void main(String[] args) {

  Scanner scanner = new Scanner(System.in);

  String arrayl[] = new String[5];

  for(int i = 0; i < arrayl.length; i++) {

   System.out.println("请输入第"+(i +1)+"位学生的姓名");

   arrayl[i] = scanner.next();

  }

  System.out.println("输入学生的姓名如下: ") ;

  for(String a : arrayl) {

  System.out.println(a);

  }

  System.out.println("请输入要查询的学生姓名:");

  String find = scanner.next();

  int position = -1;

  for(int i = 0;i < arrayl.length; i++) {

   if(find.equals(arrayl[i])) {

    position = i;

    System.out.println(find + "的索引位置是" + position);

   }

  }

  if(position == -1){

   System.out.println("未找到");

  }

 }

}

package test3; //计算1-100除了50之外的累计和

public class Leijia {

    public static int leijia(int y)

    {

        int sum = 0;

        for (int j=1;j<101;j++){

            if(j==50){

                continue;

            }

            else{

                sum+=j;

            }

        }

        return sum;

    }

    public static void main(String[] args) {

        int y=0;

        int sum=leijia(y);

        System.out.println(sum);

    }

}

package test3; //根据身份证分辨男女

import java.util.Scanner;

public class Demo3 {

    public static void main(String[] args) {

         System.out.println("请输入18位身份证号码:");

         Scanner scanner  = new Scanner(System.in);

         String number = scanner.next();

         String sex;

         int n = number.charAt(16);

         int year,month,day;

             if (n%2==0){

             sex = "女";

             }else{

                sex = "男";

             }

            System.out.println("性别为:"+sex);

    }

}

package test3;  //输入字符串,判断数字出现次数

import java.util.Scanner;

public class Zfc {

    public static void main(String[] args) {

         Scanner scanner = new Scanner(System.in);

         int b = 0;

         String a= scanner.next ();

         char[] ch = a.toCharArray();

         for(char c: ch ){

            if (c>48 && c<57){

                b=b+1;

            }

            System.out.println(b);

        }

    }

}

package test3; //数组存储12个成绩并算出平均数

public class Pingjun {

    public static void main(String[] args) {

         int[] a = {72,89,65,87,91,53,82,71,93,76,68};

         int sum = 0;

         for (int i = 0; i < a.length; i++){

            sum+=a[i];

        }

         int x = 0;

         x = sum /a.length;

         System.out.println("平均数:"+x);

    }

}

package test3;

public class Car {

     private String brand;

     private double longs;

     private String color;

     private double price;

     public String getBrand() {

         return brand;

     }

     public void setBrand(String brand) {

         this.brand = brand;

     }

     public double getLongs() {

         return longs;

     }

     public void setLongs(double longs) {

         this.longs = longs;

     }

     public String getColor() {

         return color;

     }

     public void setColor(String color) {

         this.color = color;

     }

     public double getPrice() {

         return price;

     }

     public void setPrice(double price) {

         this.price = price;

     }

     public Car(String brand,double longs,String color,double price){

     super();

         this.brand = brand;

         this.longs = longs;

         this.color = color;

         this.price = price;

     }

     public  Car() {

          super();

     }

     public void run() {

     }

     public static void main(String[] args) {

         Car car1 = new Car("捷达",5.3,"红色",8.9);

         Car car2 = new Car("宝马",5.8,"黑色",35.5);

         Car car3 = new Car("捷达",5.3,"红色",11.5);

         Car car4 = new Car("捷达",5.3,"红色",11.5);

         Car car5 = new Car("捷达",5.3,"红色",11.5);

    }

}  


java的评论 (共 条)

分享到微博请遵守国家法律