Академический Документы
Профессиональный Документы
Культура Документы
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
View/Hide Solution
import java.util.*;
class ISCprac2011q01{
public static void main(String args[])
throws InputMismatchException{
int n;
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"};
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());
}
}
}
View/Hide Solution
import java.io.*;
class ISCprac2011q02{
public static void main(String args[])
throws IOException{
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];
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++){
}
}
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{
s+=d;
System.out.print(s);
}else{
System.out.print("INVALID DATE");
}
}
}
Recently Registered
Guess Questions
Ask a Question