Aniruddha
| Subject: PATTERN Fri Sep 19, 2008 10:54 am | |
| CAN ANYONE DO THISSSSSS.........
1********** 120 ****2****24 ******6**** ****2**** 24 1********** 120 //"*" INDICATES SPACES logic::: 1=1*1; 2=1*2; 3=1*2*3;.............. patten logic::: two loops suppose;;; for(int m=1;m<=5;m++) for(int n=1;n<=5;n++) if(m==n || m+n==6) //then call the factorial function... PLEASE HEP MEEEEEE!!!!!!!!!!!!!!!!!!!!!!!
Last edited by Aniruddha on Fri Sep 19, 2008 11:00 am; edited 2 times in total (Reason for editing : SIMPLE) |
|
abhas Active member
| Subject: icse iit cbse java free help program pattern Sat Sep 20, 2008 10:39 am | |
| //you logic is correct i have made your prog using your logic.... //i have used isc style that you will be using in 11th 12th in class 10th you should consider pat class only or //if you wish you may consider both classes //i have tested prog in jdk1.5.0
class pattern_new { public static void main(String args[]) { pat obj=new pat(); pat.run(); } }
class pat { //to get factorial (i love this logic) but you may use simple logic too public static int factorial(int num) { //factorial not defined for negative ints if (num < 0) return -1; if (num == 0) return 1; if (num <= 2) return num; //RECURSIVE STEP: n! = n * (n-1)! return (num * factorial(num - 1)); } public static void run() { for(int m=1;m<=5;m++) {for(int n=1;n<=5;n++) { if(m==n || m+n==6) System.out.print(factorial(n)); else System.out.print(" "); } System.out.println(); } } } |
|
Arya Nair Active member
| Subject: Re: PATTERN Mon Feb 16, 2009 1:44 pm | |
| is this an important question? |
|