You are on page 1of 20

import java.util.*; public class Example {public static void main(String[] args) { Scanner in = ne Scanner(S!stem.in); S!stem.out.

println("#lease enter a string$"); String input = in.next();%%

&et'od ( ) *+ ans'ul import java.io.*; class vo els{ public static void main()t'ro s ,*Exception { -u++ered.eader in=ne -u++ered.eader(ne ,nputStream.eader(S!stem.in)); String str; int i/c=0/j; S!stem.out.println("Enter a string"); str=in.read1ine(); str=str.to1o er2ase(); +or(i=0;i3=str.lengt'())(;i44) { j=str.c'ar5t(i); i+(j==6 6) { i+((j4()==6a6(j4()==6e6(j4()==6i6(j4()==6o6(j4()==6u6) c44; % % i+(str.c'ar5t(0)==6a6str.c'ar5t(0)==6e6str.c'ar5t(0)==6i6str.c

'ar5t(0)==6o6str.c'ar5t(0)==6u6) c44; S!stem.out.println("7n no. o+ ords starting it' vo els$$$$"4c); % % &et'od 8 (-! 9ars')(me $)) import java.io.*; class #roverbial { public static void main(String args[])t'ro s ,*Exception { -u++ered.eader br = ne -u++ered.eader(ne ,nputStream.eader(S!stem.in)); S!stem.out.println(" Enter a String "); String s=br.read1ine(); c'ar c'; s=s.to1o er2ase(); int c=0/l=s.lengt'(); +or(int i=0;i { c'=s.c'ar5t(i); i+(c'==6a6::c'==6e6::c'==6i6::c'==6o6::c'==6u6) c44; % S!stem.out.println(" ;re<uenc! o+ =o els is "4 c); % %

