Escolar Documentos
Profissional Documentos
Cultura Documentos
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
corresponding to 'N' days after the generated date. Display error message if the
value of the day number, year and N are not within the limit or not according to
the condition specified. Test your program for the following data and some
random data.
Example:
INPUT : DAY NUMBER : 233 YEAR : 2008 DATE AFTER(N) : 17
OUTPUT: 20TH AUGUST 2008 DATE AFTER 17 DAYS : 6TH SEPTEMBER 2008
INPUT : DAY NUMBER : 360 YEAR : 2008 DATE AFTER(N) : 45
OUTPUT: 25TH DECEMBER 2008 DATE AFTER 45 DAYS : 8TH FEBRUARY 2009
View/Hide Solution
import java.util.*;
class ISCprac2009q01{
public static void main(String args[])
throws InputMismatchException{
if(day_number<1 || day_number>366)
System.out.println("INVALID DAY NUMBER.");
else if(year<1000 || year >9999)
System.out.println("INVALID YEAR");
i=0;
//FIND THE DATE CORRESPONDING TO THE DAY NUMBER
day=day_number;
while(day>month_days[i])
{
day-=month_days[i];
i++;
}
month=i;
//ADD SUFFIX AS PER THE DAY
if(day%10==1 && day/10!=1)
suffix="ST";
else if(day%10==2 && day/10!=1)
suffix="ND";
suffix="ND";
else if(day%10==3 && day/10!=1)
suffix="RD";
else
suffix="TH";
//SECOND PART OF THE OUTPUT
System.out.println(day+suffix+" "+
month_names[month]+" "+year);
}
}
}
4.
5.
6.
7.
OUTPUT :
8.
ORIGINAL MATRIX :
9.
10.
11.
12.
REARRANGED MATRIX :
13.
14.
15.
16.
BOUNDARY ELEMENTS :
17.
18.
19.
4
5
View/Hide Solution
import java.util.*;
class ISCprac2009q02{
public static void main(String args[])
throws InputMismatchException{
Scanner scan=new Scanner(System.in);
else{
int a[][]=new int[m][n];
int i,j,x,t,c;
System.out.println("Enter "+m*n+" elements for the matrix : ");
for(i=0;i< m;i++)
{
for(j=0;j< n;j++)
a[i][j]=scan.nextInt();
}
System.out.println("\nOriginal Matrix : ");
for(i=0;i< m;i++)
{
for(j=0;j< n;j++)
System.out.print(a[i][j]+" ");
System.out.println();
}
for(i=1;i< m;i++)
a[i][n-1]=b[c++];
for(i=n-2;i>=0;i--)
a[m-1][i]=b[c++];
for(i=m-2;i> 0;i--)
a[i][0]=b[c++];
System.out.println();
}
System.out.println("BOUNDARY ELEMENTS : ");
for(i=0;i< m;i++)
{
for(j=0;j< n;j++)
if(i==0 || j==0 || i==m-1 || j==n-1)
System.out.print(a[i][j]+" ");
else
System.out.print("
");
System.out.println();
}
}
}//end of main
}//end of class
20. Read a single sentence which terminates with a full stop(.). The words are to be
separated with a single blank space and are in lower case. Arrange the words
contained in the sentence according to the length of the words in ascending
order. If two words are of the same length then the word occurring first in the
input sentence should come first. For both, input and output the sentence must
begin in upper case.
Test your program for the following data and some random data.
INPUT : The lines are printed in reverse order.
OUTPUT : In the are lines order printed reverse.
INPUT : Print the sentence in ascending order.
OUTPUT : In the print order sentence ascending.
View/Hide Solution
import java.io.*;
public class ISC2009q03
{
public static void main()throws IOException
{
BufferedReader br=new BufferedReader(
new InputStreamReader(System.in));
System.out.println("Enter the string : ");
String str=br.readLine();
int l=str.length();
String a[]=new String[l];
int p=0,x=0,i,j;
String t;
for(i=0;i< l;i++)
{
char ch=str.charAt(i);
if(ch==' '||ch=='.')
{
a[x]=str.substring(p,i);
System.out.print(a[x]+" ");
x++;
p=i+1;
}
}
System.out.println();
for(i=0;i< x;i++)
{
for(j=0;j< x-i-1;j++)
{
if(a[j].length() > a[j+1].length())
{
t=a[j];
a[j]=a[j+1];
a[j+1]=t;
}
}
}
String s=a[0];
char ch=s.charAt(0);
System.out.print(Character.toUpperCase(ch));
System.out.print(s.substring(1));
for(i=1;i< x;i++)
{
System.out.print(" "+a[i]);
}
System.out.print(".");
}}
Recently Registered
Guess Questions
Ask a Question
View All Questions
Do you know?
The strongest muscle in proportion to its size in the human body is the tongue.
Quote Of The Day
Much education today is monumentally ineffective. All too often we are giving young people cut
flowers when we should be teaching them to grow their own plants. - Mae West
View all quotes
2014 Mentors. All Rights Reserved. Privacy Policy and Terms of Use
Mon Sep 01 2014 18:23:03 GMT+0530 (India Standard Time)