I cant get this to work for some reason. I have an app that reads transactions, when an empty line in entered it needs to print out some stuff.
int transationCount = 0;
while(sc.hasNext())
{
String trans = sc.next();
String mode = trans.substring(0, 1);
Double amount = Double.valueOf(trans.substring(1));
if(mode.equals("C"))
{
c.charge(amount);
ps.println(c.getBalance());
transationCount = transationCount + 1;
}
else if(mode.equals("P"))
{
c.pay(amount);
ps.println(c.getBalance());
transationCount = transationCount + 1;
}
}
ps.println(c.getBalance());
ps.println(transationCount);
I tried
while(sc.hasNext() && !(sc.next().equals("")))
doesnt work. I also tried adding inside the while loop
else if (!(trans.equals("")) {break;}