每天一练:持续更新
import java. utility. Scanner;
class xuanze{
public static void main(String[] args){
Scanner sc = new Scanner(System.in)
System. out. println("请输入一个数(1-99)");
int i = Sc. nextInt();
if (i==5){
System. out. println("你猜中了!");
}
if(i!=5){
System. out. println("你猜错了!");
}
}
}
class xunhuan{
public static void main(String[] args){
int count = 0;
for(int i=100;i<1000;i++){
int ge = i%10;
int shi = i/10%10;
int bai = i/100%10;
if(ge*ge*ge+shi*shi*shi+bai*bai*bai == i){
count++;
System.out.println(i);
}
}
System.out.println(count);
}
}
import java.util.Scanner;
class xunhuan2{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
System.out.println("请输入第一个数:");
double i = sc.nextDouble();
System.out.println("请输入第二个数:");
double j = sc.nextDouble();
double k = i+j;
double e = i-j;
System.out.println(i+"+"+j+"="+k);
System.out.println(i+"-"+j+"="+e);
System.out.println(i+"*"+j+"="+i*j);
System.out.println(i+"/"+j+"="+i/j);
System.out.println(i+"%"+j+"="+i%j);
}
}
import java.util.Scanner;
class xunhuan2{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
System.out.println("请输入第一个数:");
int a = sc.nextInt();
System.out.println("请输入第二个数:");
int b = sc.nextInt();
System.out.println("请输入第三个数:");
int c = sc.nextInt();
if(a>b && a>c){
System.out.println("最大值max="+a);
}
else if(b>a && b>c){
System.out.println("最大值max="+b);
}
else{
System.out.println("最大值max="+c);
}
}
}
import java.util.Scanner;
class xunhuan2{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
System.out.println("请输入一个数:");
int a = sc.nextInt();
if(a%2 == 0){
System.out.println("该数是偶数");
}
else{
System.out.println("该数是奇数");
}
}
}
import java.util.Scanner;
class xunhuan2{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
System.out.println("请输入长方体的长:");
double a = sc.nextDouble();
System.out.println("请输入长方体的宽:");
double b = sc.nextDouble();
System.out.println("请输入长方体的高:");
double h = sc.nextDouble();
double s = 2*(a*b+b*h+a*h);
double v = a*b*h;
System.out.println("长方形的面积s="+s);
System.out.println("长方形的体积v="+v);
}
}
import java.util.Scanner;
class xunhuan2{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
System.out.println("请输入圆的半径:");
double r = sc.nextDouble();
double PI = 3.14;
double s = PI*r*r;
double c = PI*2*r;
System.out.println("圆的面积s="+s);
System.out.println("圆的周长c="+c);
}
}
class xunhuan2{
public static void main(String[] args){
System.out.println("byte这种数据类型的最大值为:"+Byte.MAX_VALUE+"\t最小值:"+Byte.MIN_VALUE);
System.out.println("short这种数据类型的最大值为:"+Short.MAX_VALUE+"\t最小值:"+Short.MIN_VALUE);
System.out.println("long这种数据类型的最大值为:"+Long.MAX_VALUE+"\t最小值:"+Long.MIN_VALUE);
}
}
import java.util.Scanner;
class xunhuan2{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
System.out.println("请输入用户名:");
String name = sc.nextLine();
System.out.println("请输入密码:");
int password = sc.nextInt();
if(password == 123321){
System.out.println("你的用户名是:flower"+"你的密码是:******"+"\t");
}
else{
System.out.println("密码错误,请重新输入!");
}
}
}
package com.uplooking.day05.lianxi1;
public class WeekDemo1 {
//输出你一周的安排
//先写一个方法
public void search(int day){
//先判断
if (day>7 || day<0){
System.out.println("对不起,你输入的值有问题");
return;
}
//活得东西
switch (day){
case 1:
case 2:
case 3:
case 4:
case 5:
System.out.println("今天是工作日,努力工作");
break;
case 6:
System.out.println("今天是休息日。睡一天");
break;
case 7:
System.out.println("今天出去玩。。。");
break;
default:
System.out.println("你输入的东西不对,不属于一个星期数。。。");
}
}
}
package com.uplooking.day05.lianxi1;
import java.util.Scanner;
public class Test2 {
public static void main(String[] args) {
System.out.println("请输入你要的天数:");
Scanner input = new Scanner(System.in);
int day = input.nextInt();
//通过对象 去调用方法
WeekDemo1 weekDemo1 = new WeekDemo1();
weekDemo1.search(day);
}
}
class xunhuan2{
public static void main(String[] args){
int day = 0;
double start = 0;
double last = 100;
while(start<last){
if(start<last){
day++;
start +=2.5;
if(day%5==0){
start -= 6;
}
continue;
}
}
System.out.println("第"+day+"天攒够100元");
}
}
import java.util.Scanner;
class xunhuan2{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
System.out.println("请输入第一个数:");
int one = sc.nextInt();
System.out.println("请输入第二个数:");
int two = sc.nextInt();
System.out.println("请输入第三个数:");
int three = sc.nextInt();
System.out.println("请输入第四个数:");
int four = sc.nextInt();
System.out.println("请输入第五个数:");
int five = sc.nextInt();
int a = one>two?one:two;
int b = a>three?a:three;
int c = b>four?b:four;
int d = c>five?c:five;
System.out.println("最大的数为:"+d);
}
}
import java.util.Scanner;
class xunhuan2{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
System.out.println("请输入成绩:");
int grade = sc.nextInt();
if(grade<=100 && grade>90){
System.out.println(grade+"分非常优秀");
}
else if(grade<=90 && grade>80){
System.out.println(grade+"分优秀");
}
else if(grade<=80 && grade>70){
System.out.println(grade+"分良好");
}
else if(grade<=70 && grade>60){
System.out.println(grade+"分一般");
}
else if(grade<=70 && grade>60){
System.out.println(grade+"分不及格");
}
else if(grade<=60 && grade>=0){
System.out.println(grade+"分不及格");
}
else{
System.out.println("输入有误,请重新输入!");
}
}
}
import java.util.Scanner;
class xunhuan2{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
System.out.println(" **********中国人民银行***************");
System.out.println("1.取款 2.存款");
System.out.println("3.转账 4. 汇款");
System.out.println("5.修改密码 6.退出账号");
System.out.println("请输入相应的业务:");
int serve = sc.nextInt();
if(serve == 1){
System.out.println("请输入取款金额:");
}
else if(serve == 2){
System.out.println("请将现金放入窗口:");
}
else if(serve == 3){
System.out.println("请输入转账金额:");
}
else if(serve == 4){
System.out.println("请输入汇款金额:");
}
else if(serve == 5){
System.out.println("请输入新密码:");
}
else if(serve == 6){
System.out.println("确认退出");
}
else{
System.out.println("输入有误,请重新输入!");
}
}
}
package com.uplooking;
import java.util.Scanner;
/*
1. 基类
*/
class Car {
String name;
int price;
int people;
int tonnes;
}
/*
2. 客车类
*/
class kc extends Car {
public kc(String name,int price,int people){
this.name = name;
this.price = price;
this.people = people;
}
/*
* 重写toString方法用于main中输出客车信息
*/
public String toString() {
return name + "\t\t" + price + "\t\t" + people;
}
}
/*
3. 货车类
*/
class hc extends Car {
public hc(String name,int price,int tonnes){
this.name = name;
this.price = price;
this.tonnes = tonnes;
}
/*
* 重写toString方法用于main中输出货车信息
*/
public String toString() {
return name + "\t\t" + price + "\t\t" + tonnes;
}
}
/*
4. 皮卡类
*/
class pc extends Car {
public pc(String name,int price,int tonnes,int people){
this.name = name;
this.price = price;
this.tonnes = tonnes;
this.people = people;
}
/*
* 重写toString方法用于main中输出皮卡车信息
*/
public String toString() {
return name + "\t\t" + price + "\t\t" + people + "\t\t" + tonnes;
}
}
/*
5. 测试类
*/
public class Main {
public static void main(String[] args) {
//TODO自动生成的方法存根
System.out.println("欢迎使用哒哒租车系统:");
System.out.println("请问是否要租车 1是 0否");
Scanner fake =new Scanner(System.in);//判断是否进入租车系统
Car[]car={
new kc("K001",500,4),//利用基类初始化各车辆信息方便后面使用多态car.*
new kc("K002",400,4),
new kc("K003",800,20),
new hc("H001",400,4),
new hc("H002",1000,20),
new hc("H003",1500,20),
new pc("P001",450,4,2),
new pc("P002",900,6,4),
new pc("P003",1250,8,6),
};
if(fake.nextInt() == 1){
System.out.println("下列为现有车型");
System.out.println("车号"+"\t\t车名"+"\t\t金额(元)"+"\t拉客量(人)&拉货量(t)");
for(int i = 0;i <car.length;i ++){
//循环输出各车辆信息
System.out.println((i+1)+"\t\t"+car[i]);
}
System.out.println("请问要租几辆车?");
int a = fake.nextInt();//a保存租车数
int zongjia = 0;//保存总价
int renshu = 0;//保存总人数
int dunshu = 0;//保存总顿数
int jiage = 0;//保存每辆车的价格
for(int i = 0;i <a;i ++){
//循环租车次数
System.out.println("请输入要租的第" + (i+1) +"辆车号");
int chehao = fake.nextInt();
System.out.println("您租车的信息为:");
System.out.println(car[chehao-1]);//输出租车信息
System.out.println("请输入要租天数:");
jiage = car[chehao-1].price;//保存该车价格
int day = fake.nextInt();//获取天数
zongjia = jiage * day + zongjia;//计算总价格
renshu = car[chehao-1].people + renshu;//计算总人数
dunshu = car[chehao-1].tonnes + dunshu;//计算总吨数
}
System.out.println("租车总价格");
System.out.println(zongjia);
System.out.println("共载" + renshu +"人" +" 载货" +dunshu +"吨");
}
fake.close(); //Scanner对象关闭
}
}
package day05.lianxi1;
import java.util.Scanner;
import java.util.Scanner;
/**
* 吃货联盟订餐管理系统
*
* @author rong.zhou
*
*/
public class Test2 {
public static void main(String[] args) {
// 数据主体:一组订单信息
String[] names = new String[4]; // 订餐人名称
String[] dishMegs = new String[4]; // 所选菜品
int[] times = new int[4]; // 送餐日期
String[] addresses = new String[4]; // 送餐地址
int[] states = new int[4]; // 订单状态: 0:已预定 1:已完成
double[] sumPrices = new double[4]; // 总金额
//初始化2个订单信息
names[0] = "张晴";
dishMegs[0] = "红烧带鱼 2份";
times[0] = 3;
addresses[0] = "天成路207号";
sumPrices[0] = 76.0;
states[0] = 1;
names[1] = "张晴";
dishMegs[1] = "鱼香肉丝 2份";
times[1] = 10;
addresses[1] = "天成路207号";
sumPrices[1] = 20.0;
// 供选择的菜品信息
String[] dishNames = {
"红烧带鱼", "鱼香肉丝", "时令鲜蔬" }; // 菜品名称
double[] prices = new double[] {
38.0, 20.0, 10.0 }; // 菜品单价
int[] praiseNums = new int[3];
Scanner input = new Scanner(System.in);
int num = -1; // 用户输入0返回主菜单,否则退出系统
boolean isExit = false; // 标志用户是否退出系统: true:退出系统
System.out.println("\n欢迎使用“吃货联盟订餐系统”");
// 循环:显示菜单,根据用户选择的数字执行相应功能
do {
// 显示菜单
System.out.println("****************************");
System.out.println("1、我要订餐");
System.out.println("2、查看餐袋");
System.out.println("3、签收订单");
System.out.println("4、删除订单");
System.out.println("5、我要点赞");
System.out.println("6、退出系统");
System.out.println("****************************");
System.out.print("请选择:");
int choose = input.nextInt(); // 记录用户选择的功能编号
boolean isAdd = false; //记录是否可以订餐
boolean isSignFind = false; //找到要签收的订单
boolean isDelFind = false; //找到要删除的订单
// 根据用户选择的功能编号执行相应功能
switch (choose) {
case 1:
// 我要订餐
System.out.println("***我要订餐***");
for (int j = 0; j < names.length; j++) {
if(names[j] == null){
//找到第一个空位置,可以添加订单信息
isAdd = true; //置标志位,可以订餐
System.out.print("请输入订餐人姓名:");
String name = input.next();
// 显示供选择的菜品信息
System.out.println("序号" + "\t" + "菜名"+"\t"+"单价");
for (int i = 0; i < dishNames.length; i++) {
String price = prices[i] + "元";
String priaiseNum = (praiseNums[i]) > 0 ? praiseNums[i]
+ "赞" : "";
System.out.println((i + 1) + "\t" + dishNames[i] + "\t" +price+"\t"+ priaiseNum);
}
// 用户点菜
System.out.print("请选择您要点的菜品编号:");
int chooseDish = input.nextInt();
System.out.print("请选择您需要的份数:");
int number = input.nextInt();
String dishMeg = dishNames[chooseDish - 1]
+" "+ number + "份";
double sumPrice = prices[chooseDish - 1] * number;
//餐费满50元,免送餐费10元
double deliCharge = (sumPrice>=50)?0:6;
System.out.print("请输入送餐时间(送餐时间是10点至20点间整点送餐):");
int time = input.nextInt();
while (time < 10 || time > 20) {
System.out.print("您的输入有误,请输入10~20间的整数!");
time = input.nextInt();
}
System.out.print("请输入送餐地址:");
String address = input.next();
//无需添加状态,默认是0,即已预定状态。
System.out.println("订餐成功!");
System.out.println("您订的是:"+dishMeg);
System.out.println("送餐时间:"+time+"点");
System.out.println("餐费:"+sumPrice+"元,送餐费"+deliCharge+"元,总计:"+(sumPrice+deliCharge)+"元。");
//添加数据
names[j] = name;
dishMegs[j] = dishMeg;
times[j] = time;
addresses[j] = address;
sumPrices[j] = sumPrice+deliCharge;
break;
}
}
if(!isAdd){
System.out.println("对不起,您的餐袋已满!");
}
break;
case 2:
// 查看餐袋
System.out.println("***查看餐袋***");
System.out.println("序号\t订餐人\t餐品信息\t\t送餐日期\t送餐地址\t\t总金额\t订单状态");
for(int i=0;i<names.length;i++){
if(names[i]!=null){
String state = (states[i]==0)?"已预定":"已完成";
String date = times[i]+"日";
String sumPrice = sumPrices[i]+"元";
System.out.println((i+1)+"\t"+names[i]+"\t"+dishMegs[i]+"\t"+date+"\t"+addresses[i]+"\t"+sumPrice+"\t"+state);
}
}
break;
case 3:
// 签收定单
System.out.println("***签收定单***");
System.out.print("请选择要签收的订单序号:");
int signOrderId = input.nextInt();
for(int i=0;i<names.length;i++){
//状态为已预定,序号为用户输入的订单序号:可签收
//状态为已完成,序叼为用户输入胡订单序号:不可签收
if(names[i]!=null && states[i]==0 && signOrderId==i+1){
states[i] = 1; //将状态值置为已完成
System.out.println("订单签收成功!");
isSignFind = true;
}else if(names[i]!=null && states[i]==1 && signOrderId==i+1){
System.out.println("您选择的订单已完成签收,不能再次签收!");
isSignFind = true;
}
}
//未找到的订单序号:不可签收
if(!isSignFind){
System.out.println("您选择的订单不存在!");
}
break;
case 4:
// 删除订单
System.out.println("***删除订单***");
System.out.print("请输入要删除的订单序号:");
int delId = input.nextInt();
for(int i=0;i<names.length;i++){
//状态值为已完成 序号值为用户输入的序号:可删除
//状态值为已预定 序号值为用户输入的序号:不可删除
if(names[i]!=null && states[i]==1 && delId==i+1){
isDelFind = true;
//执行删除操作:删除位置后的元素依次前移
for(int j=delId-1;j<names.length-1;j++){
names[j] = names[j+1];
dishMegs[j] = dishMegs[j+1];
times[j] = times[j+1];
addresses[j] = addresses[j+1];
states[j] = states[j+1];
}
//最后一位清空
names[names.length-1] = null;
dishMegs[names.length-1] = null;
times[names.length-1] = 0;
addresses[names.length-1] = null;
states[names.length-1] = 0;
System.out.println("删除订单成功!");
break;
}else if(names[i]!=null && states[i]==0 && delId==i+1){
System.out.println("您选择的订单未签收,不能删除!");
isDelFind = true;
break;
}
}
//未找到该序号的订单:不能删除
if(!isDelFind){
System.out.println("您要删除的订单不存在!");
}
break;
case 5:
// 我要点赞
System.out.println("***我要点赞***");
// 显示菜品信息
System.out.println("序号" + "\t" + "菜名"+"\t"+"单价");
for (int i = 0; i < dishNames.length; i++) {
String price = prices[i] + "元";
String priaiseNum = (praiseNums[i]) > 0 ? praiseNums[i]
+ "赞" : "";
System.out.println((i + 1) + "\t" + dishNames[i] + "\t" +price+"\t"+ priaiseNum);
}
System.out.print("请选择您要点赞的菜品序号:");
int priaiseNum = input.nextInt();
praiseNums[priaiseNum-1]++; //赞数加1
System.out.println("点赞成功!");
break;
case 6:
// 退出系统
isExit = true;
break;
default:
//退出系统
isExit = true;
break;
}
if (!isExit) {
System.out.print("输入0返回:");
num = input.nextInt();
} else {
break;
}
} while (num == 0);
System.out.println("谢谢使用,欢迎下次光临!");
}
}