Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-05-2011, 10:20 PM   PM User | #1
roher4
New Coder

 
Join Date: Jul 2010
Location: Canada
Posts: 26
Thanks: 2
Thanked 0 Times in 0 Posts
roher4 is an unknown quantity at this point
Pascal's Triangle

I can't find the error's in this program. I had to create these methods and must use them. It's for my high school class and I've cut 19 errors to one.

Code:
import java.util.Scanner;

public class Pascal{

public static void main(String[] args)
{
	Scanner input= new Scanner(System.in);
   int rows = getRows();
   while (rows != 0){
      printTriangle(rows);
      rows = getRows();
   }
} 

public static long factorial(long n)
{
	//A number that is leading up to the specified number
	for (int i=2,k=1; i<=n; i++){
	k*=i;
	return k;
	}
	return 1;
}
public static int getRows(){
	Scanner input= new Scanner(System.in);
	
	int rows=5;
	System.out.println("Please enter the number of rows:");
	rows = input.nextInt();
	return (rows);
}

public static long nCr(long n, long r){
	return factorial(n)/factorial(r)*(factorial (n-r));
}

public static void printTriangle(int r){
	for (int i=1;i<=r;i++)
	{
		for(int j=1;j<=i; j++)
		{
			System.out.println(nCr(i-1,j-1));
		}
		
		System.out.println("");
	  }

	}

}
roher4 is offline   Reply With Quote
Old 03-06-2011, 12:51 AM   PM User | #2
barillitos
New to the CF scene

 
Join Date: Mar 2011
Location: san antonio,TX
Posts: 4
Thanks: 1
Thanked 0 Times in 0 Posts
barillitos is an unknown quantity at this point
Lightbulb error

what did the compiler spit out, what type of error?
barillitos is offline   Reply With Quote
Old 03-06-2011, 03:38 PM   PM User | #3
roher4
New Coder

 
Join Date: Jul 2010
Location: Canada
Posts: 26
Thanks: 2
Thanked 0 Times in 0 Posts
roher4 is an unknown quantity at this point
Quote:
Originally Posted by barillitos View Post
what did the compiler spit out, what type of error?
Arithmetic exception..divide by zero?
roher4 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:00 AM.


Advertisement
Log in to turn off these ads.