Почему мои последние два оператора if имеют незаконный запуск выражения, а без ошибок? также я не могу опубликовать свой код здесь, потому что он хочет форматирования, и я не знаю, как это сделать правильно. как я могу опубликовать фактический код?Почему я получаю ошибку, если инструкции else
Я изменил его, и это отредактированный код. благодарю вас за вашу помощь.
//Import Java scanner
import java.util.Scanner;
//This class ask a user for their item count and informs the user of the best packing method.
public class PackingOrganizer{
public static void main(String[] args){
//declare constants and variables
int CARTONS = 4, BOXES = 5;
double containerAmount;
double containerAmount2;
//Get users item count
Scanner input = new Scanner(System.in);
System.out.print("Enter number of items : (All partial items are to be rounded up. ex. 6.5 items is rounded to 7 items)");
double itemCount = input.nextDouble();
//Check to see if input is an integer value
if (itemCount != (int) itemCount)
System.out.println("Invalid input round all partial numbers up");
//processing phase
else if (itemCount % CARTONS == 0){
containerAmount =(itemCount /CARTONS);
System.out.println("Cartons can be used. The " + itemCount + " items will require " + containerAmount + " cartons ");}
else if (itemCount % BOXES ==0){
containerAmount = (itemCount/BOXES);
System.out.println("Boxes can be used. The " + itemCount + " items will require " + containerAmount + " Boxes ");}
else if ((itemCount % BOXES != 0) && (itemCount % CARTONS != 0))
System.out.println("Neither boxes nor cartons can be used for your: " + itemCount + " items.");
else if ((itemCount % BOXES == 0) && (itemCount % CARTONS == 0));{
containerAmount = (itemCount/BOXES);
containerAmount2 = (itemCount/CARTONS);
System.out.println("Cartons can be used. The " + itemCount + " items will require " + containerAmount2 +"." + " Boxes can be used. The " + itemCount + " items will require" + containerAmount +" boxes ");}
}
}
Скопируйте свой код, выделите его и нажмите кнопку '{}'. –
Просто положил backticks вокруг вашего кода и опубликовал его – s3nzoM
Это очень понравилось. –