标题2021年第一次接触Java
java老师布置的第一次作业
package cn.jc.output;
public class Twochapter {
public static void main(String[] args){
//课堂练习题:P21案例
int wangScore=80;
int zhangScore=wangScore+15;
System.out.println("张萌的Java:"+zhangScore);
//运算符“+”的延伸知识
int a=10;
int b=100;
System.out.println("a+b="+(a+b));
//课堂练习题:P22-P23案例和示例3
int com=85;
int javascore=97;
int MySQL=93;
double avg=(com+javascore+MySQL)/3;
int diffen=javascore-MySQL;
System.out.println("-------------------------------");
System.out.println("计算机基础\tjava\tMySQL");
System.out.println(com+"\t"+"\t"+javascore+"\t"+MySQL);
System.out.println("-------------------------------");
System.out.println("java和MySQL的分数差:"+diffen);
System.out.println("平均分:"+avg);
System.out.println("\n");
//数据类型转换 P23
//1.自动数据类型转换
int score = 8;
double newScore = score;
System.out.println(newScore);
//2.强制数据类型转换
double pi = 3.14;
int ji = (int)pi;
System.out.println(ji);
//关系运算符 P23
//案例4
int zhanScore=90;
int liScore=80;
boolean isHeight=zhanScore>liScore;
boolean issame=zhanScore==liScore;
System.out.println("张三的成绩比李四的成绩高吗:"+isHeight);
System.out.println("张三的成绩和李四的成绩是否相等:"+issame);
System.out.println("\n");
//第二单元的课后作业
//1.(课上练习)
System.out.println("------------消费单------------");
System.out.println("商品名称\t商品单价\t个数\t金额");
int shirt = 246;
int shirtnumber = 2;
int shoe = 570;
int shoenumber = 1;
int racket = 320;
int racketnumber = 1;
double num;
num = (int)(shirt*shirtnumber+shoe*shoenumber+racket*racketnumber)*0.8;
System.out.println("T恤\t"+shirt+"\t"+shirtnumber+"\t"+shirt*shirtnumber);
System.out.println("网球鞋\t"+shoe+"\t"+shoenumber+"\t"+shoe*shoenumber);
System.out.println("网球拍\t"+racket+"\t"+racketnumber+"\t"+racket*racketnumber);
System.out.println("消费总金额:"+num);
System.out.println("\n");
//2.(变量值的交换)------技巧:[利用第三个变量达到变量值的交换]
int left = 10;
int right = 8;
int added;
System.out.println("输出互换前手中的纸牌:");
System.out.println("左手的纸牌:"+left);
System.out.println("右手的纸牌:"+right);
added = left;
left = right;
right = added;
System.out.println("输出互换后手中的纸牌:");
System.out.println("左手的纸牌:"+left);
System.out.println("右手的纸牌:"+added);
System.out.println("\n");
//3. 2.4自助取款机-欢迎界面 P25
/* ----设置用戶名,密码及账号余额
* String Administrator = "shaolei";
int password = 1234567890;
double mony = 520;
*/
//基本信息
System.out.println("**************************************");
System.out.println("\t欢迎登陆前程ATM系统\n");
System.out.println("\t1.查询\n"+"\t2.存款\n"+"\t3.取款\n"+"\t4.修改密码\n"+"\t5.退出\n");
System.out.println("**************************************");
}
}