
September 8th, 2006, 05:40 PM
|
|
Registered User
|
|
Join Date: Aug 2006
Posts: 15
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
|