Skip to content

Tag: return

JAVA Do/while loop not returning the value

I’m new at stackoverflow and coding. I’m trying to make a method for validating the user input. The user is only allowed to answer, add, show or exit. But I keep getting stuck in the first while loop. I tried to change it to !userChoice.equals.. but it is not working. What am I doing wrong. Answer Your posted code has

Returning a value from one method to another to be used in the output

I can’t figure out how to return the value of finalCost to the main method and have it printed. Specifically, I can’t find how to use the returned value in the “println” line. Answer You call calcMonthlyCharge(downloadLimit),but don’t store the returnvalue. When you call System.out.println(“Plan monthly cost: ” + calcMonthlyCharge(finalCost) ); It is unknown what finalcost is, this is a

simple java program returning incorrect value

Hello I am brushing up on Java practice. I have this very simple program: There are two int values, along with a boolean variable. i) The program will return true if one of these values is negative and one is positive. ii) However, if the boolean variable is true, the program can only return true if both int values are

Two sum return statement returns nothing

I’m trying to attempt a problem where I must add two elements in an array to equal a target integer value. I think my code is correct and will return the desired target however the return statement is not returning any value. why is this and how can I fix it? Thanks Answer break is wrongly used. Also, you have

ANTLR4 Return values from a function

Im making a programming language as a project at my University and I’ve run into a problem with adding a return statement in functions. This is my grammar: And here is the custom visitor To help with transferring data I have made classes to carry values and function data. The problem I have atm is when I make a function

Why is function not returning array in Java?

I’m making a small script to calculate the Fibonacci sequence by having an array to give how many digits i want, I just can’t figure out why my fib function is saying that there is no array being returned. Code: Answer It’s a matter of scopes. Your only return statements is within the for loop, but if your for loop