Guess Questions for ISC Computer Practical

Enter date of submission, number of days given to complete the project and find the date of announcement of project.

/*
* Enter date of submission, number of days given to complete
* the project and find the date of announcement of project.
*/
import java.util.*;
class DateOfAnnouncement
{
public static void main (String args[])throws InputMismatchException
{
Scanner scan = new Scanner(System.in);
int dd, mm, yy, nod,i,tdays = 0,m;
System.out.println("Enter the day, month and year of the date of announcement of the project: ");
dd = scan.nextInt();
mm = scan.nextInt();
yy = scan.nextInt();
System.out.println("Enter the no of days given to complete the project: ");
nod = scan.nextInt();
int dom[] = {31,28,31,30,31,30,31,31,30,31,30,31};
// If it is a leap year, februrary should have 29 days.
if(yy%4 == 0)
dom[1] = 29;
// Add the days of the month
for(i = 0; i< mm-1; i++)
tdays+= dom[i];
// Add the days of the current month
tdays+= dd;
// Subtract the number of days given to complete the project from total days
tdays-= nod;
// Now convert the total calculated days to date
// If the result is negative that means the project was announced
// in the previous year
if(tdays < 0)
{
yy--;
// If the previous year was a leap year, add 366 to get the corresponding
// day of that year else add 365
if(yy%4 == 0)
tdays += 366;
else
tdays += 365;
}
if(yy%4 == 0)
dom[1] = 29;
else
dom[1] = 28;
m=0;
while(tdays>dom[m]){
tdays-= dom[m];
m++;
}
System.out.println("Date of announcement: " + tdays + "/" + (m+1) + "/" + yy);
}//end of main
}//end of class

WAP to enter the current date in dd/mm/yyyy format and the day name on the 1st of January of that year. Display the name of the day on the given date.

/* Write a program to accept a date in the string format dd/mm/yyyy
* and accept the name of the day
* on 1st of January of the corresponding year. Find the day for the given date.
Example:
INPUT Date: 5/7/2001 Day on 1st January : MONDAY
OUTPUT Day on 5/7/2001 : THURSDAY
Test run the program on the following inputs:
INPUT DATE DAY ON 1ST JANUARY OUTPUT DAY FOR INPUT DATE
4/9/1998 THURSDAY FRIDAY
31/8/1999 FRIDAY TUESDAY
6/12/2000 SATURDAY WEDNESDAY
The program should include the part for validating the inputs namely the date
and the day on 1st January of that year.
*/
import java.util.*;
class CurrentDayName
{
public static void main (String args[])
throws InputMismatchException
{
Scanner scan = new Scanner(System.in);
int i,dd,mm,yy,tdays, index,r;
String date,dayName;
System.out.println("Enter a date in the string format dd/mm/yyyy: ");
System.out.println("If the date is 9th Februaray,
2013 enter it as 09/02/2013. ");
date = scan.next();
dd=mm=yy=0;
// Convert the date in string format to day, month and year
try{
dd = Integer.parseInt(date.substring(0,2));
mm = Integer.parseInt(date.substring(3,5));
yy = Integer.parseInt(date.substring(6));
System.out.println("Enter the name of the day on 1st of January ");
dayName = scan.next();
//Store the days of the months
int dom[] = {31,28,31,30,31,30,31,31,30,31,30,31};
//If it is a leap year, februrary should have 29 days.
if(yy%4 == 0)
dom[1] = 29;
if(dd < 0 || dd > dom[mm-1]){
System.out.println("Invalid date.");
}else{
//Store the day names of the week
String days[] = {"Monday", "Tuesday", "Wednesday", "Thursday",
"Friday", "Saturday", "Sunday"};
//Find the corresponding day of the year
tdays = 0;
//Add the days of the month
for(i = 0; i < mm-1; i++)
tdays+= dom[i];
//Add the days of the current month
tdays+= dd;
index = 0;
//Find the index of the entered day name in the day names array
for(i = 0; i < 7; i++)
{
if(dayName.equalsIgnoreCase(days[i])){
index = i;
break;
}
}
//find the index of the day in the day names array for the current day
r = tdays%7 + index - 1;
if( r >= 7)
r -= 7;
System.out.println("Day on " + date + " : " + days[r]);
} // else
}catch(Exception e){
System.out.println("Please enter the date in the specified format.");
System.out.println("Error : "+e);
}
}//end of main
}//end of class

WAP to enter two dates of the same year and find the number of days elapsed between them.

Enter n sentences and merge them to form a single sentence, where n <= 10. The merged sentence should not have duplicate words and must only consist of letters and blank spaces. Any other character should be removed.

Enter date of announcement, number of days given to complete the project and find the date of submission of project.

/* Enter date of announcement, number of days given to complete the project and
* find the date of submission of project.
*/
import java.util.*;
class DateOfSubmission
{
public static void main (String args[])throws InputMismatchException
{
Scanner scan = new Scanner(System.in);
int dd, mm, yy, nod,i,tdays=0,m;
System.out.println("Enter the day, month and year of the date of
announcement of the project: ");
dd = scan.nextInt();
mm = scan.nextInt();
yy = scan.nextInt();
System.out.println("Enter the no of days given to complete the project: ");
nod = scan.nextInt();
int dom[] = {31,28,31,30,31,30,31,31,30,31,30,31};
//If it is a leap year, februrary should have 29 days.
if(yy%4 == 0)
dom[1] = 29;
//Add the days of the month
for(i=0; i< mm-1; i++)
tdays+=dom[i];
//Add the days of the current month
tdays+=dd;
//Add the number of days given to complete the project
tdays+=nod;
//Now convert the total calculated days to date
// If the days exceed the total number of days in a year
// Increment the year by one
if(yy%4 == 0){
if(tdays > 366){
tdays-=366;
yy++;
}
}else{
if(tdays > 365){
tdays-=365;
yy++;
}
}
if(yy%4 == 0)
dom[1] = 29;
else
dom[1] = 28;
m=0;
while(tdays>dom[m]){
tdays-=dom[m];
m++;
}
System.out.println("Date of submission: "+tdays+"/"+(m+1)+"/"+yy);
}//end of main
}//end of class

A number with n digits, which, when multiplied by 1, 2, 3, ..., n produces the same digits in a different order is known as a Cyclic Number. For example, 142857 is a cyclic number: 142857 x 2 = 285714; 142857 x 3 = 428571; 142857 x 4 = 571428; 142857 x 5 = 714285; 142857 x 6 = 857142, and so on. Write a program to enter a number and check if it is a cyclic number or not.

A number that is smaller than the sum of its aliquot parts (proper divisors) is known as an Abundant Number. Twelve is the smallest abundant number - the sum of its aliquot parts is 1 + 2 + 3 + 4 + 6 = 16 - followed by 18, 20, 24, and 30.

A number such that both the sum of its divisors and the number of its divisors are perfect numbers is known as a Sublime Number. The smallest sublime number is 12. There are 6 divisors of 12 - 1, 2, 3, 4, 6, and 12 - the sum of which is 28. Both 6 and 28 are perfect. Write a program to check if a number is a sublime number or not.