take a look at the end of the code (the if else section), and please tell me how to fix it | SoloLearn: Learn to code for FREE!

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..."); } } }

5/23/2020 12:55:47 PM

yahel

2 Answers

New Answer

+1

before the if your declaration is not correct i think : var contain = li... i think that var doesn't exist in Java

+1

compare the contain length to 1 contain length greater than one