十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
//第一题的答案:
创新新互联,凭借十载的做网站、网站制作经验,本着真心·诚心服务的企业理念服务于成都中小企业设计网站有1000+案例。做网站建设,选创新互联建站。
import java.util.Scanner;
public class test {
public static void main(String[] args)
{
System.out.println("输入购买金额:");
Scanner input=new Scanner(System.in);
double a=input.nextDouble();
System.out.println("输入顾客类型(会员或普通):");
String b=input.next();
if(b=="会员")
{
if(a=100)
{
a=a*0.8;
System.out.println("需付款:"+a);
}
else
{
System.out.println("需付款:"+a);
}
}
if(b=="普通")
{
if(a=200)
{
a=a*0.75;
System.out.println("需付款:"+a);
}
else
{
System.out.println("需付款:"+a);
}
}
}
}
//下面是第二题答案:
public class test {
public static void main(String[] args)
{
for(int i = 0; i 3; i++)
{
for(int x = i + 1; x 3; x++)
{
System.out.print(" ");
}
for(int y = 0; y (i + 1) * 2 - 1; y++)
{
System.out.print("*");
}
System.out.println();
}
for(int i = 0; i 4; i++)
{
for(int x = 0; x i; x++)
{
System.out.print(" ");
}
for(int y = i; y 2 * 4 - i - 1; y++)
{
System.out.print("*");
}
System.out.println();
}
}
}
尝试解答一下,这个里面还有老年和教师的判断就省略,主要是打折的代码
import java.util.Scanner;
class Test{
public static void main (String[] args){
Scanner sc = new Scanner(System.in);
System.out.println("请输入消费的金额:");
double oldprice = sc.nextDouble();
double newprice;
if(oldprice = 2000){
newprice = oldprice * 0.85;
}else if(oldprice = 1000 oldprice 2000){
newprice = oldprice * 0.9;
}else
newprice = oldprice;
Judge jud = new Judge();
if(jud.isTeacher()|| jud.isOldman())
newprice = newprice * 0.95;
System.out.println("打折后的价格是:" + newprice);
System.out.println("折扣的程度是: " + newprice / oldprice);
}
}
class Judge{
public boolean isTeacher(){
boolean isTeacher = false;
return isTeacher;
}
public boolean isOldman(){
boolean isOld = false;
return isOld;
}
}
2、public class Test11 {
public static void main(String[] args) {
System.out.println("滞贸旅客的人数" + (1189 - 108*10) );
}
}
3、public class Test11 {
public static void main(String[] args) {
try {
Scanner scanner = new Scanner(System.in);
System.out.print("输入购买鸡蛋(斤):");
int number = scanner.nextInt();
if(number10){
throw new RuntimeException("不允许购买这么多!");
}
else {
System.out.println("用户应支付金额"+number*3.98);
}
}
catch (Exception e){
System.out.println(e.getMessage());
}
}
}
public class Test {
public static void main(String[] args) {
System.out.println("请问您需要消费多少钱?");
Scanner scan=new Scanner(System.in);
double sum=0d;
double money=scan.nextDouble();
sum+=money;
System.out.println("本次消费:"+money+"元");
System.out.println("请问您是否需要继续消费?(输入1,表示继续消费)");
int isContinue=scan.nextInt();
while(true){
if(isContinue==1){
System.out.println("请问您需要消费多少钱?");
money=scan.nextDouble();
sum+=money;
System.out.println("本次消费:"+money+"元");
System.out.println("请问您是否需要继续消费?(输入1,表示继续消费)");
isContinue=scan.nextInt();
}else{
System.out.println("本次消费结束");
System.out.println("总共消费:"+sum+"元");
break;
}
}
}
}