Results 1 to 5 of 5
Thread: java program for recursion
- 11-25-2008, 04:33 PM #1
Member
- Join Date
- Nov 2008
- Location
- Sri Lanka
- Posts
- 2
- Rep Power
- 0
need an interface for a recursion algorithm program
i need some help to finish my assignment
following is the code
i want the main method to get an user input, it should be a GUI, since i don;t know swing i find it hard , please help me.. regards.. i want the interface to get a single integer and buttons to compute, factorial, triangle and partaily by giving a nother value to compute permutation or combination
import java.io.*;
class fcp
{
int factorialGen(int x){
int temp;
if(x==0){
temp=1;
}else if(x==1){
temp=1;
}else{
temp=x*factorialGen(x-1); //recurtion of function;
}
return temp;
}
int combination(int n,int r){
int x = factorialGen(n)/(factorialGen(r)*factorialGen(n-r));
return x;
}
int permutation(int n,int r){
int x = factorialGen(n)/factorialGen(r);
return x;
}
void triangle(int x){
for(int n=0;n<=x;n++){
for(int j=x;j>=0;j--){
System.out.println(" ");
}
for(int r=0;r<n;r++){
combination(n,r);
}
}
System.out.println("\n");
}
void pascalTrianglefactorial(int x){
System.out.println("The factorial value is"+factorialGen(x));
triangle(x);
}Last edited by oshiru; 11-25-2008 at 04:55 PM. Reason: title doesn't match for what i require
- 11-26-2008, 12:53 AM #2
Create JFrame ,add to it JPanel which will have JButton and JTextField,and add to the action listeners,which will produce and operate all the functions you need.
- 11-26-2008, 03:57 AM #3
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,370
- Blog Entries
- 1
- Rep Power
- 26
Search on the Google, you can find lots of simple examples related to this. Just have a try first.
Try this one
- 11-27-2008, 02:07 AM #4
Member
- Join Date
- Nov 2008
- Location
- Sri Lanka
- Posts
- 2
- Rep Power
- 0
thnx alot guys..im absolutely new for this field
- 11-27-2008, 04:34 AM #5
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,370
- Blog Entries
- 1
- Rep Power
- 26
Don't worry lol, just start from the basis. Work hard and try to do something yourself first. It makes a big difference.
Similar Threads
-
Recursion in Java ..
By Java01 in forum New To JavaReplies: 6Last Post: 10-24-2008, 11:42 AM -
java recursion infinite loop
By tony404 in forum Advanced JavaReplies: 9Last Post: 10-03-2008, 01:16 PM -
i could not get the recursion in java
By sivasayanth in forum New To JavaReplies: 3Last Post: 04-23-2008, 08:08 AM -
How to execute an External Program through Java program
By Java Tip in forum java.ioReplies: 0Last Post: 04-04-2008, 02:40 PM -
Recursion in java
By lenny in forum Advanced JavaReplies: 1Last Post: 08-07-2007, 06:23 AM
Bookmarks