You are on page 1of 2

import java.io.

;
import javax.swing.;

public class pascal3
,
public static int,, triangle3(int r)
,
int ,, tria = new intr+1,r+1,;
for (int c = 0; c < r; c++)
,
System.out.println("");
for (int k = 0; k < c; k++)
,
if (k == 0)
,

triac,k, = 1;
,
else if (k == c-
1)
,

triac,k, = 1;
,
else
,

triac,k, = 1;

for (int l = 0; l < k; l++)
,


,
,

System.out.print(triac,k, + ", ");
,
,
return tria;
,

public static void main(String, args)
,
int
r=Integer.parseInt(JJptionPane.showInputDialog("Enter number of Elements:"));
int,, pascal = triangle3(r);
,
,
l have a problem wlLh Lhls one coz lL doesnL show Lhe values on Lhe base of Lhe Lrlangle heres my
example

lf l lnpuL 4 Lhe ouLpuL would be

1
1 1
1 2 1
1 3 3 1


lLs supposed Lo be

1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
i was reading your code, i think your problem is here
1 for (int c = 0; c < r; c++)
you are missing one simple thing, you are stopimg the Ior loop just beIore c takes r value, su c
will never reach r value, why don't you add an , like this:
1 for (int c = 0; c <= r; c++)


I hope this is helpIul.

You might also like