Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/379.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 类型不匹配:无法从int转换为boolean_Java_Eclipse_Boolean_Type Mismatch - Fatal编程技术网

Java 类型不匹配:无法从int转换为boolean

Java 类型不匹配:无法从int转换为boolean,java,eclipse,boolean,type-mismatch,Java,Eclipse,Boolean,Type Mismatch,在if语句中,在参数中我得到一个错误,说“类型不匹配,无法从int转换为boolean”。请提供解决方案 public static void main(String[] args) { Scanner sathya1 = new Scanner(System.in); System.out.println("Enter the numbers"); int x = (sathya1.nextInt()); int y = (sathya1.nextInt())

if
语句中,在参数中我得到一个错误,说“类型不匹配,无法从int转换为boolean”。请提供解决方案

public static void main(String[] args) {

    Scanner sathya1 = new Scanner(System.in);
    System.out.println("Enter the numbers");
    int x = (sathya1.nextInt());
    int y = (sathya1.nextInt());
    int addition = x+y;
    int subtraction = x-y;
    int multiplication = x*y;
    float division = x/y;       
    if(sathya1.nextInt(addition){
        System.out.println("The number is " +addition);
        elseif(sathya1.nextInt(subtraction)){
            System.out.println("The number is " +subtraction);
            elseif(sathya1.nextInt(multiplication)){
                System.out.println("The number is " +multiplication);
                elseif(sathya.1nextInt(division)){
                    System.out.println("The number is " +division);
                }

            }
        }
    }
}
}这条线

if(sathya1.nextInt(addition){
毫无意义。这就像说“如果12”。其他线路也是如此。此外,在许多其他问题中,您还缺少一个结束语。

您的意思可能是:

import java.util.Scanner;
public class BasicArithmetic
{
    public static void main(String[] args)
    {

    //create a scanner for keyboard input
    Scanner sathya1 = new Scanner(System.in);

    //ask user for the operation to be used
    System.out.print("Please enter the corresponding number to be used \n(1)for Addition,(2)for Subtraction,(3)for Multiplication,(4)for Division:");
    int enteredNumber = sathya1.nextInt();

    //get the two numbers to be used
    System.out.println("Enter the numbers");
    float x = sathya1.nextFloat();
    float y = sathya1.nextFloat();

    //arithmetic operations of the two numbers
    float addition = x+y;
    float subtraction = x-y;
    float multiplication =x*y;
    float division = x/y;

    //if..else statement
    if(enteredNumber==1)
    {
    System.out.println("The sum of the two number is "+addition);
    }
    else if(enteredNumber==2)
    {
    System.out.println("The subtraction of the two number is "+subtraction);
    }
    else if(enteredNumber==3)
    {
    System.out.println("The product of the two number is "+multiplication);
    }
    else if(enteredNumber==4)
    {
    System.out.println("The quotient of the two number is "+division);
    }
    else
    {
     System.out.println("Please enter the correct corresponding number");
    }
    }





}

大写字母被认为是尖叫,因此被认为是粗鲁的。Beyond:if-if-nextInt()将返回一个布尔值(它没有!)。。。您缺少一个结束符)。另外,
elseif
不是Java命令。而
else
块不在前面的
if
块的内部。甚至不清楚代码应该做什么。我是java的noob…无论如何,感谢您的帮助,请告诉我您的问题必须更具体。@user3682031这不是编程学校的超级基础课程。有无数的资源可以解释这些事情!这是一个计算基本算术的程序