有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

带3个数字的java打印3个不同的大小写

int a、b、c

Scanner scan = new Scanner(System.in);
System.out.println("Inserire a");
a = scan.nextInt();
System.out.println("Inserire b");
b = scan.nextInt();
System.out.println("Inserire c");
c = scan.nextInt();

if (a == b && a == c){
    System.out.println("All the same");
}

if (((a==b) && b!=c) || ((a==c) && (b!=c)) || ((b == c) && (a!= c)));
{
    System.out.println("Two the same and one different ");
}
else 
    {
    System.out.print(" All different");
    }
else if (( a != b)  && (b != c) && (a != c));
{
            System.out.println("Tutti diversi");
}

扫描。close(); }

我得到了else的错误,程序读取了所有3种不同的情况 然后打印出3张照片


共 (2) 个答案

  1. # 1 楼答案

    你必须这样做,因为在同一块的else后面加上else if会给你带来麻烦。如果这不是你想要的行为,请提供更多信息,我会尽力帮助:)

    int a, b, c;
    
    Scanner scan = new Scanner(System.in);
    System.out.println("Inserire a");
    a = scan.nextInt();
    System.out.println("Inserire b");
    b = scan.nextInt();
    System.out.println("Inserire c");
    c = scan.nextInt();
    
    if (a == b && a == c){
         System.out.println("All the same");
    }
    
    else if (((a==b) && b!=c) || ((a==c) && (b!=c)) || ((b == c) && (a!= c)));
    {
        System.out.println("Two the same and one different ");
    }
    else 
    {
        System.out.println("Tutti diversi");
        System.out.print(" All different");
    }
    
  2. # 2 楼答案

    尝试使用else if,而不是第二个if,在所有else if之后粘贴else部分