一、年会找座
import java.util.Scanner;
public class Annualmeeting {
public static void main(String args[]) {
System.out.println("请输入您的姓名:"); //输出操作提示
Scanner sc = new Scanner(System.in); //输入字符串数据
String a = sc.nextLine(); //储存字符串数据
switch (a) { //switch语句
case "张龙":System.out.println("您是一号桌");break;
case "赵虎":System.out.println("您是二号桌");break;
case "王潮":System.out.println("您是三号桌");break;
}
}
}
二、 手机号隐藏
import java.util.Scanner;
public class PhoneNumber {
public static void main(String args[]) {
System.out.println("请输入手机号:"); //输出操作提示
Scanner sc = new Scanner(System.in); //输入数据
String number = sc.next(); //存入字符串
String substr = number.substring(3,7); //截取字符串
String number1 = number.replace(substr ,"****"); //替换字符串
System.out.println("手机号"+ number +"屏蔽后的效果:" + number1); //输出效果
}
}
三、模拟商品入库功能
import java.util.Scanner;
public class CommodityWarehousing {
public static void main(String args []) {
Scanner sc = new Scanner(System.in);
System.out.println("请您输入商品编号:");
String number = sc.next();
System.out.println("请您输入商品名称:");
String name = sc.next();
System.out.println("请您输入商品规格:");
String guige = sc.next();
System.out.println("请您输入商品价格:");
String price = sc.next();
System.out.println("请您输入商品数量:");
String quantity = sc.next();
System.out.println("商品入库单");
System.out.println(" 商品编号"+ number);
System.out.println(" 商品名称"+ name);
System.out.println(" 商品规格"+ guige);
System.out.println(" 商品价格"+ price);
System.out.println(" 商品数量"+ quantity);
System.out.println(" 保存 取消");
}
}
四、实时更新导航菜单
import java.util.Scanner;
public class Dhssgx {
public static void main(String args[]) {
String a = new String("天猫 聚划算 天猫超市 |淘抢购 电器城 司法拍卖 淘宝心选 兴农扶贫 |飞猪旅行");
System.out.println(a);
System.out.println("请您选择要被替换的导航菜单:");
Scanner sc = new Scanner(System.in);
String b = sc.next();
System.out.println("请您输入新的导航菜单:");
String c = sc.next();
String d = a.replace(b , c);
System.out.println("被替换后的导航菜单:"+ d);
}
}
五、模拟输出中国联通流量提醒
import java.util.Date;
public class LiuLiangTiXing {
public static void main(String args[]) {
float u = 3.59f ;
float h = 3.40f ;
String d = "http://u.10010.cn/tAE3v";
Date date = new Date();
String month = String.format("%tm", date);
String day = String.format("%td", date);
String hour = String.format("%tH",date);
System.out.println("中国联通流量提示:");
System.out.println("截止"+ month +"月"+ day +"号"+ hour +"时");
System.out.println("您的共享通用流量已用"+ u +"GB剩余流量为"+ h +"GB");
System.out.println("如需查询流量详情,亲您登陆"+ d +"进行查询");
}
}