The assignment is to create Pascal\'s Triangle without using arrays. I have the method that produces the values for the triangle below. The method accepts an integer for the
You need to print the spaces (like others have mentioned) and also as this is homework I'm leaving it to you but you might want to look at this handy little function
System.out.printf();
Here is a handy reference guide
Also note that you will need to take into account that some numbers are more than 1 digit long!
public class HelloWorld{
public static void main(String []args){
int s=7;
int k=1;
int r;
for(int i=1;i<=s;i++){
int num=1;
r=i;
int col=0;
for(int j=1;j<=2*s-1;j++){
if(j <= s-i)
System.out.print(" ");
else if(j >= s+i)
System.out.print(" ");
else{
if(k%2 ==0){
System.out.print(" ");
}
else{
if (col > 0) {
num = num * (r - col) / col;
}
System.out.print(num+" ");
col++;
}
k++;
}
}
System.out.println("");
k=1;
}
}
}