大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
public class Test {
我们提供的服务有:网站建设、成都网站制作、微信公众号开发、网站优化、网站认证、拉萨ssl等。为近1000家企事业单位解决了网站和推广的问题。提供周到的售前咨询和贴心的售后服务,是有科学管理、有技术的拉萨网站制作公司
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String str = "";
while(true) {
System.out.println("请输入一个字符:");
str = sc.nextLine();
if(str=="exit") // 如果字符串为"exit",退出循环
break;
if(str.length()==1) {
char c = str.charAt(0);
System.out.println("它对应的ASCII码为:" + (int)c); //(int)c将c强制转换为它的ascii码
}
else
System.out.println("请输入一位字符。");
}
sc.close();
}
}
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Scanner;
enum Huo {
TX(1, "T恤", 245), WQX(2, "网球鞋", 570), WQP(3, "网球拍", 320);
private int id;
private String name;
private double price;
private Huo(int id, String name, double price) {
this.id = id;
this.name = name;
this.price = price;
}
public int getId() {
return id;
}
public String getName() {
return name;
}
public double getPrice() {
return price;
}
public static Huo getById(int id) {
for (Huo item : Huo.values()) {
if (item.id == id) {
return item;
}
}
return null;
}
}
public class Test {
private static MapInteger, Integer countMap = new HashMapInteger, Integer();
private static double sum = 0;
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
while (true) {
System.out.println("**********************************************");
System.out.println("请选择购买的商品编号:");
for (Huo item : Huo.values()) {
System.out.print(item.getId() + ":" + item.getName() + " ");
}
System.out.println();
System.out.println("**********************************************");
System.out.print("输入购买商品编号:");
int id = in.nextInt();
System.out.print("输入购买商品数量:");
int count = in.nextInt();
Integer tmp = countMap.get(id);
if (tmp == null) {
tmp = 0;
}
countMap.put(id, tmp + count);
show();
while (true) {
System.out.print("是否继续(y/n):");
String jixu = in.next();
if ("Y".equalsIgnoreCase(jixu)) {
break;
} else if ("N".equalsIgnoreCase(jixu)) {
System.out.print("请支付:");
double zhifu = in.nextDouble();
System.out.println("应付金额:" + sum);
System.out.println("客户支付:" + zhifu);
System.out.println("找钱:" + (zhifu - sum));
System.exit(0);
} else {
System.out.print("输入错误");
}
}
}
}
private static void show() {
IteratorInteger it = countMap.keySet().iterator();
while (it.hasNext()) {
Integer key = it.next();
Integer count = countMap.get(key);
Huo huo = Huo.getById(key);
double heji = huo.getPrice() * count;
System.out.println(huo.getName() + "¥" + huo.getPrice() + " 数量:" + count + " 合计:" + heji);
sum += heji;
}
}
}
算是最简单的吧
package cn.job01;
import java.util.Scanner;
public class Lx07 {
public static void choice() {
System.out.println("登陆菜单 ");
System.out.println("1登陆系统");
System.out.println("2退出");
}
static void choice1() {
System.out.println("购物管理系统客户信息");
System.out.println("1显示所有客户信息");
System.out.println("2添加客户信息");
System.out.println("3修改客户信息");
System.out.println("4查询客户信息");
}
static void choice2() {
System.out.println("购物管理系统真情回馈");
System.out.println("1幸运大放送");
System.out.println("2幸运抽奖");
System.out.println("3生日问候");
}
public static void main(String[] args) {
choice();
Scanner input = new Scanner(System.in);
System.out.println("请输入1or2");
int num = input.nextInt();
switch (num) {
case 1:
System.out.println("主菜单");
System.out.println("1客户信息管理");
System.out.println("2购物结算");
System.out.println("3真情回馈");
System.out.println("4注销");
break;
}
System.out.println("选择输入数字");
int num1 = input.nextInt();
switch (num1) {
case 1:
choice1();
break;
case 2:
System.out.println("购物结算");
break;
case 3:
choice2();
break;
case 4:
choice();
break;
}
}
}
刚帮你调测了一下,当你输入"n"的时候,已经跳出循环了,只不过你没有输出提示,以为没出来,
又输入字符了所有报错了,应该是输入金额的,我帮你加了下输出你可以看下结果;
public static void main(String args[]){
System.out.println("********************");
System.out.println("");
System.out.println("请选择购买商品编号:");
System.out.println("1.T恤(¥245.0) 网球鞋(¥570.0) 网球拍(¥500.0)");
System.out.println("********************");
System.out.println("");
double s=0;
String d;
do{
System.out.println("请输入商品编号:");
Scanner input=new Scanner(System.in);
int a=input.nextInt();
if(a==1){
System.out.println("请输入购买数量:");
int b=input.nextInt();
double c=245*b;
System.out.println("T恤¥245.0 数量:"+b+" "+"合计:"+c);
s=s+c;
}
else if(a==2){
System.out.println("请输入购买数量:");
int b=input.nextInt();
double c=570*b;
System.out.println("网球鞋¥245.0 数量:"+b+" "+"合计:"+c);
s=s+c;
}
else if(a==3){
System.out.println("请输入购买数量:");
int b=input.nextInt();
double c=500*b;
System.out.println("网球拍¥245.0 数量:"+b+" "+"合计:"+c);
s=s+c;
}
else {System.out.println("无此商品");}
System.out.println("否继续(y/n)");
d=input.next();
}while(d.equals("y"));
System.out.println("===========付款===========");
System.out.println("=====输入金额=====");
Scanner input=new Scanner(System.in);
int x=input.nextInt();
double m=s*0.8;
System.out.println("折扣:0.8");
System.out.println("应付金额:"+m);
System.out.println("实际金额:"+x);
double p=x-m;
System.out.println("找钱:"+p);
}
import java.awt.BorderLayout;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.WindowConstants;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
import javax.swing.SwingUtilities;
public class TestFrame extends javax.swing.JFrame {
private JScrollPane jScrollPane1;
private JTable jTable1;
/**
* Auto-generated main method to display this JFrame
*/
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
TestFrame inst = new TestFrame();
inst.setLocationRelativeTo(null);
inst.setVisible(true);
}
});
}
public TestFrame() {
super();
initGUI();
}
private void initGUI() {
try {
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
{
jScrollPane1 = new JScrollPane();
getContentPane().add(jScrollPane1, BorderLayout.CENTER);
{
TableModel jTable1Model =
new DefaultTableModel(
new String[][] { {"","",""},{} ,{} ,{} },
new String[] { "上网总时间", "上网花费金额" ,"上网单价"});
jTable1 = new JTable();
jScrollPane1.setViewportView(jTable1);
jTable1.setModel(jTable1Model);
}
}
pack();
setSize(400, 300);
} catch (Exception e) {
e.printStackTrace();
}
}
}
import java.util.Scanner;
public class JieZhang {
public static void main(String[] args) {
System.out.println("请输入要结账的顾客数:");
Scanner s = new Scanner(System.in);
int num = s.nextInt();
for(int i=0;inum;i++){
int flag = 1;
double sum = 0;//总价
while(flag==1){
flag = 1;
System.out.println("请输入单价:");
double price = s.nextDouble();
System.out.println("请输入数量:");
int number = s.nextInt();
sum = sum + price * number;
System.out.println("请选择是否继续计算:1继续");
flag = s.nextInt();
}
System.out.println("第"+(i+1)+"位顾客消费:"+sum);
}
}
}