Question: Here is the code: import java.util.Scanner; public class A0Q1 { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int Items = scanner.nextInt();

Here is the code:

import java.util.Scanner;

public class A0Q1

{

public static void main(String[] args) {

Scanner scanner = new Scanner(System.in);

int Items = scanner.nextInt();

scanner.nextLine();

for (int i = 0; i <= Items; i++) {

String line = scanner.nextLine();

String[] parts = line.split(" ");

String name = parts[0];

int SHU = Integer.parseInt(parts[1]);

double Price1 = Double.parseDouble(parts[2]);

double Price2 = Double.parseDouble(parts[3]);

double Price3 = Double.parseDouble(parts[4]);

String warning = "mild";

if (SHU > 10000 && SHU < 1000000) {

warning = "hot!";

} else if (SHU >= 1000000) {

warning = "DANGER!!!";

}

System.out.printf("%s Wings cost $%.2f/$%.2f/$%.2f and have %d Scovilles (%s) ",

name, Price1, Price2, Price3, SHU, warning);

}

}

}

and here are the inputs:

7 Spicy 8000 7 12 20 Hot 15000 7 12 20 Dangerous 20000 8 13 22 HabaneroArrow 350000 12 20 27 SmokeyChipotle 7500 10 18 25 TropicalSunburn 50000 12 20 27 MadHatter 350000 12 20 27

and the codio shows :

Spicy Wings cost $7.00/$12.00/$20.00 and have 8000 Scovilles (mild) Hot Wings cost $7.00/$12.00/$20.00 and have 15000 Scovilles (hot!)

Dangerous Wings cost $8.00/$13.00/$22.00 and have 20000 Scovilles (hot!)

HabaneroArrow Wings cost $12.00/$20.00/$27.00 and have 350000 Scovilles (hot!)

SmokeyChipotle Wings cost $10.00/$18.00/$25.00 and have 7500 Scovilles (mild)

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 4 out of bounds for length 4 at A0Q1.main(A0Q1.java:17)

I can not find where the wrong is.:(

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!