Wednesday 9 March 2016

java - Now am getting incompatible error when using the if else statements



trying to run the program below but am getting an error when using the switch method




import java.util.Scanner;



/**
*
* @author kern
public class loans {



public static void main(String[] args) {



Scanner input = new Scanner(System.in);



    //variabled decleared
double rate, payment,principal,interest,n;
int length;
String period;

//input
System.out.print("Enter the amount of money borrowed: $");

principal = input.nextDouble();
System.out.print("Enter the annual interest rate: ");
interest = input.nextDouble();
System.out.print("Enter the payment period :");
period = input.next();
System.out.print("Enter Loan Length:");
length = input.nextInt();
//process

rate=interest/100;

payment= principal*(rate*Math.pow((1+rate),n)/ Math.pow ((1+rate),n));

if (period==annually) {
n=1*length;
System.out.prtintf(Your monthly sum is %f:,payment);{

if (period==semiannuall) {
n=2*length;
System.out.prtintf(Your monthly sum is %f:,payment);{


if (period== quarterly) {
n=4*length;
System.out.prtintf(Your quarterly sum is %f:,payment);{

if (period==monthly) {
n=12*length;
System.out.prtintf(Your monthly sum is %f:,payment);{





}


}


Answer



String as case value are supported from java 7



See






You need to use it like



if("annually".equals(period)){
}

No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...