java第二章

知识点丶

package com.bdqn.technology;

public class Demo3 {
    
    public static void main(String[] args) {
        /**
         * ctrl + shift + c  注释选中的代码
         */
//        int a = 10;
//        int b = 5;
//        /**
//         * 求余
//         */
//        int c = (a % b);
//        System.out.println(c);
//        
//        
//        int r = 5;
//        
//        double result = (Math.PI * r * r);
//        System.out.println(result);
        /**
         * double > int   double类型的级别比int类型的级别要高
         * 
         * 低级别的类型能够自动转换成高级别的类型
         */
//        double a = 81.29;
//        int b = 2;
//        double c = (a + b);
        
        
//        double a = 2;
        
        /**
         * 低级别类型不能自动转换成高级别类型
         */
//        int b = 2.0;
        
        /**
         * 每一个字符都会对应一个唯一的整数
         * char < int char类型级别比int要低  所以char类型数据能够自动转换成int类型的数据
         */
//        int c = 'B';
//        System.out.println(c);
        
        /**
         * 如果高级别类型数据想要转换成低级别类型数据  称之为  强制转换
         * (输入你想要转换的类型)
         * 转换的到的结果是  整数部分
         */
        double a = 2.6;
        int b = (int)a;
        System.out.println(b);
    }

}

一丶纸牌互换

package com.bdqn.demo;

import java.util.Scanner;

public class Zhipai {
    public static void main(String[] args) {
         Scanner scanner = new Scanner(System.in);
            
        System.out.println("输出互换前手中的纸牌:");
        System.out.print("右手中的纸牌:");
        double  zhipai = scanner.nextDouble();
        
        System.out.print("左手中的纸牌:");
        double  zuoshou = scanner.nextDouble();
        
        System.out.println("\n输出呼唤后手中的纸牌:");
        System.out.println("左手中的纸牌"+zhipai);
        System.out.println("右手中的纸牌"+zuoshou);
    }

}
二丶本金利息

package com.bdqn.demo;

import java.util.Scanner;

public class Benjin {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        System.out.println("请输入本金:");
        double diyi = 0.0225;
        double ernen = 0.027;
        double shann = 0.0324;
        double wunen =0.036;
        int benjin = input.nextInt();
        double qwer=benjin*diyi;
        double wert=benjin*ernen*2;
        double erty=benjin*shann*3;
        double rtyu=benjin*wunen*5;
        System.out.println("本金为:"+benjin);
        System.out.println("存取一年后的本息是:"+(qwer+benjin));
        System.out.println("存取两年后的本息是:"+(wert+benjin));
        System.out.println("存取三年后的本息是:"+(erty+benjin));
        System.out.println("存取五年后的本息是:"+(rtyu+benjin));
    }

}
三丶购物折扣

package com.bdqn.demo;

import java.util.Scanner;

public class Zhekou {
   public static void main(String[] args) {
       int txjg = 245;
       int wqxjg = 570;
       int wqpjg = 320;
       System.out.println("ÇëÊäÈëÕÛ¿Û£º");
    Scanner input =new Scanner(System.in);
    
    double zhekou=input.nextDouble();  
    double txjg1=(txjg*zhekou);
    double wqxjg1=(wqxjg*zhekou);
    double wqpjg1=(wqpjg*zhekou);
    boolean txjg2=txjg1<100;
    boolean wqxjg2=wqxjg1<100;
    boolean wqpjg2=wqpjg1<100;
    System.out.println("TÐôÕÛ¿ÛµÍÓÚ100Âð£¿"+txjg2);
    System.out.println("ÍøÇòЬÕÛ¿ÛµÍÓÚ100Âð£¿"+wqxjg2);
    System.out.println("ÍøÇòÅÄÕÛ¿ÛµÍÓÚ100Âð£¿"+wqpjg2);
    
    
}
}
三丶购物抽奖

package com.bdqn.demo;

import java.util.Scanner;

public class Choujiang {
   public static void main(String[] args) {
       
       
     int custNo;
     System.out.println("请输入四位会员卡号:");
     
     Scanner input = new Scanner(System.in);
     custNo = input.nextInt();
     
     int gewei = custNo%10;
     int shiwei = custNo/10%10;
     int baiwei = custNo/100%10;
     int qianwei = custNo/1000;
     
     int sum = gewei+shiwei+baiwei+qianwei;
     System.out.println("会员卡号"+custNo+"各位之和"+sum);
     boolean isLuck=sum>20;
     System.out.println("是幸运客户没?"+isLuck);
}
}
四丶购物积分


package com.bdqn.demo;

import java.util.Scanner;

public class Teso {
    public static void main(String[] args) {
        System.out.println("***************消费单***************");
        System.out.println("购买物品\t\t单价\t个数\t金额");
        System.out.println("T恤\t\t$245\t2\t$490");
        System.out.println("网球鞋\t\t$570\t1\t$570");
        System.out.println("网球拍\t\t$320\t1\t$320");
        System.out.println("\n折扣:\t\t8折");
        int shirtPrice = 245;  //T恤价格
        int shoePrice = 570;   //网球鞋价格
        int padPrice = 320;    //网球拍价格  
        int momey=1500;        //实际交费
        int shirtNo=2;         //T恤数
        int shoeNo=1;          //网球鞋数目
        int padNo=1;           //网球拍数目 
        double discount = 0.8; 
        double finalpay = (shirtPrice*shirtNo
                +shoePrice*shoeNo+padPrice*padNo)*discount;//计算消费总金额
        double returnMoney=momey-finalpay;
        double score=(int)finalpay*3/100;
        System.out.println("消费总金额\t¥"+finalpay);
        System.out.println("实际交费\t\t¥"+momey);
        System.out.println("找钱\t\t¥"+returnMoney);
        System.out.println("本次购物所获的积分是:"+score);
        
    
    }
}
五丶购物结算

package com.bdqn.demo;
public class Gouwu {
     public static void main(String[] args) {
        int shirtPrice = 245;  //T恤价格
        int shoePrice = 570;   //网球鞋价格
        int padPrice = 320;    //网球拍价格
        int shirtNo=2;         //T恤数
        int shoeNo=1;          //网球鞋数目
        int padNo=1;           //网球拍数目
        double discount = 0.8;   
        double finalpay = (shirtPrice*shirtNo
                +shoePrice*shoeNo+padPrice*padNo)*discount;//计算消费总金额
        System.out.println("消费总金额;"+finalpay);
    }
}
六丶成绩

 package com.bdqn.demo;

import java.util.Scanner;

public class Title {
    
    public static void main(String[] args) {
        /**
         * scanner
         */
        Scanner scanner = new Scanner(System.in);
        System.out.print("请输入java成绩:");
        //读取用户输入的数据
        int javaScore = scanner.nextInt();
        
        System.out.print("请输入SQL成绩:");
        //读取用户输入的数据
        int sqlScore = scanner.nextInt();
        
        System.out.print("请输入STB成绩:");
        //读取用户输入的数据
        int stbScore = scanner.nextInt();
        
        int score1 = javaScore - sqlScore;    
        System.out.println("java成绩与sql成绩之差是:"+score1);
        
        int totalScore = (javaScore + sqlScore +stbScore);
        /**
         * 如果两个整数相除   得到的结果一定是整数   如果有小数  直接省略
         */
        int usa = totalScore / 3;
        System.out.println("平均分是:"+usa);
    }

}
 

猜你喜欢

转载自blog.csdn.net/weixin_43930984/article/details/84981926