2021-04-17

java语言代码完整代码

(希望对你有所有帮助)

package cn.shijie.test;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class test1 {
static mproduct m1 = new mproduct();
static mproduct m2 = new mproduct();
static mproduct m3 = new mproduct();

public static void main(String[] args) {
	// 初始话数据
	GetList();
	System.out.println("***************");
	System.out.println("请选择购买的商品编号");
	System.out.println(m1.id + "." + m1.name + "      " + m2.id + "."
			+ m2.name + "      " + m2.id + "." + m2.name + "      ");
	System.out.println("***************");
	System.out.println("请输入商品编号:");
	Scanner s = new Scanner(System.in);
	int int1 = s.nextInt();
	if (int1 == 1) {
		System.out.println(m1.name + "         " + m1.price);
	} else if (int1 == 2) {
		System.out.println(m2.name + "         " + m2.price);
	} else if (int1 == 3) {
		System.out.println(m3.name + "         " + m3.price);
	}
	System.out.println("是否继续:");


	while (new Scanner(System.in).next().equals("y")) {
		System.out.println("请输入商品编号:");
		Scanner s2 = new Scanner(System.in);
		int int2 = s.nextInt();
		if (int1 == 1) {
			System.out.println(m1.name + "         " + m1.price);
		} else if (int2 == 2) {
			System.out.println(m2.name + "         " + m2.price);
		} else if (int2 == 3) {
			System.out.println(m3.name + "         " + m3.price);
		}
		System.out.println("是否继续:");
	}
}


static class mproduct {
	int id;
	String name;
	double price;


}


static void GetList() {
	m1.id = 1;
	m1.name = "T血";
	m1.price = 245.0;
	m2.id = 2;
	m2.name = "网球鞋";
	m2.price = 570.0;
	m3.id = 1;
	m3.name = "网球拍";
	m3.price = 247.0;
}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值