Latest topics | » Nitration of aniline - IIT JEE 2018 Advanced - solved Fri Jun 08, 2018 2:34 am by adianadiadi » Diamagnetic - Paramagnetic - Ni(CO)4, [Ni(CN)4]2- and [NiCl4Fri Apr 06, 2018 1:05 am by adianadiadi » IIT JEE chemistry solved interactive question paperSun Oct 29, 2017 12:11 pm by adianadiadi » IIT JEE 2015 SOLVED QUESTION PAPERWed Oct 19, 2016 1:44 pm by adianadiadi » IIT JEE chemistry solved questionsSat Jul 18, 2015 6:15 pm by adianadiadi » General Description of Chinese Market for Foaming Agent ADC Fri May 09, 2014 2:09 pm by happybaicaitou » How to get Lowest Cost MBBS Admission?Mon Feb 24, 2014 6:39 pm by MENTOR 2014 » girl boy vashikaran specialist agori baba ji +91-9461165Tue Jan 21, 2014 6:00 pm by krshastri » STRONG LOST LOVE SPELL +91-9461165176Tue Jan 21, 2014 6:00 pm by krshastri |
feeds | |
|
Search if you can't find it here
| |
Author | Message |
---|
RC Active member
| Subject: Whats Wrong ?? Wed Mar 17, 2010 6:58 pm | |
| Pls tell me whats wrong with this prog..this is not working.. this is the soln to 1st prob of Sec B in Specimen Paper 2010
import java.io.*; class Prime { int arr[][],r,c; Prime()throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); System.out.println("Please Enter Number Of Rows : "); r=Integer.parseInt(br.readLine()); System.out.println("Please Enter Number Of Columns : "); c=Integer.parseInt(br.readLine()); } int isPrime(int p) { for(int i=2;i<=p/2;i++) if(p%i==0) return 0; return 1; } void fill() { int i,j,x=1,pos=1; for(i=0;i<r;i++) for(j=0;j<c;j++) for(x=pos;;x++) if(isPrime(x)==1) { pos=x; arr[i][j]=x; } System.out.println("a"); } void display() { for(int i=0;i<r;i++) { for(int j=0;j<c;j++) System.out.println(arr[i][j]+" "); System.out.println(); } } void main()throws IOException //if error is not thrown here,exception occurs. { Prime obj=new Prime(); //Object named obj is created. obj.fill(); obj.display(); } } |
| | | WinRrule Active member
| Subject: Re: Whats Wrong ?? Wed Mar 17, 2010 7:36 pm | |
| i am also struck in the same program..! |
| | | RC Active member
| Subject: Re: Whats Wrong ?? Wed Mar 17, 2010 7:52 pm | |
| i just cant figure out why my prog is'nt working,, |
| | | saif Active member
| Subject: Re: Whats Wrong ?? Wed Mar 17, 2010 8:31 pm | |
| Done have removed 5-6 bugs from your prog.. Here is the correct version Test output Please Enter Number Of Rows : 5 Please Enter Number Of Columns : 5 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 //program import java.io.*; class mainp { public static void main(String args[])throws IOException //if error is not thrown here,exception occurs. { Prime obj=new Prime(); //Object named obj is created. obj.fill(); obj.display(); } }
class Prime { int arr[][],r,c; Prime()throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); System.out.println("Please Enter Number Of Rows : "); r=Integer.parseInt(br.readLine()); System.out.println("Please Enter Number Of Columns : "); c=Integer.parseInt(br.readLine()); arr=new int[r][c]; } int isPrime(int p) { for(int i=2;i<=p/2;i++) if(p%i==0) return 0; return 1; } void fill() { int i,j,x=2; for(i=0;i<r;i++) { for(j=0;j<c;j++) { while(isPrime(x)!=1) {x++;} arr[i][j]=x; x++; } } } void display() { for(int i=0;i<r;i++) { for(int j=0;j<c;j++) {System.out.print(arr[i][j]+" ");} System.out.println(); } } } |
| | | saif Active member
| Subject: Re: Whats Wrong ?? Wed Mar 17, 2010 8:31 pm | |
| ALL IZZZZ WELLLLL |
| | | kevinjo911
| Subject: Re: Whats Wrong ?? Thu Mar 18, 2010 11:55 am | |
| hey dude put the main method in the beginning else it wont work....... |
| | | RC Active member
| Subject: Re: Whats Wrong ?? Thu Mar 18, 2010 11:58 am | |
| thanks saif.. but are we allowed to make another class not mentioned in the question ?? |
| | | saif Active member
| Subject: Re: Whats Wrong ?? Thu Mar 18, 2010 2:29 pm | |
| @RC
thats exactly the question that I have planed to ask my comp teacher before exam.Unfortunately i don't have his mobile number or else i would have asked him by now |
| | | WinRrule Active member
| Subject: Re: Whats Wrong ?? Thu Mar 18, 2010 4:23 pm | |
| U don't need another class..! |
| | | G-7 Active member
| Subject: Re: Whats Wrong ?? Thu Mar 18, 2010 5:08 pm | |
| no no no no..winrule..! can we just use any other class as an extra..? will there be any penalty for it.? |
| | | RC Active member
| Subject: Re: Whats Wrong ?? Thu Mar 18, 2010 5:34 pm | |
| i know winrule we dont need it..just asking if its allowed..else it can be done this way-- import java.io.*; public class Prime { int arr[][],r,c; Prime()throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); System.out.println("Please Enter Number Of Rows : "); r=Integer.parseInt(br.readLine()); System.out.println("Please Enter Number Of Columns : "); c=Integer.parseInt(br.readLine()); arr=new int[r][c]; } public int isPrime(int p) { for(int i=2;i<=p/2;i++) if(p%i==0) return 0; return 1; } public void fill() { int i,j,x=2; for(i=0;i<r;i++) for(j=0;j<c;j++) { while(isPrime(x)!=1) {x++;} arr[i][j]=x; x++; } } public void display() { for(int i=0;i<r;i++) { for(int j=0;j<c;j++) System.out.printf("%2d ",arr[i][j]); System.out.println(); } } public static void main(String args[])throws IOException //if error is not thrown here,exception occurs. { Prime obj=new Prime(); //Object named obj is created. obj.fill(); obj.display(); } } |
| | | WinRrule Active member
| Subject: Re: Whats Wrong ?? Thu Mar 18, 2010 6:38 pm | |
| yes RC.. that's what is expected..
@G-7, when they r not asking for it to be called from another class y do extra and give the examiner chance to cut marks? |
| | | RC Active member
| Subject: Re: Whats Wrong ?? Thu Mar 18, 2010 7:19 pm | |
| ok thanks |
| | | WinRrule Active member
| Subject: Re: Whats Wrong ?? Thu Mar 18, 2010 7:27 pm | |
| Welcome..! |
| | | Sponsored content
| Subject: Re: Whats Wrong ?? | |
|
|
| | | |
Page 1 of 1 | |
| Permissions in this forum: | You cannot reply to topics in this forum
| |
| |
| |