Could you please explain why this loop doesn't work in case if user types "yes" and why there are errors with variables initialisations.
import java.util.ArrayList;
import java.util.Scanner;
public class Main {
public static void main(String args[]) {
Scanner src;
String amount;
String counterparty;
String dt;
String ct;
System.out.println("Create new transaction:yes/no");
Scanner abc = new Scanner(System.in);
String g = abc.nextLine();
if (g=="yes") {
System.out.println("Amount of transaction:");
src = new Scanner(System.in);
amount = src.nextLine();
System.out.println("Counterparty:");
counterparty = src.nextLine();
System.out.println("Dt:");
dt = src.nextLine();
System.out.println("Ct:");
ct = src.nextLine();
}
else if (g=="no") {
amount="0";
}
System.out.println("Transaction:");
ArrayList <String> Provodka = new ArrayList();
Provodka.add(amount);
Provodka.add(counterparty);
Provodka.add(dt);
Provodka.add(ct);
for (int i = 0; i < Provodka.size(); i++) {
String value = Provodka.get(i);
System.out.println("Element: " + value);
}
}
}