0

take a look at the end of the code (the if else section), and please tell me how to fix it

import java.util.ArrayList; import java.util.List; import java.util.Collections; import java.util.Scanner; public class Program { public static void main(String[] args) { List <String> list = new ArrayList <String> (); //Cars is Stock: list.add ("Mercedes"); list.add ("Ford"); list.add ("Mazda"); list.add ("Fiat"); list.add ("Jeep"); list.add ("Toyota"); list.add ("Nisan"); System.out.println ("Cars avaliable:"); Collections.sort (list); for (String cars : list){ System.out.println (cars); } System.out.println (""); Scanner scan = new Scanner (System.in); String myCar = scan.nextLine(); myCar = myCar.substring (0 , 1).toUpperCase() + myCar.substring (1); var contain = list.contains (myCar); if (contain){ System.out.println (myCar + " is in stock!"); }else if (myCar == int){ //this line System.out.println ("you need to enter a brand - not an Integer"); }else{ System.out.println (myCar + " is not in our stock..."); } } }

23rd May 2020, 12:55 PM
Yahel
Yahel - avatar
2 Antworten
+ 1
before the if your declaration is not correct i think : var contain = li... i think that var doesn't exist in Java
23rd May 2020, 1:05 PM
Honorable Con 🇸🇳
Honorable Con 🇸🇳 - avatar
+ 1
compare the contain length to 1 contain length greater than one
23rd May 2020, 1:09 PM
Honorable Con 🇸🇳
Honorable Con 🇸🇳 - avatar