主题:java小问题
类型 PrintStream 中的方法 printf(String, Object[])对于参数(String,
double)不适用
下面这段程序怎么改一下啊?各位大虾,帮帮忙,我是刚学.
import java.util.Scanner
public class AccountTest
{
public static void main(String args[])
{
Account account1 = new Account(50.00);
Account account2 = new Account(-7.53);
System.out.printf( "account balance:$%.2f\n",
account1.getBalance() );
System.out.printf( "account balance:$%.2f\n\n",
account2.getBalance() );
Scanner input = new Scanner(System.in);
double depositAmount;
System.out.print("Enter deposit amount for account1:");
depositAmount = input.nextDouble();
System.out.printf("\nadding %.2f to account1 balance\n\n ", depositAmount);
account1.credit(depositAmount);
System.out.printf( "account balance:$%.2f\n",
account1.getBalance() );
System.out.printf( "account balance:$%.2f\n\n",
account2.getBalance() );
System.out.print("Enter deposit amount for account2:");
depositAmount = input.nextDouble();
System.out.printf("\nadding %.2f to account1 balance\n\n ", depositAmount);
account2.credit(depositAmount);
System.out.printf( "account balance:$%.2f\n",
account1.getBalance() );
System.out.printf( "account balance:$%.2f\n",
account2.getBalance() );
}
}//end class AccountTest
double)不适用
下面这段程序怎么改一下啊?各位大虾,帮帮忙,我是刚学.
import java.util.Scanner
public class AccountTest
{
public static void main(String args[])
{
Account account1 = new Account(50.00);
Account account2 = new Account(-7.53);
System.out.printf( "account balance:$%.2f\n",
account1.getBalance() );
System.out.printf( "account balance:$%.2f\n\n",
account2.getBalance() );
Scanner input = new Scanner(System.in);
double depositAmount;
System.out.print("Enter deposit amount for account1:");
depositAmount = input.nextDouble();
System.out.printf("\nadding %.2f to account1 balance\n\n ", depositAmount);
account1.credit(depositAmount);
System.out.printf( "account balance:$%.2f\n",
account1.getBalance() );
System.out.printf( "account balance:$%.2f\n\n",
account2.getBalance() );
System.out.print("Enter deposit amount for account2:");
depositAmount = input.nextDouble();
System.out.printf("\nadding %.2f to account1 balance\n\n ", depositAmount);
account2.credit(depositAmount);
System.out.printf( "account balance:$%.2f\n",
account1.getBalance() );
System.out.printf( "account balance:$%.2f\n",
account2.getBalance() );
}
}//end class AccountTest