Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Print contents of an array

807598Jul 13 2006 — edited Jul 13 2006
I am having difficulty printing the contents of an array I designed. I am completely new to Java and I need to print certain things from an array. I have desingned my array to be 4 rows and 3 columns and think that I have assigned values to the array correctly. I am not sure how to make those contents print to a command line screen. Can anyone help. Here is the code I have so far:
import java.text.*;
import java.math.*;



public class MortCalc_Week4_3b

{

            public static void main(String [] args)

            {

                        //Define variables and assign values

                        DecimalFormat twoPlaces = new DecimalFormat("#,###.00");

                        double loanamt = 200000.00; //loan amount of 200k
                        double apr1 = 5.35;  //interest rate of 5.35%
                        double apr2 = 5.5;  //interest rate of 5.5%
                        double apr3 = 5.75; //interest rate of 5.75%
                        double moninterest1 = (apr1 / 12) / 100;  //monthly interest rate
                        double moninterest2 = (apr2 / 12) / 100;  //monthly interest rate
                        double moninterest3 = (apr3 / 12) / 100;  //monthly interest rate
					  double mthlypayment1 = 0;  //monthly payment
					 double mthlypayment2 = 0;  //monthly payment
					 double mthlypayment3 = 0;  //monthly payment
                        int termyrs1 = 7;  //term of 7 years
                        int termyrs2 = 15; //term of 15 years
                        int termyrs3 = 30; //term of 30 years
                        int termmths1 = (termyrs1 * 12);  //term of 84 months
                        int termmths2 = (termyrs2 * 12);  //term of 180 months
                        int termmths3 = (termyrs3 * 12);  //term of 360 months

                        //int[][] myTable = new int[4][3]; \\ constructs the two dimensional array (4 rows, 3 columns)   **********  example from book on arrays
						//myTable[1][3] = 487; \\ assigns the value 487 to row 1, column 3

                        double [][] myTable = new double [4][3];


                        //M = P * ( J / (1 - (1 + J) ^ -N)) *****  Template for formula


                        mthlypayment1 = (loanamt * moninterest1) / (1 - Math.pow(1 + moninterest1, - termmths1));  // formula for calculating a monthly payment
                        mthlypayment2 = (loanamt * moninterest2) / (1 - Math.pow(1 + moninterest2, - termmths2));  // formula for calculating a monthly payment
                        mthlypayment3 = (loanamt * moninterest3) / (1 - Math.pow(1 + moninterest3, - termmths3));  // formula for calculating a monthly payment

                        System.out.println("\nMortgage Calculator\n");  // title display

                        myTable[1][1] = loanamt;
                        myTable[1][2] = apr1;
                        myTable[1][3] = termyrs1;
                        myTable[1][4] = mthlypayment1;
                        myTable[2][1] = loanamt;
                        myTable[2][2] = apr2;
                        myTable[2][3] = termyrs2;
                        myTable[2][4] = mthlypayment2;
                        myTable[3][1] = loanamt;
	   myTable[3][2] = apr3;
	   myTable[3][3] = termyrs3;
                        myTable[3][4] = mthlypayment3;




                        //System.out.println("\nMortgage Calculator\n");  // title display
                       // System.out.println("\nLoan Amount: \t$" + twoPlaces.format(loanamt));  // display the loan amount
                       // System.out.println("\nInterest Rate: \t" + apr1 +"%");  //display the annual percentage rate
                        //System.out.println("\nTerm: \t" + termyrs1 + " years");  //term in years
                       // System.out.println("\nYour monthly payment is: \t$" + twoPlaces.format(mthlypayment1));  //display the monthly payment
                       // System.out.println("\n\n");  // double blank line






            }

}
Can anyone help me???
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 10 2006
Added on Jul 13 2006
2 comments
188 views