• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

methods that do and do not return any value

 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Rancher
Posts: 3742
16
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This should tell you all you need to know.
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Marshal
Posts: 79178
377
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

Look in the Java Tutorials. Try this section.
 
fred rosenberger
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 99
1
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't destroy the earth! That's where I keep all my stuff! Including this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic