Note that there are some explanatory texts on larger screens.

plurals
  1. POJava program works but ends early
    primarykey
    data
    text
    <p>I have a program that I am writing that has these directions:</p> <ul> <li>When creating the 10 Taxpayer objects, increment the SSN by 10 and their income by 10,000; </li> <li>starting at 10 and 10,000 respectively.</li> <li>The output should look like</li> <li>Taxpayer SSN: 10 Income: 10000</li> <li>Taxpayer SSN: 20 Income: 20000</li> <li>...</li> <li>Taxpayer SSN: 100 Income: 100000</li> </ul> <p>I have the code written but am getting it to end at 90 instead of 100. What am I doing wrong?</p> <pre><code>public class UseTaxpayer { public static void main(String[] args) { Taxpayer[] tp = new Taxpayer[10]; for (int i=1; i&lt;10; i++) { payer[i] = new Taxpayer(i*10, 10000*i); System.out.println("Taxpayer SSN: " + payer[i].getSS() + " Income: " + tp[i].getIncome()); } } } class Taxpayer { private int socialsecurity, income; Taxpayer(int ss, int income) { socialsecurity = ss; this.income = income; } int getSS() { return socialsecurity; } int getIncome() { return income; } } </code></pre> <p>I have "kludged" a working solution with doing this for the For statement: for (int i = 0; i &lt; 10; i++) { payer[i] = new payer(i * 10 + 10, (10000 * (i + 1))); // calculates the SSN and money based upon directions System.out.println(" Taxpayer SSN: " + payer[i].getSSN() + " Income: " + payer[i].getmoney());</p> <p>If I start the array at 1, I get an off by one error. If I don't add the "+ 10" section of payer(i), I get SSN: 0 Income 10000. </p> <p>This method works but wonder if there is a better way to do this.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload