Tuesday 22 May 2018

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

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...