尝试运行下面的程序,但使用切换方法时出错
import java.util.Scanner;
/ ** * * @author kern公共类贷款{
public static void main(String[] args) {
扫描仪输入=新扫描仪(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);{
}
}
2 回答
java 7支持
String
作为案例值See
你需要像它一样使用它
Per Jigar Joshi链接你现在可以做一些字符串:
Using Strings in switch Statements
在Java SE 7及更高版本中,您可以在switch语句的表达式中使用String对象 . 以下代码示例StringSwitchDemo根据名为month的String的值显示月份的数量:
}