String car;
if (type == 'E')
{fee = rate*50;
car = "Economy";}
else if (type == 'M')
{fee = rate*70;
car = "Midsize";}
else if (type == 'F')
{fee = rate*100;
car = "Fullsize";}
System.out.println("Car type is " + car);
Run Code Online (Sandbox Code Playgroud)
这是我遇到问题的程序的一部分.我得到'本地变量车可能尚未初始化'.我应该怎么做才能让'汽车'初始化?
public class Interest {
public static void main(String[] args) {
int n; // number of years
double rate; // annual rate
for (int r = 5; r<=10; r++ ) {
System.out.println("\nInterest rate is " + r + "%");
System.out.println("**********************");
System.out.println("Year\tAmount on deposit");
for (n=1; n<=10; n++) {
int p = 1000; // original amount
rate = r / 100;
double a = p * (Math.pow(1 + rate, n)); // amount on deposit at the end of year
System.out.printf("\n%d\t%.2f", n, a); …Run Code Online (Sandbox Code Playgroud) 我有一个家庭作业,我应该写几个方法(例如,提示客户的汽车类型并返回有效的汽车类型的方法)然后我的程序应显示汽车类型,汽车租用的天数,额外这是老师要我写的第一种方法,
public static String promptForCarType(){
Scanner input = new Scanner(System.in);
char type;
System.out.println("(E) Economy - 50 TL");
System.out.println("(M) Midsize - 70 TL");
System.out.println("(F) Fullsize - 100 TL");
do{
System.out.println("Enter the car type (E/M/F) : ");
type = input.next().charAt(0);
type = Character.toUpperCase(type);
} while (type != 'E' && type != 'M' && type != 'F' ); //I tried to define condition with "||" operator,didn't work.
switch(type) {
case 'E' : ;return "Economy";
case 'M' : return "Midsize";
case 'F' : return …Run Code Online (Sandbox Code Playgroud)