在下面的java代码中,我如何要求用户在每个咖啡杯中输入他们想要的镜头数(假设他们订购了超过1个)? import java.util.scanner; 公共级咖啡机器人{ 公共静态void main(字符串[]args){ 扫描仪键盘=新扫描仪(System.in); System.out.println(“你好,你叫什么名字?”); 字符串名称=scanner.nextline(); System.out.println(“您想点些咖啡,”+name+(是/否)?) 字符串响应=scanner.nextline() { 如果响应=y System.out.println(“太好了!让我们开始吧。”) System.out.println(“库存中有6个咖啡杯,每个售价2.00美元”); System.out.println(“库存中有8杯咖啡,每杯售价1美元”); System.out.println(“您想要多少杯咖啡?”); int杯; cups=键盘.nextInt(); { 如果cups=0; System.out.println(“没有杯子,没有咖啡,再见”); 系统退出(); 如果cups6; System.out.println(“库存不足,请稍后再来。”); 系统退出(); } System.out.println(“杯子1中有多少杯咖啡?”); int-shots; shots=键盘.nextInt();
例如,如果用户订购2个杯子,我应该询问用户每个杯子(即cup1和cup2)需要多少张照片。有人可以建议我如何为这个动作构造代码吗?您的代码有很多错误。因此我更正了代码,如下所示:在下面的java代码中,我如何要求用户在每个咖啡杯中输入他们想要的镜头数(假设他们订购了超过1个)? import java.util.scanner; 公共级咖啡机器人{ 公共静态void main(字符串[]args){ 扫描仪键盘=新扫描仪(System.in); System.out.println(“你好,你叫什么名字?”); 字符串名称=scanner.nextline(); System.out.println(“您想点些咖啡,”+name+(是/否)?) 字符串响应=scanner.nextline() { 如果响应=y System.out.println(“太好了!让我们开始吧。”) System.out.println(“库存中有6个咖啡杯,每个售价2.00美元”); System.out.println(“库存中有8杯咖啡,每杯售价1美元”); System.out.println(“您想要多少杯咖啡?”); int杯; cups=键盘.nextInt(); { 如果cups=0; System.out.println(“没有杯子,没有咖啡,再见”); 系统退出(); 如果cups6; System.out.println(“库存不足,请稍后再来。”); 系统退出(); } System.out.println(“杯子1中有多少杯咖啡?”); int-shots; shots=键盘.nextInt();,java,Java,例如,如果用户订购2个杯子,我应该询问用户每个杯子(即cup1和cup2)需要多少张照片。有人可以建议我如何为这个动作构造代码吗?您的代码有很多错误。因此我更正了代码,如下所示: import java.util.scanner; public class CoffeeBot { public static void main(String[] args) { Scanner keyboard = new Scanner (System.in); System.out.prin
import java.util.scanner;
public class CoffeeBot {
public static void main(String[] args) {
Scanner keyboard = new Scanner (System.in);
System.out.println("Hello, what's your name?");
String name = scanner.nextline();
System.out.println("Would you like to order some coffee, "+name+(y/n)?")
String response = scanner.nextline()
{
if response = y
System.out.println("Great! Lets get started.")
System.out.println("There are 6 coffee cups in stock and each costs $2.00.");
System.out.println("There are 8 coffee shot in stock and each costs $1.00.");
System.out.println("How many cups of coffee would you like?");
int cups;
cups = keyboard.nextInt();
{
if cups = 0;
System.out.println("No cups, no coffee. Goodbye.");
System.exit();
if cups < 0;
System.out.println("Does not compute. System terminating.");
System.exit();
if cups > 6;
System.out.println("Not enough stock. Come back later.");
System.exit();
}
System.out.println("How many coffee shots in cup 1?");
int shots;
shots = keyboard.nextInt();
此方法将循环多次询问用户需要多少次放炮,并将其放置在一个数组中。最后,该数组将返回到调用该方法的位置。您可以根据需要执行任何操作
import java.util.Scanner;
public class CoffeeBot {
static Scanner keyboard = new Scanner (System.in);
public static void main(String[] args) {
System.out.println("Hello, what's your name?");
String name = keyboard.next();
System.out.println("Would you like to order some coffee, "+name+"(y/n)?");
String response = keyboard.next();
{
if (response.equalsIgnoreCase("y")){
System.out.println("Great! Lets get started.");
System.out.println("There are 6 coffee cups in stock and each costs $2.00.");
System.out.println("There are 8 coffee shot in stock and each costs $1.00.");
System.out.println("How many cups of coffee would you like?");
int cups;
cups = keyboard.nextInt();
{
if (cups == 0){
System.out.println("No cups, no coffee. Goodbye.");
}
if (cups < 0){
System.out.println("Does not compute. System terminating.");
}
if (cups > 6){
System.out.println("Not enough stock. Come back later.");
}
}
shots(cups); //This methods calls the shots static class
}
}
}
public static int[] shots(int num){
int[] shots = new int[num];
for(int i = 0; i<num;i++){
System.out.println("How many coffee shots in cup "+(i+1)+" ?");
shots[i] = keyboard.nextInt();
}
return shots;
}
}
public static int[] shots(int num){
int[] shots = new int[num];
for(int i = 0; i<num;i++){
System.out.println("How many coffee shots in cup "+(i+1)+" ?");
shots[i] = keyboard.nextInt();
}
return shots;
}