Thank you so much, it works now
Result:
run:
Color: Red Length in mm: 16 Sharpness: 1
Color: Yellow Length in mm: 17 Sharpness: 4
Color: Green Length in mm: 10 Sharpness: 2
Color: Blue Length in mm: 11 Sharpness: 5
Color: Brown Length in mm: 16 Sharpness: 1
Color: Black Length in mm: 23 Sharpness: 2
Color: Orange Length in mm: 29 Sharpness: 3
Color: Purple Length in mm: 17 Sharpness: 4
Which crayon you like to see? (1-8) type [end] to terminate 1
That crayon is Color: Red Length in mm: 16 Sharpness: 1
Color: Red Length in mm: 16 Sharpness: 1
Color: Yellow Length in mm: 17 Sharpness: 4
Color: Green Length in mm: 10 Sharpness: 2
Color: Blue Length in mm: 11 Sharpness: 5
Color: Brown Length in mm: 16 Sharpness: 1
Color: Black Length in mm: 23 Sharpness: 2
Color: Orange Length in mm: 29 Sharpness: 3
Color: Purple Length in mm: 17 Sharpness: 4
Which crayon you like to see? (1-8) type [end] to terminate 2
That crayon is Color: Yellow Length in mm: 17 Sharpness: 4
Color: Red Length in mm: 16 Sharpness: 1
Color: Yellow Length in mm: 17 Sharpness: 4
Color: Green Length in mm: 10 Sharpness: 2
Color: Blue Length in mm: 11 Sharpness: 5
Color: Brown Length in mm: 16 Sharpness: 1
Color: Black Length in mm: 23 Sharpness: 2
Color: Orange Length in mm: 29 Sharpness: 3
Color: Purple Length in mm: 17 Sharpness: 4
Which crayon you like to see? (1-8) type [end] to terminate end
BUILD SUCCESSFUL (total time: 6 seconds)
New Code:
import java.util.Scanner;
import java.util.Random;
public class Crayon {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
Random rand = new Random();
String choice;
choice = "";
String[]crayon = {"Color: Red \t\tLength in mm: 16 \tSharpness: 1",
"Color: Yellow \t\tLength in mm: 17 \tSharpness: 4",
"Color: Green \t\tLength in mm: 10 \tSharpness: 2",
"Color: Blue \t\tLength in mm: 11 \tSharpness: 5",
"Color: Brown \t\tLength in mm: 16 \tSharpness: 1",
"Color: Black \t\tLength in mm: 23 \tSharpness: 2",
"Color: Orange \t\tLength in mm: 29 \tSharpness: 3",
"Color: Purple \t\tLength in mm: 17 \tSharpness: 4",};
while(!choice.equals("end"))
{
for(int a=0; a<crayon.length; a++)
{
System.out.println(crayon[a]);
}
System.out.print("Which crayon you like to see? (1-8) type [end] to terminate ");
choice = scan.nextLine();
//If string is not "end" then convert string to int
if(!choice.equals("end"))
{
System.out.println("That crayon is " + crayon[Integer.parseInt(choice) - 1]);
}
}
}
}