import java.util.Scanner; public class =o el5nal!st { >> >> public static void main (String[] args) { String userString; int a2ount = 0/ e2ount = 0/ i2ount = 0/ o2ount = 0/ u2ount = 0; c'ar vo els; Scanner scan = ne Scanner (S!stem.in); S!stem.out.println ("enter string$"); userString = scan.next1ine(); +or (int count = 0; count 3 userString.lengt'(); count44) { vo els = userString.c'ar5t(count);

s itc' (vo els) { case 6a6$ a2ount44; brea?; case 6e6$ e2ount44; brea?; case 6i6$ i2ount44; brea?; case 6o6$ o2ount44; brea?; case 6u6$ u2ount44; brea?; de+ault$ S!stem.out.println ("#lease enter valid string.");

% S!stem.out.println ("a$ " 4a2ount); S!stem.out.println ("e$ " 4e2ount); S!stem.out.println ("i$ " 4i2ount); S!stem.out.println ("o$ " 4o2ount); S!stem.out.println ("u$ " 4u2ount); % % %

80(8 ,S2 2omputer Science #ractical Solved #aper Program number 1 of 2012 ISC computer science practical paper 5 prime palindrome integer is a positive integer ( it'out leading @eros) 'ic' is prime as ell as a palindrome. Aiven t o positive integers m and n/ 'ere m Blt; n/write

a program to determine how many primepalindrome integers are t'ere in t'e range bet een m and n (bot' inclusive) and output t'em. C'e input contains t o positive integers m and n 'ere mBlt; D000 and nBlt; D000.Eispla! t'e number o+ prime palindrome integers in t'e speci+ied range along it' t'eir values in t'e +ormat speci+ied belo $ Test your program with the sample data and some random data: Example ($ ,F#GC$ m=(00 F=(000 *GC#GC$ C'e prime palindrome integers are$ (0(/(D(/(H(/(I(/(J(/D(D/DH(/DKD/DID/K8K/KHK/KIK/KJK/J( J/J8J ;re<uenc! o+ prime palindrome integers$ (H Example 8$ ,F#GC$ &=(00 F=H000 *GC#GC$ *ut o+ .ange import java.io.*;

class #al#rime { -u++ered.eader br=ne -u++ered.eader(ne ,nputStream.eader(S!stem.in)); int m/n; int c; public void s'o #al#rime() t'ro s Exception { c=0; S!stem.out.println("Enter t'e 1o er 1imit$"); m=,nteger.parse,nt(br.read1ine()); S!stem.out.println("Enter t'e Gpper 1imit$"); n=,nteger.parse,nt(br.read1ine()); i+(mL =n :: nL =D000) S!stem.out.println("*ut o+ .ange."); else { S!stem.out.println("C'e #rime #alindrome integers are$"); 'ile(m 3=n) { i+(pal#rime(m)) { i+(c==0) S!stem.out.print(m); else S!stem.out.print("/ "4m); c44; % m44; %

S!stem.out.println("7n;re<uenc! o+ #rime #alindrome integers$ "4c); % % private boolean pal#rime(int x) { boolean bool=+alse; int i; int rev=0; +or(i=8;i3 x;i44) { i+(xMi==0) brea?; % i+(i==x) bool=true; i+(bool) { +or(i=x;i L0;i=i>(0) { rev=rev*(04iM(0; % i+(revN=x) bool=+alse; % return bool; % public static void main(String args[]) t'ro s Exception { #al#rime ob=ne #al#rime ();

ob.s'o #al#rime(); % % Program number 2 of 2012 ISC computer science practical paper rite a program to accept a sentence as input. C'e ords in t'e string are to be separated b! a blan?. Eac' ord must be in upper case. C'e sentence is terminated b! eit'er O.P/PNP or OQP. #er+orm t'e +ollo ing tas?s$ *btain t'e length of the sentence (measured in ords) 5rrange t'e sentence in alp'abetical order o+ t'e ords Cest !our program it' t'e sample data and some random data$ Example ($ ,F#GC$ FE2ESS,CR ,S C9E &*C9E. *; ,F=EFC,*F. *GC#GC$ 1engt'$ S .earranged Sentence$ ,F=EFC,*F ,S &*C9E. FE2ESS,CR *; C9E Example 8$ ,F#GC$ -E A**E C* *C9E.S.

*GC#GC$ 1engt'$ T .earranged Sentence$ -E A**E *C9E.S C* import java.io.*; import java.util.*; class &atrixmult { -u++ered.eader br=ne -u++ered.eader(ne ,nputStream.eader(S!stem.in)); String str; String ords[]; StringCo?eni@er st?; int i/j/c/x; public void ta?e()t'ro s Exception { int +lag; 'ile(true) { +lag=0; S!stem.out.println("Enter t'e sentence$"); str=br.read1ine(); +or(i=0;i 3 str.lengt'();i44) { i+(2'aracter.is1o er2ase(str.c'ar5t(i))) { +lag=(; brea?; % %

i+ (+lag==0) brea?; % st?=ne StringCo?eni@er(str/" ./QN"); c=st?.countCo?ens(); x=0; ords=ne String[c]; 'ile(st?.'as&oreElements()) { ords[x44]=st?.nextCo?en(); % S!stem.out.println("1engt'="4c); +or(i=0;i 3 x)(;i44) { +or(j=i4(;j 3 x;j44) { i+( ords[i].compareCo( ords[j])L0) { str= ords[i]; ords[i]= ords[j]; ords[j]=str; % % % S!stem.out.println("7n.earranged Sentence$7n"); +or(i=0;i 3 c;i44) S!stem.out.print( ords[i]4" "); % public static void main(String args[]) t'ro s Exception {

&atrixmult ob=ne &atrixmult(); ob.ta?e(); % % Same program using alternate techni!ue. import java.io.*; import java.util.*; class &atrixmult { -u++ered.eader br=ne -u++ered.eader(ne ,nputStream.eader(S!stem.in)); String str; String ords[]=ne String[80]; StringCo?eni@er st?; int i/j/x; public void ta?e()t'ro s Exception { int +lag; 'ile(true) { +lag=0; S!stem.out.println("7nEnter t'e sentence$"); str=br.read1ine(); +or(i=0;i 3 str.lengt'();i44) { i+(2'aracter.is1o er2ase(str.c'ar5t(i))) { +lag=(;

brea?; % % i+ (+lag==0) brea?; % str=str.replace(6.6/6 6); str=str.replace(6/6/6 6); str=str.replace(6Q6/6 6); str=str.replace(6N6/6 6); x=0; 'ile(true) { i=str.index*+(6 6); i+(i 3 0) brea?; ords[x44]=str.substring(0/i); str=str.substring(i4(); % ords[x44]=str; S!stem.out.println("1engt'="4(x)()); +or(i=0;i 3 x)(;i44) { +or(j=i4(;j 3 x;j44) { i+( ords[i].compareCo( ords[j]) L 0) { str= ords[i]; ords[i]= ords[j];

ords[j]=str; % % % S!stem.out.println("7n.earranged Sentence$7n"); +or(i=0;i 3 x;i44) { i+(i==x)() S!stem.out.print( ords[i]); else S!stem.out.print( ords[i]4" "); % % public static void main(String args[]) t'ro s Exception { &atrixmult ob=ne &atrixmult(); ob.ta?e(); % % Program number " of 2012 ISC computer science practical paper Urite a program to declare a matrix 5 [][] o+ order (&VF) 'ere W&X is t'e number o+ ro s and WFX is t'e number o+ columns suc' t'at bot' & and F must be greater t'an 8 and less t'an 80. 5llo t'e user to input integers into t'is matrix. #er+orm t'e +ollo ing tas?s on t'e matrix$

#isplay the input matri$ ;ind t'e maximum and minimum value in t'e matrix and displa! t'em along it' t'eir position. Sort t'e elements o+ t'e matrix in ascending order using an! standard sorting tec'ni<ue and rearrange t'em in t'e matrix. *utput t'e rearranged matrix. Sample input %utput ,F#GC$ &=D F=T Entered values$ I/K/J/D/)8/0/T/H/(/D/S/)T *riginal matrix$ I K J D )8 0 T H ( D S )T 1argest Fumber$ J .o $ 0

2olumn$ 8 Smallest Fumber$ )T .o =8 2olumn=D .earranged matrix$ )T )8 0 ( D D T H S K I J import java.io.*; class &atrixmult { -u++ered.eader br=ne -u++ered.eader(ne ,nputStream.eader(S!stem.in)); int arr[][]; int r/c/max/min/maxi/maxj/mini/minj/i/j/m/n; public void ta?e()t'ro s Exception { boolean bool=true; 'ile(bool) { S!stem.out.println("7nEnter t'e number o+ ro s$"); r=,nteger.parse,nt(br.read1ine()); S!stem.out.println("7nEnter t'e number o+ columns$"); c=,nteger.parse,nt(br.read1ine()); i+(r 3 8 :: c 3 8 :: r L 80 :: c L 80) bool=true; else

bool=+alse; % arr=ne int[r][c]; +or(i=0;i 3 r;i44) { +or(j=0;j 3 c;j44) { S!stem.out.println("7nEnter =alue$"); arr[i][j]=,nteger.parse,nt(br.read1ine()); % % max=arr[0][0]; min=arr[0][0]; maxi=0; mini=0; maxj=0; minj=0; +or(i=0;i 3 r;i44) { +or(j=0;j3 c;j44) { i+(arr[i][j]L max) { max=arr[i][j]; maxi=i; maxj=j; % else i+(arr[i][j]3 min) { mini=i; minj=j;

min=arr[i][j]; % % % S!stem.out.println("7n*riginal 5rra!7n"); +or(i=0;i3 r;i44) { +or(j=0;j3 c;j44) { S!stem.out.print(arr[i][j]4" "); % S!stem.out.println(); % S!stem.out.println("7n&aximum =alue="4max); S!stem.out.println("7n.o ="4maxi); S!stem.out.println("7n2olumn="4maxj); S!stem.out.println("7n&inimum =alue="4min); S!stem.out.println("7n.o ="4mini); S!stem.out.println("7n2olumn="4minj); +or(m=0;m3 r;m44) { +or(n=0;n3 c;n44) { +or(i=0;i3 r;i44) { +or(j=0;j3 c;j44) { i+(arr[m][n]3 arr[i][j]) {

min=arr[m][n]; arr[m][n]=arr[i][j]; arr[i][j]=min; % % % % % S!stem.out.println("7nSorted 5rra!7n"); +or(i=0;i3 r;i44) { +or(j=0;j3 c;j44) { S!stem.out.print(arr[i][j]4" "); % S!stem.out.println(); % % public static void main(String args[]) t'ro s Exception { &atrixmult ob=ne &atrixmult(); ob.ta?e(); % % 5lgorit'm and variable description o+ t'e above programs ill be posted in t'is pagever! soon.

You might also like