Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-07-2008, 10:15 AM
Member
 
Join Date: Nov 2007
Posts: 20
Phobos0001 is on a distinguished road
need help with my 1st multi-method program
Greetings everyone,

i'm currently studying java as one of my subjects at TAFE, we are starting on learning to use 2 or more methods in a single program

i have started working on an extremely simple one and i got it all working as a single method, but when i split it up and put a method call, i got a compile error "'class' or 'interface' expected" im guessing ive put my braces in the wrong spot or something and im hoping someone can help me figure out where i went wrong
Code:
import javax.swing.*; public class q5 { public static void main (String[] args) { String enter; double number =0; enter = JOptionPane.showInputDialog("Enter a number:"); number = Double.parseDouble(enter); findAbs (number); System.exit(0); } } { public static void findAbs (double number) { if ( number <0 ) number = -number; JOptionPane.showMessageDialog(null, "the absoloute value is:" + number, "Exerscise 6.1", JOptionPane.INFORMATION_MESSAGE); } }
any help will be greatly apriciated. once i can get one program working it will be quite easy to modify it and study where the braces are to be placed in more complex code with 3 or more methods. thanks again for any help
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 02-07-2008, 12:12 PM
Member
 
Join Date: Feb 2008
Posts: 2
$_ACE_$ is on a distinguished road
remove the closing and opening braces before the "public static void findAbs" method. should work fine..
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 02-07-2008, 01:26 PM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,402
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
You have use additional open brace. Seems findAds method is outside of the class.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 02-07-2008, 03:43 PM
Member
 
Join Date: Nov 2007
Posts: 20
Phobos0001 is on a distinguished road
awsome, cheers for that, ill take a look tommmorow morning and try again. thanks for your help everyone, ill let you all know how i go
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 02-08-2008, 04:07 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,402
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Why are you waiting until tomorrow morning. Haven't you check it out.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 02-08-2008, 06:30 AM
Member
 
Join Date: Nov 2007
Posts: 20
Phobos0001 is on a distinguished road
all solved
Eranga, the reason why i had to leave it untill the next day is i have an early class that i had to wake up for, CISCO 3, and i cannot afford to fall behind in that class either

i have weeded out the program and solved it, again thanks for the assistance, i apriciate it, its good to have a stable base program to modify for future use

Code:
import javax.swing.*; public class q5 { public static void main (String[] args) { String enter; double number =0; enter = JOptionPane.showInputDialog("Enter a number:"); number = Double.parseDouble(enter); findAbs (number); System.exit(0); } public static void findAbs (double number) { if ( number <0 ) number = -number; JOptionPane.showMessageDialog(null, "the absoloute value is:" + number, "Exerscise 6.1", JOptionPane.INFORMATION_MESSAGE); } }
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 02-08-2008, 07:44 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,402
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Nice to here that you have solved the question.

Yes, as you said, it is better to develop any code/program by depend on the future developments. It's make sense really in the future, if not always make wired
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Need help with a program for high school regarding multi-dimensional arrays. Torque New To Java 2 01-07-2008 09:45 PM
How come multi thread don't look like it? jkhoa Threads and Synchronization 1 09-22-2007 06:25 AM
Call a main method from within a running program zoe New To Java 1 08-07-2007 08:16 AM
Axiomatic Multi-Platform C 1.6.4 (Mac OS X) JavaBean Java Announcements 0 06-22-2007 07:59 PM
Axiomatic Multi-Platform C 1.6.4 JavaBean Java Announcements 0 06-22-2007 01:49 AM


All times are GMT +3. The time now is 04:49 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org