它没有显示任何错误,但编译器只是继续加载或显示 [object object]

It didn't show any error, but the compiler just keep loading or show [object object]

我想做一个长度转换器,可以将英尺转换为其他单位,如微米、毫米…… 当我尝试 运行 它时,它一直在加载,有时会显示 [Object Object]....(我不知道 [Object Object] 是不是错误

import java.util.Scanner;
public class Converter{


public static void calculateMicro(double number){
double answer =   304796.293632 * number;
System.out.print ("The answer is: " + answer );
}
public static void calculateMilli(double number){
double answer =   304.8 * number;
System.out.print ("The answer is: " + answer );
}
public static void calculateCenti(double number){
double answer =   30.48 * number;
System.out.print ("The answer is: " + answer );
}
public static void calculateMeter(double number){
double answer =   0.3048 * number;
System.out.print ("The answer is: " + answer );
}
public static void calculateKilo(double number){
double answer =   0.0003048 * number;
System.out.print ("The answer is: " + answer );
}
public static void main (String args[]) {
Scanner sc = new Scanner(System.in);

double number = sc.nextDouble();
int x = 1;
int option = sc.nextInt();

while(x==1){
   System.out.println("1.micrometer  2.millimeter  3.centimeter  4.meter  5. kilometer");
  if(option==1){
    calculateMicro(number);
  }
  else if(option==2){
    calculateMilli(number);
  }
  else if(option==3){
    calculateCenti(number);
  }
  else if(option==4){
    calculateMeter(number);
  }
  else if(option==5){
    calculateKilo(number);
  }
}

使你进入无限循环
int x = 1;
while(x==1){
//code...
}

你应该

  1. 向用户询问选项
  2. 询问用户是否想再试一次(将 x 更改为 0 或 1 )
while(x==1){
   System.out.println("1.micrometer  2.millimeter  3.centimeter  4.meter  5. kilometer");
x = sc.nextInt();
  //code to convert....
 System.out.println("do you wanna try again 1 for Yes or 0 for No");
x = sc.nextInt();
}

而且我认为如果你有多项选择,你应该尝试 Switch not if else if else....

switch(option) {
  case 1:
        calculateMicro(number);
    break;
  case 2:
        calculateMilli(number);
    break;
  //cases
//  default:
}