Welcome to Dream.In.Code
Become a Java Expert!

Join 149,477 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,794 people online right now. Registration is fast and FREE... Join Now!




methods

 
Reply to this topicStart new topic

methods, working with methods that require single arguments ,multifple agurment

snugglesmocha
15 May, 2007 - 03:36 PM
Post #1

New D.I.C Head
*

Joined: 14 Apr, 2007
Posts: 28


My Contributions
This is the assigment that I have-- Create a class named Numbers whose main() method holds two integer variables. Assign values to the variables. Create two additional methods, sum and difference that compute the sum and differences between the two values of the two variables.

Here is what I have--but it isn't working.
public class Numbers
{
public static void main(String[] args)
{
int twoDigits = 88;
int oneDigit = 7;

sumOfDigits();

System.out.println("This is my numbers program");
}
{
public static void sumOfDigits()

System.out.println("88 + 7");
System.out.println(sumOfDigits);
}
}

I think that I have really messed this up. Only did the sum so far cause one I get the idea of doing this I figure that I can also do the difference.

User is offlineProfile CardPM
+Quote Post

Mila
RE: Methods
15 May, 2007 - 03:58 PM
Post #2

D.I.C Head
Group Icon

Joined: 28 Oct, 2006
Posts: 94


Dream Kudos: 25
My Contributions
Please remember to surround your code with [ code ] tags.

Your problem lies in the sumOfDigits method: you tell it System.out.println(sumOfDigits);, but you have never declared the sumOfDigits variable.

You might want to consider having the sumOfDigits method actually take in two variables, such as:
CODE
public static int sumOfDigits(int a, int b)
{
return a + b;
}


This physically returns the sum of the inputted digits, so in your main method you could actually use a declaration such as System.out.println(sumOfDigits(twoDigits, oneDigit));.

This post has been edited by Mila: 15 May, 2007 - 03:59 PM
User is offlineProfile CardPM
+Quote Post

snugglesmocha
RE: Methods
19 May, 2007 - 05:38 AM
Post #3

New D.I.C Head
*

Joined: 14 Apr, 2007
Posts: 28


My Contributions
QUOTE(Mila @ 15 May, 2007 - 04:58 PM) *

Please remember to surround your code with [ code ] tags.

Your problem lies in the sumOfDigits method: you tell it System.out.println(sumOfDigits);, but you have never declared the sumOfDigits variable.

You might want to consider having the sumOfDigits method actually take in two variables, such as:
CODE
public static int sumOfDigits(int a, int b)
{
return a + b;
}


This physically returns the sum of the inputted digits, so in your main method you could actually use a declaration such as System.out.println(sumOfDigits(twoDigits, oneDigit));.


THANK YOU!!!!
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/7/09 03:02PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month