• Post Reply Bookmark Topic Watch Topic
  • New Topic

methods that do and do not return any value  RSS feed

 
Hans Baba
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi there;
Basically, Im a college student and my teacher wanted me to do following to things, but I have no idea what they mean

What do you understand from followings and what do I need to do?

Write the header for a method named send that has one parameter of type String, and does
not return a value.


Write the header for a method named average that has two parameters, both of type int, and
returns an int value.
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you don't understand what your teacher is asking of you, shouldn't either the teacher or his teaching assistant be ready to answer questions?
 
Hans Baba
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf Dittmer wrote:If you don't understand what your teacher is asking of you, shouldn't either the teacher or his teaching assistant be ready to answer questions?


it is kind of challenge in the class and I got a week to do so cant get any help from him
 
Joanne Neal
Rancher
Posts: 3742
16
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This should tell you all you need to know.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12563
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you know how to write any kind of method?
 
Hans Baba
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
fred rosenberger wrote:Do you know how to write any kind of method?


I will learn it at the end of this week hopefully :fingers crossed: just jumped into Java today and done few small exercises and learnt about methods theoretically. And my this question was the last part of the exercise. ( Am I a real beginner? )

Does my question look really strange? lol
 
Campbell Ritchie
Marshal
Posts: 56536
172
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

Look in the Java Tutorials. Try this section.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12563
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We strongly feel that no question is too small or too strange. But we also don't just hand out answer...we sort of have the belief that a dialog works better. So we ask questions to gauge what you know, to make you think, to get you to try stuff...


So...Try it. Read the link Joanne gave, and try it. Then, post it here. Someone will take a look, and give you comments.
 
Campbell Ritchie
Marshal
Posts: 56536
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
fred rosenberger wrote:. . . Read the link Joanne gave, . . .
Same link which I gave later. I should have read Joanne's post more carefully.
 
Hans Baba
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you guys. I will check your links and hope I can get something, as I am very new this topic.
 
Hans Baba
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys, its me again. After checking your links and making some research on the internet I come up with something like these;

Public void send(strx)
{
system.output.print(x)
}

for the first part of exercise and;

public int average(inta, intb)
{
return(a+b);
}

for the second part.

how do you think about them?

Also this youtube video is very helpful for understanding methods in java for newbies like me :P
https://www.youtube.com/watch?v=yi0vT3M3gCE
 
Charles D. Ward
Ranch Hand
Posts: 99
1
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Memis Baba wrote:



This will not compile.
Line 1: Public is not the same as public (remember Java is case sensitive). You must also specify what type is the parameter you're passing to the method.
Same with line 3. Class names start with an uppercase letter so it's System, not system.
Also the System class doesn't have a member named output, but one named out.
Finally, you are printing x, which doesn't exist. However, you are passing a something (because you didn't specify the type) named strx to the method, and that's what you want to print.


As you can see, these "details" DO matter in Java.
 
Hans Baba
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have written as you said on my notead but dont know why I wrote like this on the post ( but I didnt know it was case senstive anyway, so thanks ) , also that .output too. ( i think im high, lol)

I think im done, thank you all for your responses!
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16059
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Memis Baba wrote:public int average(inta, intb)
{
return(a+b);
}

Besides the syntax errors, this method does not calculate what its name suggests. Instead of calculating the average of a and b, it just adds a and b. So, the implementation is not correct.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!