I'm asking you a question about the Java beginner's blank Why isn't there an answer?

Asked 2 years ago, Updated 2 years ago, 23 views

public class Main{
    public static void main(String[ ] args) throws Exception{
        System.out.println( tri(1,3) );
    }

    public static String tri(int x, int y){
    return x*y/2;
    }
}

So, the output should be the code The blanks in question are in the 6th and 7th lines

public < > < > tri(< >x, int y){ < > x*y/2; } In , the < > parts were blank.

The error code that came out when I executed is

Type mismatch: cannot convert from int to String

That's it. What's the answer? What is the problem with my code?

java

2022-09-20 10:40

1 Answers

I changed the string to int, so it was solved right away!


2022-09-20 10:40

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.