My assignment has me inputting two variables using scanner keyboard which are values dealing with currency. I’m using print f but keep error

Viewed 23

My assignment has me inputting two variables using scanner keyboard which are values dealing with currency. I’m using print f but keeps coming up with “ syntax error on token “,”, Expression expected after this token”

class LAB1 {

public static void main(String[] args) {
                
Scanner input= new Scanner(System.in);
     
System.out.println("What is the name of your bank");
String bank = input.next();

System.out.println("What is your balance");
double balance = input.nextDouble();

System.out.println ("New amount put into bank");
double amount = input.nextDouble();

System.out.println("New balance after amount added");
double newbalance = (amount + balance);

 

System.out.print("Your bank " + bank + "has");
System.out.printf("%3.2f",[newbalance] ); 
1 Answers

The printf should be used like this:

System.out.printf("%3.2f",newbalance );
Related