74 求机票的价格;求质数
package com.fqs.test; public class hello { public static void main(String[] args) { //卖飞机票 //机票的价格按照第一 淡11月到4月、旺季5月到10月; // 第二 头等舱 旺季 9折、经济舱旺季 8.5折收费 // 第二 头等舱 淡季7折、经济舱旺季 6.5折收费 //输入机票原价 月份 头等舱 经济舱 显示售价 double price=1000; int mouth=4; int cang=1; System.out.println("打完折的价格:"+getPrice(price,mouth,cang)); } public static double getPrice (double price,int mouth,int cang) { double zhePrice=1; if(cang==1){//头等舱 if(mouth>=5&&mouth<=10){ zhePrice=price*0.9; }else{ zhePrice=price*0.7; } }else{//经济舱 if(mouth>=5&&mouth<=10){ zhePrice=price*0.85; }else{ zhePrice=price*0.65; } } return zhePrice; } }//类结束
求飞机票的价格 优化后 增加了不合法判断
package com.fqs.test; public class hello { public static void main(String[] args) { //卖飞机票 需要对非法数据做校验 //机票的价格按照第一 淡11月到4月、旺季5月到10月; // 第二 头等舱 旺季 9折、经济舱旺季 8.5折收费 // 第二 头等舱 淡季7折、经济舱旺季 6.5折收费 //输入机票原价 月份 头等舱 经济舱 显示售价 double price=1000.0; int mouth=4; int cang=1; double v1=1.0; double v2=1.0; boolean isW=getIsOne(mouth); System.out.println("机票价格:"+getV(price,cang,isW,v1,v2)); } //判断淡季和旺季 public static boolean getIsOne(int mouth) { boolean isOne=false; if(mouth>=5&&mouth<=10){ //旺季 isOne=true; }else if(mouth<1||mouth>12){ //不合法 System.out.println("月份不合法"); }else{ //淡季 isOne=false; } return isOne; } //判断是否是 头等舱和经济舱 获得折扣后值 public static double getV (double price, int cang, boolean isOne, double v1, double v2) { double zhePrice=1.0; if(cang==1){//头等舱 if(isOne==true){ v1=0.9;//旺季 zhePrice=price*v1; }else { v2=0.85;//淡季 zhePrice=price*v2; } }else if(cang==2){//经济舱 if(isOne==true){ v1=0.7;//旺季 zhePrice=price*v1; }else { v2=0.65;//淡季 zhePrice=price*v2; } }else { System.out.println("不合法"); } return zhePrice; } }//类结束
求质数
package com.fqs.test; public class hello { public static void main(String[] args) { //找1到10之间的质数 //能被1整除 7除以1等于7 8除以2等于4 int start=1; int end=10; for(int num=start;num<end;num++){ if(isZ(num,end)==true) { System.out.println("质数:"+num); } } } //判断是否是质数 public static boolean isZ(int num,int end) { boolean isZ=false; int count=0;//被整除的次数 for(int i=2;i<=end;i++){ if(num!=i && num%i==0){//102不等于2 且102对2求余==0 ;101不等于2并且101对2求余数不为0 //能整除,不是质数 count++; } } if(count==0){ isZ=true; } return isZ; } }//类结束
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 使用C#创建一个MCP客户端
· ollama系列1:轻松3步本地部署deepseek,普通电脑可用
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 按钮权限的设计及实现
2021-06-08 robotFramework里 python3.8打不开RIDE的解决办法
2021-06-08 Robot Framework安装与使用