![]() 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. When this happens, the programmer has to locate the. Change the parameters and the return type of your method, and then call it twice. that violates these rules, a syntax error will result and the program cannot be compiled or executed. 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. ![]() Stephan van Hulst wrote:Welcome to CodeRanch! Otherwise, you could find and select one of the non-breaking spaces (looks like a space, shows code 160 in the message bar) then do a Ctrl-F and replace with. Try 'Edit' > 'Paste Special' in jGRASP and see if a plain text paste will avoid this. ![]() I think using nextLine() would be better. That character is a non-breaking space, so probably OneNote is substituting it for ordinary spaces. 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(). You can use a Scanner and the nextDouble() method. M圜ode. It should only take one parameter: the prompt. Arguments are the actual data values passed to the method’s parameters during invocation. This error is triggered by a method call attempted with the wrong number, type, and/or order of arguments. With this, the way you are calling the method would be correct but the method itself needs to be re-written. Whenever a method invocation doesn’t match the corresponding method signature, the method X in class Y cannot be applied to given types error is raised. 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: 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. 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. To make Java programs machine independent, that is, able to run on many different types of computer platforms, the designers of Java introduced a hypothetical. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |