我試圖將for循環的迭代總和加在一起。這是我迄今爲止所擁有的。在Java中一起添加迭代
import java.util.Scanner;
public class Pennies
{
public static void main (String [] args)
{
double amount; //To hold the amount of pennies per day
double days; //To hold the days user saved.
double total;
System.out.println("I will display a table of salary if you're paid every day in pennies and it doubles every day.");
Scanner keyboard = new Scanner(System.in);
System.out.print("How many days do you wish to save for?");
days = keyboard.nextDouble();
//Display the table
System.out.print("Day \t Salary \n");
for (amount = 1; amount <= days; amount++)
{
total = amount * .01 * amount;
System.out.println(amount + "\t \t $" + total);
}
}
}
任何幫助將不勝感激!
究竟是什麼問題? –
期望的輸出是什麼以及要改進的電流輸出是多少? – Zabuza
期望的輸出將是一張表格,顯示每天加倍的薪水,然後在底部顯示所有迭代的總和。 –