0% found this document useful (0 votes)
10 views2 pages

Data Processing and Analysis Guide

This document contains code for generating Pascal's triangle in Java. The code uses nested for loops to populate a 2D array with the binomial coefficient values for each row and column. There is also a discussion that identifies a problem with the code - the outer for loop stopping at r rather than <= r causes it to miss printing the last row of values for a given input. Suggesting changing the termination condition of the outer for loop to <= r instead of < r is proposed as a fix.

Uploaded by

DINESHRAHNGD
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views2 pages

Data Processing and Analysis Guide

This document contains code for generating Pascal's triangle in Java. The code uses nested for loops to populate a 2D array with the binomial coefficient values for each row and column. There is also a discussion that identifies a problem with the code - the outer for loop stopping at r rather than <= r causes it to miss printing the last row of values for a given input. Suggesting changing the termination condition of the outer for loop to <= r instead of < r is proposed as a fix.

Uploaded by

DINESHRAHNGD
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

import [Link].

;
import [Link].;

public class pascal3
,
public static int,, triangle3(int r)
,
int ,, tria = new intr+1,r+1,;
for (int c = 0; c < r; c++)
,
[Link]("");
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++)
,


,
,

[Link](triac,k, + ", ");
,
,
return tria;
,

public static void main(String, args)
,
int
r=[Link]([Link]("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