Java, a return method which I cannot understand
public String getCar(int marvel){
}
I cannot understand how to correctly write the return method. I am pretty much new at Java and tried searching for it on google everywhere, but couldn't find an example like that. I cannot return marvel, because it has to be from type String. Well yea, what else could I possibly return in this case or should I convert marvel into String? Thanks in advance!
java string get int return
add a comment |
public String getCar(int marvel){
}
I cannot understand how to correctly write the return method. I am pretty much new at Java and tried searching for it on google everywhere, but couldn't find an example like that. I cannot return marvel, because it has to be from type String. Well yea, what else could I possibly return in this case or should I convert marvel into String? Thanks in advance!
java string get int return
6
We can't know what the method is supposed to do. All we know is that it must return a String. A valid (technically) implementation would bereturn "hello";. Is it the right string to return? We don't know, since you haven't said what the method should do. The method seems to indicate that you need to return a car, and that the car to return depends on the marvel passed as argument. But we have no idea of what a marvel is or how and where to find its car.
– JB Nizet
Nov 24 '18 at 10:08
Well before that I have public String getCar()(NOTE: without int marvel in the brackets) in another class which returns car from type String. Now I have to write the same method with (int marvel) in the brackets in another class. So yea I am not sure what is supposed to happen
– Kirimidko Tuhlev
Nov 24 '18 at 12:18
add a comment |
public String getCar(int marvel){
}
I cannot understand how to correctly write the return method. I am pretty much new at Java and tried searching for it on google everywhere, but couldn't find an example like that. I cannot return marvel, because it has to be from type String. Well yea, what else could I possibly return in this case or should I convert marvel into String? Thanks in advance!
java string get int return
public String getCar(int marvel){
}
I cannot understand how to correctly write the return method. I am pretty much new at Java and tried searching for it on google everywhere, but couldn't find an example like that. I cannot return marvel, because it has to be from type String. Well yea, what else could I possibly return in this case or should I convert marvel into String? Thanks in advance!
java string get int return
java string get int return
edited Nov 24 '18 at 10:07
JB Nizet
542k588821009
542k588821009
asked Nov 24 '18 at 10:06
Kirimidko TuhlevKirimidko Tuhlev
142
142
6
We can't know what the method is supposed to do. All we know is that it must return a String. A valid (technically) implementation would bereturn "hello";. Is it the right string to return? We don't know, since you haven't said what the method should do. The method seems to indicate that you need to return a car, and that the car to return depends on the marvel passed as argument. But we have no idea of what a marvel is or how and where to find its car.
– JB Nizet
Nov 24 '18 at 10:08
Well before that I have public String getCar()(NOTE: without int marvel in the brackets) in another class which returns car from type String. Now I have to write the same method with (int marvel) in the brackets in another class. So yea I am not sure what is supposed to happen
– Kirimidko Tuhlev
Nov 24 '18 at 12:18
add a comment |
6
We can't know what the method is supposed to do. All we know is that it must return a String. A valid (technically) implementation would bereturn "hello";. Is it the right string to return? We don't know, since you haven't said what the method should do. The method seems to indicate that you need to return a car, and that the car to return depends on the marvel passed as argument. But we have no idea of what a marvel is or how and where to find its car.
– JB Nizet
Nov 24 '18 at 10:08
Well before that I have public String getCar()(NOTE: without int marvel in the brackets) in another class which returns car from type String. Now I have to write the same method with (int marvel) in the brackets in another class. So yea I am not sure what is supposed to happen
– Kirimidko Tuhlev
Nov 24 '18 at 12:18
6
6
We can't know what the method is supposed to do. All we know is that it must return a String. A valid (technically) implementation would be
return "hello";. Is it the right string to return? We don't know, since you haven't said what the method should do. The method seems to indicate that you need to return a car, and that the car to return depends on the marvel passed as argument. But we have no idea of what a marvel is or how and where to find its car.– JB Nizet
Nov 24 '18 at 10:08
We can't know what the method is supposed to do. All we know is that it must return a String. A valid (technically) implementation would be
return "hello";. Is it the right string to return? We don't know, since you haven't said what the method should do. The method seems to indicate that you need to return a car, and that the car to return depends on the marvel passed as argument. But we have no idea of what a marvel is or how and where to find its car.– JB Nizet
Nov 24 '18 at 10:08
Well before that I have public String getCar()(NOTE: without int marvel in the brackets) in another class which returns car from type String. Now I have to write the same method with (int marvel) in the brackets in another class. So yea I am not sure what is supposed to happen
– Kirimidko Tuhlev
Nov 24 '18 at 12:18
Well before that I have public String getCar()(NOTE: without int marvel in the brackets) in another class which returns car from type String. Now I have to write the same method with (int marvel) in the brackets in another class. So yea I am not sure what is supposed to happen
– Kirimidko Tuhlev
Nov 24 '18 at 12:18
add a comment |
1 Answer
1
active
oldest
votes
You can't return a int value here because the method's return type is String. So you can either return the String value of the int marvel like here,
public String getCar(int marvel) {
return String.valueOf(marvel);
}
Or change your method's return type to int and then return then int value like here,
public int getCar(int marvel) {
return marvel;
}
Thank you! I solved my problem with the first code! Thanks a lot for your time.
– Kirimidko Tuhlev
Nov 24 '18 at 12:04
@KirimidkoTuhlev You're welcome.
– Sand
Nov 24 '18 at 13:59
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53457080%2fjava-a-return-method-which-i-cannot-understand%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can't return a int value here because the method's return type is String. So you can either return the String value of the int marvel like here,
public String getCar(int marvel) {
return String.valueOf(marvel);
}
Or change your method's return type to int and then return then int value like here,
public int getCar(int marvel) {
return marvel;
}
Thank you! I solved my problem with the first code! Thanks a lot for your time.
– Kirimidko Tuhlev
Nov 24 '18 at 12:04
@KirimidkoTuhlev You're welcome.
– Sand
Nov 24 '18 at 13:59
add a comment |
You can't return a int value here because the method's return type is String. So you can either return the String value of the int marvel like here,
public String getCar(int marvel) {
return String.valueOf(marvel);
}
Or change your method's return type to int and then return then int value like here,
public int getCar(int marvel) {
return marvel;
}
Thank you! I solved my problem with the first code! Thanks a lot for your time.
– Kirimidko Tuhlev
Nov 24 '18 at 12:04
@KirimidkoTuhlev You're welcome.
– Sand
Nov 24 '18 at 13:59
add a comment |
You can't return a int value here because the method's return type is String. So you can either return the String value of the int marvel like here,
public String getCar(int marvel) {
return String.valueOf(marvel);
}
Or change your method's return type to int and then return then int value like here,
public int getCar(int marvel) {
return marvel;
}
You can't return a int value here because the method's return type is String. So you can either return the String value of the int marvel like here,
public String getCar(int marvel) {
return String.valueOf(marvel);
}
Or change your method's return type to int and then return then int value like here,
public int getCar(int marvel) {
return marvel;
}
answered Nov 24 '18 at 10:08
SandSand
1,7212721
1,7212721
Thank you! I solved my problem with the first code! Thanks a lot for your time.
– Kirimidko Tuhlev
Nov 24 '18 at 12:04
@KirimidkoTuhlev You're welcome.
– Sand
Nov 24 '18 at 13:59
add a comment |
Thank you! I solved my problem with the first code! Thanks a lot for your time.
– Kirimidko Tuhlev
Nov 24 '18 at 12:04
@KirimidkoTuhlev You're welcome.
– Sand
Nov 24 '18 at 13:59
Thank you! I solved my problem with the first code! Thanks a lot for your time.
– Kirimidko Tuhlev
Nov 24 '18 at 12:04
Thank you! I solved my problem with the first code! Thanks a lot for your time.
– Kirimidko Tuhlev
Nov 24 '18 at 12:04
@KirimidkoTuhlev You're welcome.
– Sand
Nov 24 '18 at 13:59
@KirimidkoTuhlev You're welcome.
– Sand
Nov 24 '18 at 13:59
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53457080%2fjava-a-return-method-which-i-cannot-understand%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
6
We can't know what the method is supposed to do. All we know is that it must return a String. A valid (technically) implementation would be
return "hello";. Is it the right string to return? We don't know, since you haven't said what the method should do. The method seems to indicate that you need to return a car, and that the car to return depends on the marvel passed as argument. But we have no idea of what a marvel is or how and where to find its car.– JB Nizet
Nov 24 '18 at 10:08
Well before that I have public String getCar()(NOTE: without int marvel in the brackets) in another class which returns car from type String. Now I have to write the same method with (int marvel) in the brackets in another class. So yea I am not sure what is supposed to happen
– Kirimidko Tuhlev
Nov 24 '18 at 12:18