Вы находитесь на странице: 1из 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 2011 Solved


1. Write a program to input a natural number less than 1000 and display it in
words.
Test your program on the sample data and some random data.

Sample input and output of the program.


Input: 29
Output: TWENTY NINE
Input: 17001
Output: OUT OF RANGE
Input: 119
Output: ONE HUNDRED AND NINETEEN
Input: 500
Output: FIVE HUNDRED

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. Encryption is a technique of coding messages to maintain their secrecy. A String


array of size 'n' where 'n' is greater than 1 and less than 10, stores single
sentences (each sentence ends with a full stop) in each row of the array.
Write a program to accept the size of the array.
Display an appropriate message if the size is not satisfying the given condition.
Define a string array of the inputted size and fill it with sentences row-wise.
Change the sentence of the odd rows with an encryption of two characters ahead
of the original character. Also change the sentence of the even rows by storing
the sentence in reverse order.
Display the encrypted sentences as per the sample data given below.
Test your program on the sample data and some random data.
Input: n=4
IT IS CLOUDY. IT MAY RAIN. THE WEATHER IS FINE. IT IS COOL.
Output: KV KU ENQWFA. RAIN MAY IT. VJG YGCVJGT KU HKPG. COOL IS IT.
Input: n=13
Output: INVALID ENTRY

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;i< nos;i++)
s[i]=(br.readLine()).toUpperCase();

for(i=0;i< nos;i++)
{

String t;
s[i]=" "+s[i];// add a blank space before each sentence
l=s[i].length();

if(i%2==0){
t="";
for(j=0;j< l;j++){

// store the ASCII code of the character


int ch=s[i].charAt(j);
if(ch!=32 && ch!='.'){
ch=ch+2;//shift the letter two spaces
if(ch>90)//to maintain cyclic order
ch=ch-26;// subtract 26
}
//convert to character and add to a temporary string
t=t+(char)ch;
}

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]);
}
}
}

3. Design a program which accepts your date of birth in dd mm yyyy format. Check
whether the date entered is valid or not.
If it is valid, display "VALID DATE", also compute and display the day number of
the year for the date of birth. If it is invalid, display "INVALID DATE" and then
terminate the program.
Testing of the program
Input: Enter your date of birth in dd mm yyyy format 05 01 2010
Output: VALID DATE 5
Input: Enter your date of birth in dd mm yyyy format 03 04 2010
Output: VALID DATE 93
Input: Enter your date of birth in dd mm yyyy format 34 06 2010
Output: INVALID DATE

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?
Donald Duck comics were banned from Finland because he doesn't wear trousers.
Quote Of The Day
Youth comes but once in a lifetime. - G. K. Chesterton
View all quotes
2014 Mentors. All Rights Reserved. Privacy Policy and Terms of Use
Mon Sep 01 2014 18:21:11 GMT+0530 (India Standard Time)

Вам также может понравиться