Vous êtes sur la page 1sur 5

Three BlueJ programs in ISC 2013 Computer Science practical examination Question number 1: An ISBN (International Standard Book

Number) is a ten digit code which uniquely identifies a book. The first nine digits re resent the grou ! ublisher and title of the book and the last digit is used to check whether ISBN is correct or not. "ach of the first none digits of the code can take a #alue between $ to %. Sometimes it is necessary to make the last digit equal to ten. This is done by writing the last digit of the code as &. To verif an ISB!! calculate '$ times the first digit! lus % times the second digit! lus ( times the third digit and so on until we add ' time the last digit. If the final number lea#es no remainder while di#ided by ''! the code is a #alid ISBN )or e*am le+ $,$''$--''.'$/$0%/,0(/$01/'02/'03/$04/-0-/-0,/'0'/'.33 This is a #alid ISBN $$142,34,&.'$/$0%/$0(/101/402/203/,04/30-/40,/,0'/'$.'12 Similarly $'','',4,3 is not a #alid ISBN. Sam le in ut5out ut+ In ut code+ $,$'3-$(,' 6ut ut+ Sum.%% 7ea#es no remainder 8 #alid ISBN In ut code+ -322($-,4 6ut ut+ Sum.in#alid in ut In ut code+ $,-'4,($-' 6ut ut+ Sum.',, 7ea#es remainder 8 in#alid ISBN Solution of t"e program number 1 im ort 9a#a.io./: class ;rog' < Buffered=eader br.new Buffered=eader(new In utStream=eader(System.in)): String str: int digit!c.'!*.$!i!len: char ch: ublic #oid show()throws "*ce tion < System.out. rintln(>"nter the ISBN code+>): str.br.read7ine(): len.str.length(): if(len?.'$)

< System.out. rintln(>In#alid in ut.>): return: @ for(i.len5':iA.$:i55) < ch.str.charAt(i): if(ch..B&B) digit.'$: else digit.ch54(: *.*0digit/c: c00: @ System.out. rintln(>CnSum.>0*): if(*D''..$) System.out. rintln(>7ea#es no remainder 5 #alid ISBN code.>): else System.out. rintln(>7ea#es remainder 5 in#alid ISBN code.>): @ ublic static #oid main(String argsEF) throws "*ce tion < ;rog' ob.new ;rog'(): ob.show(): @ @

Question number 2: Grite a rogram to declare a s#uare matrix $%&%& of order (H&N) where IHJ is the number of rows and the number of columns. IHJ should be greater than , and less than ,$. Allow user to enter integers into this matri*. Kis lay a ro riate error message for an in#alid in ut. ;erform the following tasks. '. the in ut matri* ,. Lreate a mirror image of t"e inputte' matrix. -. the mirror image matri* Sam le+ In ut+ H.4 '2 ', ( , '4 2 ' 6ut ut+ 6riginal matri*

4 '2 ', ( , '4 2 ' Hirror image matri*+ ', '2 4 '4 , ( - ' 2 Sam le ,+ In ut H.,, 6ut ut+ SiMe out of range

Solution of t"e program number 2


im ort 9a#a.io./: class ;rog, < Buffered=eader br.new Buffered=eader(new In utStream=eader(System.in)): int aEFEF: int i!9!m: ublic #oid show()throws "*ce tion < System.out. rintln(>"nter the number of rows+>): m.Integer. arseInt(br.read7ine()): if(mN., OO mA.,$) < System.out. rintln(>CnSiMe out of range+>): return: @ a.new intEmFEmF: for(i.$:iN m:i00) < for(9.$:9N m:900) < System.out. rintln(>"nter #alue+>): aEiFE9F.Integer. arseInt(br.read7ine()): @ @ System.out. rintln(>Cn6riginal matri*Cn>): for(i.$:iN m:i00) < for(9.$:9N m:900) < System.out. rint(> >0aEiFE9F): @

System.out. rintln(): @ System.out. rintln(>CnHirror image matri*Cn>): for(i.$:iN m:i00) < for(9.m5':9A.$:955) < System.out. rint(> >0aEiFE9F): @ System.out. rintln(): @ @ ublic static #oid main(String argsEF) throws "*ce tion < ;rog, ob.new ;rog,(): ob.show(): @ @ Question number 3: A alindrome is a word that may be read the same in either direction. Acce t a sentence in u er case which is terminated by either I.J!J!J! IPJ! I?J. "ach word in the sentence is se arated by a blank s ace. ;erform the following tasks+ '. the count of palin'romic (or's in t"e sentence ,. the alindromic words in the sentence. "*am le '+ In ut+ H6H ANK KAK A=" L6HINQ AT N66N. 6ut ut+ H6H KAK N66N Number of alindromic words+ "*am le ,+ In ut+ R6G A=" S6TP 6ut ut+ No alindromic words Solution of t"e program number 3 im ort 9a#a.io./: im ort 9a#a.util./: class ;rog< Buffered=eader br.new Buffered=eader(new In utStream=eader(System.in)): String str: StringTokeniMer st:

String s: int i.$: ublic #oid show()throws "*ce tion < System.out. rintln(>"nter the sentence+>): str.br.read7ine().toT erLase(): st.new StringTokeniMer(str!> .!P?>): while(st.hasHoreTokens()) < s.st.ne*tToken(): if( alin(s)) System.out. rint(> >0s): @ if(i..$) System.out. rintln(>CnNo alindromic words>): else System.out. rintln(>CnNumber of alindromic words +>0i): @ ri#ate boolean alin(String s') < int *!9!len: len.s'.length(): *.len5': for(9.$:9N lenU,:900) < if(s'.charAt(9)?.s'.charAt(*)) break: *55: @ if(9N lenU,) return false: else < i00: return true: @ @ ublic static #oid main(String argsEF) throws "*ce tion < ;rog- ob.new ;rog-(): ob.show(): @ @

Vous aimerez peut-être aussi