Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 当满足循环中继续的条件时退出循环_Java_Loops_While Loop - Fatal编程技术网

Java 当满足循环中继续的条件时退出循环

Java 当满足循环中继续的条件时退出循环,java,loops,while-loop,Java,Loops,While Loop,无论我输入“y”还是“n”,程序都会退出while循环。我尝试将一些==更改为.equals,但不管我输入什么,循环都会继续 System.out.println("Just Cycling Caps provides three types of caps: Small caps – ID: 1 Price: $4.50, Medium caps – ID: 2 Price: $7.00, and Large caps – ID: 3 Price: $9.00"); continueOrder

无论我输入“y”还是“n”,程序都会退出while循环。我尝试将一些==更改为.equals,但不管我输入什么,循环都会继续

System.out.println("Just Cycling Caps provides three types of caps: Small caps – ID: 1 Price: $4.50, Medium caps – ID: 2 Price: $7.00, and Large caps – ID: 3 Price: $9.00");
continueOrder = "y";
//While loop to get items ordered
while(continueOrder == "y"){
  //get desired cap size and quantity
  System.out.println("Enter the ID of the item you would like");
  capSize = reader.nextInt();
  if(capSize == 1){
    price = 4.5;
    System.out.println("How many small caps would you like?");
    quantityOfSmall = reader.nextInt();
    priceOfSmall = quantityOfSmall * price;
  }
  else if(capSize == 2){
    price = 7.0;
    System.out.println("How many medium caps would you like?");
    quantityOfMedium = reader.nextInt();
    priceOfMedium = quantityOfMedium * price;
  }
  else if(capSize == 3){
    price = 9.0;
    System.out.println("How many large caps would you like?");
    quantityOfLarge = reader.nextInt();
    priceOfLarge = quantityOfLarge * price;
  }
  //Ask the user if they would like to continue ordering
  System.out.println("Would you like to purchase another product? (y/n)");
  continueOrder = reader.next();
  continueOrder = continueOrder.toLowerCase();
}
改变这个

while(continueOrder == "y")

while(continueOrder.equals("y"))