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 01-31-2008, 02:51 AM
Member
 
Join Date: Jan 2008
Posts: 26
jvasilj1 is on a distinguished road
Problem with code
I am using this java code to produce output of amicable numbers...it compiles but when i run it, an error occurs in my terminal window and say "Exception in thread "main" java.lang.nosuchmethoderror: main press any key to continue...

also i need to add a joptionpane to my code, so i can tell the program what the upper bounds is for it to search upto certain amicable numbers is.
-----------------------------------------------------------------------
This is my Code
Code:
import java.util.*; public class AmicablePairs{ protected static Vector<Integer> getFactors(int number){ Vector<Integer> result = new Vector<Integer>(); for (int i = 1 ; i < number; i++){ if (number % i == 0) result.add(new Integer(i)); } return result; } protected static int sumNumbers(Vector<Integer> numbers){ int result = 0; for (Integer integer : numbers) result += integer; return result; } protected static void printNumbers(Vector<Integer> numbers){ for (Integer integer : numbers) System.out.println(integer); System.out.println(); } public AmicablePairs(int bound){ for (int m = 2; m <= bound; m++){ for (int n = 2; n <= bound; n++){ if ( (sumNumbers(getFactors(m)) == n) && (sumNumbers(getFactors(n)) == m)) { System.out.println(m + ", " + n); } } } } }
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 01-31-2008, 03:58 AM
Senior Member
 
Join Date: Jul 2007
Posts: 1,222
hardwired is on a distinguished road
"Exception in thread "main" java.lang.nosuchmethoderror
This means that the jvm (java virtual machine) could not find a main method in the class.
Code:
public static void main(String[] args) { // Use JOptionPane.showInputDialog here new AmicablePairs(25); }
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 01-31-2008, 04:01 AM
Member
 
Join Date: Jan 2008
Posts: 26
jvasilj1 is on a distinguished road
where do i put that...could u add it to my code and and paste the whole thing here...
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 01-31-2008, 04:11 AM
Senior Member
 
Join Date: Jul 2007
Posts: 1,222
hardwired is on a distinguished road
Code:
import java.util.*; public class AP { protected static Vector<Integer> getFactors(int number){ Vector<Integer> result = new Vector<Integer>(); for (int i = 1 ; i < number; i++){ if (number % i == 0) result.add(new Integer(i)); } return result; } protected static int sumNumbers(Vector<Integer> numbers){ int result = 0; for (Integer integer : numbers) result += integer; return result; } protected static void printNumbers(Vector<Integer> numbers){ for (Integer integer : numbers) System.out.println(integer); System.out.println(); } public AP(int bound){ for (int m = 2; m <= bound; m++){ for (int n = 2; n <= bound; n++){ if ( (sumNumbers(getFactors(m)) == n) && (sumNumbers(getFactors(n)) == m)) { System.out.println(m + ", " + n); } } } } public static void main(String[] args) { // Use JOptionPane.showInputDialog here new AP(25); } }
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 01-31-2008, 04:19 AM
Member
 
Join Date: Jan 2008
Posts: 26
jvasilj1 is on a distinguished road
Thanks a lot...My java code works now and i have jotptionpane working...I enter 10000 in the dialog box and it computes the perfect number up till 10000 and then the program ends...I need some help now in modifying my code to do that same procedure but just modify the math of it so it can compute AMICABLE NUMBERS....HERE IS MY CODE
--------------------------------------------------------------
Code:
import javax.swing.JOptionPane; public class AmicableNumbers { public static void main(String[] args) { int upperBound, n, factor, sum; upperBound = Integer.parseInt(JOptionPane.showInputDialog ("Enter upper bound for perfect number search")); for(n = 2; n <= upperBound; n++) { sum = 0; for(factor = 1; factor <= n / 2; factor++) if (n % factor == 0) sum += factor; if (n == sum) System.out.println(n); } } } // Prompt of input dialog: //Upper bound for amicable number search: // Sample input to input dialog: //10000 // Output in Terminal Window: //6 //28 //496 //8128
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 02-02-2008, 10:34 AM
CaptainMorgan's Avatar
Moderator
 
Join Date: Dec 2007
Location: NewEngland, US
Posts: 841
CaptainMorgan will become famous soon enoughCaptainMorgan will become famous soon enough
Send a message via AIM to CaptainMorgan
Amicable Numbers.
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
to our beloved Java Forums!
(closes on September 4, 2008)
Want to voice your opinion on your IDE/Editor of choice?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
!
Got a little Capt'n in you? (drink responsibly)
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
[SOLVED] Problem with code - inheritence yalla New To Java 1 03-30-2008 08:11 AM
What is the answer yo my problem with this code masaka New To Java 4 03-26-2008 08:33 AM
Problem with code oregon New To Java 3 08-05-2007 07:57 PM
Problem with zero in my code fernando New To Java 1 08-05-2007 08:39 AM
Problem with my first code paul New To Java 2 07-26-2007 06:09 PM


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


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