Java Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingJava Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old September 8th, 2006, 05:40 PM
ChaNgeD ChaNgeD is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2006
Posts: 15 ChaNgeD User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 21 m 37 sec
Reputation Power: 0
Help with 2 easy functions?

Ok i'm told to make a gcf program which caculates the greasest common factor of 2 or 3 numbers the user gets to choose now here lies the problem. i have twoNumGcf so if user chooses to enter 2 numbers it will caculate the gcf of those 2 numbers and i have threeNumGcf which does the gcf for 3 numbers. now i need help with making the function to caculate the gcf. i have the functions ready to go i need to know how to make the math work to caculate the gcf!
there are 2 errors becuz i have not yet finished my program!

my code:
Code:
import java.io.*;
import java.util.*;

public class Program2
{
  
public static void Playgame() throws IOException
{
 try
 {
  String YesorNo;
  BufferedReader keyboard;
  boolean loopNeeded;
  
  keyboard = new BufferedReader(new InputStreamReader(System.in));
  
  System.out.println ("Would you like to play the GCF game?\n Please type Yes or No and press Enter");
  YesorNo = keyboard.readLine();																			// assigns the entered string to the variable YesorNo
  
  
  if (YesorNo.equalsIgnoreCase("yes"))
  gcfNumbers();																								//sends the program to gcfNumbers
  else if (YesorNo.equalsIgnoreCase("no"))
  {
   System.out.println("Thanks for playing the GCF game!");
   System.exit(1);
  }
  else 
  {
   System.out.println("Please type Yes or No and press Enter");
   Playgame();
  }
 }
 catch   (NullPointerException e)
 {
  System.out.println("Oh Inferior One, why must you try to spoil my programs?");
  Playgame();
 }
}
public static void twoNumGCF()
{

}
public static void threeNumGCF()
{
	
}
public static void gcfNumbers()
{
 try 
  {
   Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();

   
   if (a == 2)
   {
     twoNumGCF();
    }
   else if (a == 3)
    {
     threeNumGCF();
    }
    else 
    {
     System.out.println("Please type 2 or 3 numbers, please try again! "); 
     gcfNumbers();
    }
  }
  
  catch (NullPointerException e)
  {
   System.out.println("Why must you bother me so, Hanosh?\n");
   }
 
};
}

Last edited by MadCowDzz : September 11th, 2006 at 08:13 AM. Reason: added [code] tags

Reply With Quote
  #2  
Old September 11th, 2006, 08:21 AM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 14 m 9 sec
Reputation Power: 8
If it's just the math you need help with, there is an abundance of formulas and calculations on the internet

As per Wikipedia: Greatest common factor

You might find the Euclidean algorithm exciting.
__________________
Daryl's Homepage | My Blogroll | My Profile | Firefox supporter!
DevArticles Forum Moderator

"The net is a waste of time, and that's exactly what's right about it." -- William Gibson

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJava Development > Help with 2 easy functions?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT