What would my return statement be? I tried 'return weight ' and 'return height ' separately, but it asked me for weight and height twice. I took your suggestions and changed my code accordingly. Change the parameters and the return type of your method, and then call it twice. Instead, you probably want its input to be a piece of text to show to the user ( String) and its output to be the type of the thing you asked for ( double). Your method has two floating point numbers as its input, and no ( void) output. Methods have parameters that are used for the method's input, and they have a return type that is used for the output. All you need for starting with Java Programming: introduction to Java Virtual Machine(JVM), variables, types, expressions, flow control structures and so on. Translate the algorithm into a computer program (using Java in this course. Stephan van Hulst wrote:Welcome to CodeRanch! Find or create an algorithm (a recipe) that spells out how to solve the problem. I think using nextLine() would be better. This won't work properly if the user puts a space in their name perhaps entering first and last name. Your promptForUserName() uses the Scanner method next(). When this happens, the programmer has to locate the. You can use a Scanner and the nextDouble() method. that violates these rules, a syntax error will result and the program cannot be compiled or executed. It should only take one parameter: the prompt. With this, the way you are calling the method would be correct but the method itself needs to be re-written. Another problem: When I try to run the driver program, I get the following error: Exception in thread 'main' at Exercise.toString(Exercise.java:68) at (String.java:2854) at java.io.PrintStream.println(PrintStream.java:821) at pg5a.main(pg5a. Public static double promptDouble( String prompt )because you can end up with multiple methods each designed to return a different type. I have created similar methods on many projects and they are usually of the form: sults in a compilation error containing a message such as cannot find symbol. Where you call it you are expecting a return value of double but you've declared the method to return void. When you're calling it you are passing in one String argument. Public static String promptUserForName() Your "promptUserFor()" method takes two parameters, both double. This error implies that the Java compiler is unable to resolve a value assigned to a variable or returned by a method, because its type is incompatible with the one declared on the variable or method in question. I realize that what the main method is calling for is different than what is in 'promptUserFor', but I don't know how to write 'promptUserFor' in a way that will fix this method.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |