java求大神
答案:2 悬赏:0
解决时间 2021-02-14 21:04
- 提问者网友:泪姬迷茫
- 2021-02-14 17:13
java求大神
最佳答案
- 二级知识专家网友:魅世女王
- 2021-02-14 17:56
package com.simple.standard;
import java.util.Scanner;
public class IntSvcAdvisor {
private static Scanner sc;
private static final String SET_A = "A";
private static final String SET_B = "B";
private static final String SET_C = "C";
public static void main(String[] args) {
sc = new Scanner(System.in);
// User set
String set = "";
// Duration
int hours = 0;
// Choose set.
System.out.print("Choose your set(A, B or C): ");
// Get user choice from keyboard.
set = sc.next();
// input hours
System.out.println("Input your hours: ");
// Get user choice from keyboard.
hours = sc.nextInt();
// Process according to user choice.
double acturalCost = calCostOfMonth(set, hours);
System.out.println(acturalCost);
outputAnalysisResult(set, hours, acturalCost);
}
private static double calCostOfMonth(String setName, int hours) {
double cost = 0;
switch (setName.toUpperCase()) {
// 套餐A:
case "A":
// 对于每月9.95美元,提供10小时访问。更多的时间是2.00美元每小时。
cost = hours > 10 ? (hours - 10) * 2 + 9.95 : 9.95;
break;
// 套餐B:
case "B":
// 对于13.95美元每月提供20小时访问。更多的时间是1.00美元每小时。
cost = hours > 20 ? (hours - 20) * 1 + 13.95 : 13.95;
break;
// 套餐C:
case "C":
// 对于每月19.95美元的无限接入提供。
cost = 19.95;
break;
default:
break;
}
return cost;
}
private static void outputAnalysisResult(String setName, int hours,
double actualCost) {
double saveForB = 0;
double saveForC = 0;
if (actualCost > 0 || SET_C.equals(setName.toUpperCase())) {
if (setName.toUpperCase().equals(SET_A)) {
saveForB = actualCost - calCostOfMonth(SET_B, hours);
if (saveForB > 0) {
System.out.println("如果购买套餐B, 将有可能节省: $" + saveForB);
}
saveForC = actualCost - calCostOfMonth(SET_C, hours);
if (saveForB > 0) {
System.out.println("如果购买套餐C, 将有可能节省: $" + saveForC);
}
} else if (setName.toUpperCase().equals(SET_B)) {
saveForC = actualCost - calCostOfMonth(SET_C, hours);
if (saveForB > 0) {
System.out.println("如果购买套餐C, 将有可能节省: $" + saveForC);
}
}
}
}
}
import java.util.Scanner;
public class IntSvcAdvisor {
private static Scanner sc;
private static final String SET_A = "A";
private static final String SET_B = "B";
private static final String SET_C = "C";
public static void main(String[] args) {
sc = new Scanner(System.in);
// User set
String set = "";
// Duration
int hours = 0;
// Choose set.
System.out.print("Choose your set(A, B or C): ");
// Get user choice from keyboard.
set = sc.next();
// input hours
System.out.println("Input your hours: ");
// Get user choice from keyboard.
hours = sc.nextInt();
// Process according to user choice.
double acturalCost = calCostOfMonth(set, hours);
System.out.println(acturalCost);
outputAnalysisResult(set, hours, acturalCost);
}
private static double calCostOfMonth(String setName, int hours) {
double cost = 0;
switch (setName.toUpperCase()) {
// 套餐A:
case "A":
// 对于每月9.95美元,提供10小时访问。更多的时间是2.00美元每小时。
cost = hours > 10 ? (hours - 10) * 2 + 9.95 : 9.95;
break;
// 套餐B:
case "B":
// 对于13.95美元每月提供20小时访问。更多的时间是1.00美元每小时。
cost = hours > 20 ? (hours - 20) * 1 + 13.95 : 13.95;
break;
// 套餐C:
case "C":
// 对于每月19.95美元的无限接入提供。
cost = 19.95;
break;
default:
break;
}
return cost;
}
private static void outputAnalysisResult(String setName, int hours,
double actualCost) {
double saveForB = 0;
double saveForC = 0;
if (actualCost > 0 || SET_C.equals(setName.toUpperCase())) {
if (setName.toUpperCase().equals(SET_A)) {
saveForB = actualCost - calCostOfMonth(SET_B, hours);
if (saveForB > 0) {
System.out.println("如果购买套餐B, 将有可能节省: $" + saveForB);
}
saveForC = actualCost - calCostOfMonth(SET_C, hours);
if (saveForB > 0) {
System.out.println("如果购买套餐C, 将有可能节省: $" + saveForC);
}
} else if (setName.toUpperCase().equals(SET_B)) {
saveForC = actualCost - calCostOfMonth(SET_C, hours);
if (saveForB > 0) {
System.out.println("如果购买套餐C, 将有可能节省: $" + saveForC);
}
}
}
}
}
全部回答
- 1楼网友:請叫我丶偏執狂
- 2021-02-14 18:49
<p>先说一下这个代码是我找的,可以参考一下 </p>
public static void main(string[] args) {
// todo auto-generated method stub
biginteger one = biginteger.one;
biginteger ten = biginteger.ten;
biginteger a = one;
biginteger b = one.add(one.add(one));
biginteger c = b;
biginteger sum = biginteger.one;
for(int i=0;i<300;i++){//需要精确到100位,所以循环次数要适当
sum = a;
for(int j=0;j<101;j++){//需要把小数点向右移动101位
sum = ten.multiply(sum);
}
biginteger res = sum.divide(c);
c = a.add(b);
a = b;
b = c;
if(res.tostring().length()==101){//要判断到101位,需要四舍五入
system.out.println(res);
}
}
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯
• 手机登qq时,显示手机磁盘不足,清理后重新登 |
• 刺客的套装怎么选啊? |