Sunteți pe pagina 1din 11

Home | Contact

aashray | Logout

Home
Resources
Class X
Class XII
Videos
Gallery
Forum
Fun

Friends (0)
Friend Requests
You have no new friend request.
Tutorials

Programming In Java

English

Computer Practical

Viva-Voce
Quick Links

For-loop

While-loop

Do-while loop

Arrays 1D

Arrays 2D

Strings

Functions

Function overloading

Recursive Functions

ISC Computer Practical 2008 Solved


1. A smith number is a composite number, the sum of whose digits is the sum of
the digits of its prime factors obtained as a result of prime factorization
(excluding 1).

The first few such numbers are 4, 22, 27, 58, 85, 94, 121.....
Example 1.
666 Prime factors are 2, 3, 3 and 37
Sum of the digits are (6+6+6) = 18
Sum of the digits of the factors (2+3+3+(3+7) = 18
Sample data:
Input 94 Output SMITH Number
Input 102 Output NOT SMITH Number

View/Hide Solution

import java.util.*;
class ISCprac2011q01{
public static void main(String args[])
throws InputMismatchException{

Scanner scan=new Scanner(System.in);

int n;

System.out.println("Enter a number less than 1000");


n=scan.nextInt();

if(n>=1000)
{
System.out.println("OUT OF RANGE");
}else{
String result,h="",t="",o="";
int a,b,c;
String ones[]={"one", "two","three","four","five","six","seven",
"eight","nine"};

String teens[]={"eleven","twelve","thirteen","fourteen","fifteen"
,"sixteen","seventeen","eighteen","nineteen"};
String tens[]={"ten","twenty","thirty","forty","fifty","sixty",
"seventy","eighty","ninety"};

if(n>=100 && n<1000){


a=n/100;
result=ones[a-1]+" hundred";
n=n%100;
}
if(n%10==0 && n!=0){
a=n/10;
if(result!=null){
result+=" and ";
result+=tens[a-1];
}else{
result=tens[a-1];
}
n=n%10;
}
if(n>20 && n<100){
a=n/10;
b=n%10;
if(result!=null){
result+=" and ";
result+=tens[a-1]+" "+ones[b-1];
}else{
result=tens[a-1]+" "+ones[b-1];
}

}
if(n>10 && n<20){
a=n%10;
if(result!=null){
result+=" and ";
result+=teens[a-1];
}else{
result=teens[a-1];
}
}
if(n<10 && n!=0){

if(result!=null)
{
result+=" and ";
result+=ones[n-1];
}else{
result=ones[n-1];
}

OR

a=n/100;
if(n>100){
n=n%100;
}
b=n/10;

c=n%10;
if(a!=0){
h=ones[a-1]+" hundred";
}
if(b==0 && c!=0){
o=ones[c-1];
}
else if(c==0 && b!=0){
t=tens[b-1];
}
else if(b==1){
t=teens[c-1];
}
else if(b!=0 && c!=0){
t=tens[b-1]+" "+ones[c-1];
}
if(b==0 && c==0)
result=h;
else if(a==0)
result=t+" "+o;
else
result=h+" and "+t+" "+o;

System.out.println("\n"+result.toUpperCase());

}
}
}

2. A sentence is terminated by either ".", "!" or "?" followed by a space.


Input a piece of text consisting of sentences. Assume that there will be a
maximum of 10 sentences in a block.
Write a program to:
(i) Obtain the length of the sentence (measured in words) and the frequency of
vowels in each sentence.
(ii) Generate the output as shown below using the given data
Sample data:
INPUT HELLO! HOW ARE YOU? HOPE EVERYTHING IS FINE. BEST OF LUCK.
OUTPUT
3.

Sentence

No. of Vowels

No. of words

4.

----------------------------------------------------------

5.

6.

7.

8.

9.
10.
11.

Sentence

12.

----------------------------------------------------------

13.

14.
15.

VVVVVVVVVVVVVVV
WWWWWWWWW

18.
19.

VVVVVV
WWW

16.
17.

No. of words/vowels

VVVVVVVVVVVVVVVVVVVVVVVV
WWWWWWWWWWWW

----------------------------------------------------------

Scale used 1:3

View/Hide Solution

import java.io.*;
class ISCprac2011q02{
public static void main(String args[])throws IOException{
BufferedReader br=new BufferedReader(
new InputStreamReader(System.in));

int nos;
System.out.print("Enter number of sentences : ");
nos=Integer.parseInt(br.readLine());

if(nos<1 || nos>=10)
System.out.println("\nInvalid Entry");
else{
int i,j,p,l;
String s[]=new String[nos];

System.out.print("\nEnter "+nos+" sentences : ");

for(i=0;i90)//to maintain cyclic order


ch=ch-26;// subtract 26
}
t=t+(char)ch;
//convert to character and add to a temporary string
}

s[i]=t.trim();// remove leading or trailing spaces


}else{
t="";
p=l-1;

for(j=l-1;j>=0;j--){
//reverse loop to start extraction of words from last to first
char ch=s[i].charAt(j);
if(ch==' '){
t=t+s[i].substring(j+1,p)+" ";
// add the extracted word and a space
p=j;

}
}
t=t+".";
s[i]=t;
}

}
System.out.println("\nOUTPUT:");
for(i=0;i< nos;i++)
System.out.print(s[i]);
}
}
}

20. Given a square matrix list [ ] [ ] of order 'n'. The maximum value possible for 'n'
is 20. Input the value for 'n' and the positive integers in the matrix and perform
the following task:
1. Display the original matrix
2. Print the row and column position of the largest element of the matrix.
3. Print the row and column position of the second largest element of the matrix.
4. Sort the elements of the rows in the ascending order and display the new

matrix.
Sample data:
INPUT:
N=3
List [][]
21.

5 1 3

22.

7 4 6

23.

9 8 2

OUTPUT
5 1 3
7 4 6
9 8 2

The largest element 9 is in row 3 and column 1


The second largest element 8 is in row 3 and column 2
Sorted list
1 3 5
4 6 7
2 8 9

View/Hide Solution

import java.util.*;
class ISCprac2011q03{
public static void main(String args[])
throws InputMismatchException{

Scanner scan=new Scanner(System.in);


System.out.println("Enter your date od birth in dd mm yyyy
format : ");
int d=scan.nextInt();
int m=scan.nextInt();
int y=scan.nextInt();
int dom[]={31,28,31,30,31,30,31,31,30,31,30,31};
if(y%400==0 || (y%100!=0 && y%4==0))
dom[1]=29;
if(d<=dom[m-1])
{
System.out.print("VALID DATE ");
int i,s=0;
for(i=0;i< m-1;i++)
s=s+dom[i];

s+=d;

System.out.print(s);
}else{
System.out.print("INVALID DATE");
}
}
}
Recently Registered

Guess Questions
Ask a Question

View All Questions


Do you know?
Pearls melt in vinegar.
Quote Of The Day
Trade knows neither friends nor kindred. - Anonymous
View all quotes
2014 Mentors. All Rights Reserved. Privacy Policy and Terms of Use
Mon Sep 01 2014 18:24:12 GMT+0530 (India Standard Time)

S-ar putea să vă placă și