Re: 10114 - Loansome Car Buyer
Posted: Mon Nov 16, 2015 11:04 am
HI,
can anyone please tell me why is my java code showing compilation error while it is working on java online editors?
can anyone please tell me why is my java code showing compilation error while it is working on java online editors?
Code: Select all
import java.io.*;
import java.util.*;
public class HelloWorld{
public static void main(String []args){
Scanner in = new Scanner(System.in);
//PrintWriter out = new PrintWriter(System.out);
while(true)
{
int year = in.nextInt();
if(year < 0)
break;
float dPay1 = in.nextFloat();
float loan = in.nextFloat();
int nDep = in.nextInt();
int[] years = new int[nDep];
float[] values = new float[nDep];
float finalVal = dPay1 + loan;
float installment = loan / year;
for(int i = 0; i < nDep; i++ )
{
int temp1 = in.nextInt();
years[i] = temp1;
float temp2 = in.nextFloat();
values[i] = temp2;
}
float cVal = finalVal - (finalVal*values[0]);
float remLoan = loan;
int currentMonth = 1;
float prevValue = values[0];
//System.out.println(""+cVal+" "+remLoan);
int i = 1;
while(true)
{
if(cVal > remLoan)
break;
if(i < values.length && currentMonth == years[i])
{
prevValue = values[i];
i++;
}
cVal = cVal - (cVal*prevValue);
remLoan -= installment;
//System.out.println(""+cVal+" "+remLoan);
currentMonth++;
}
if((currentMonth-1) != 1)
{
System.out.println(""+(currentMonth-1)+" months");
}
else
System.out.println("1"+" month");
}
}
}