Professional Documents
Culture Documents
and
display the corresponding date. Also, accept ‘N’ (1 <= N <= 100) from the user to compute and display the
future date corresponding to ‘N’ days after the generated date. Display an error message if the value of the day
number, year and N are not within the limit or not according to the condition specified.
import java.util.*;
class ISC2019Q1 {
do {
day_num = sc.nextInt();
do {
yr = sc.nextInt();
if(Integer.toString(yr).length()!=4)
System.out.println("INVALID YEAR:");
}while(Integer.toString(yr).length()!=4);
do {
N = sc.nextInt();
date.setDate(day_num,yr,N);
System.out.println("OUTPUT:");
date.dateSpecifier();
}
private boolean flag;private static boolean leap;
String[] months =
{"January","Feburary","March","April","May","June","July","August","Sepetember","October","November","
December"};
int[] mdays={31,28,31,30,31,30,31,31,30,31,30,31};
int[] ldays={31,29,31,30,31,30,31,31,30,31,30,31};
this.dayNumber = dayNumber;
this.year = year;
this.dayAfter = dayAfter;
int m = 0,k=1;
k = 1;
m++;
k++;
String prefix;
k = 1;
m++;
year++;
m = 0;
k++;
if(year%400==0)
leap=true;
else if (year%100==0)
leap=false;
else if (year%4==0)
leap=true;
else
leap=false;
return leap;
Write a program to declare a single dimensional array a[ ] and a square matrix b[ ] [ ] of size N, where N>2 and
N<10. Allow the user to input positive integers into the single dimensional array. Perform the following tasks
on the matrix: (a) Sort the elements of the single dimensional array in ascending order using any standard
sorting technique and display the sorted elements. (b) Fill the square matrix b[ ][ ] in the following format.
If the array a[ ] = { 5, 2, 8, 1 } then, after sorting a[ ] = {1, 2, 5, 8} Then, the matrix b[ ][ ] would fill as below:
1258
1251
1212
1125
static int N;
N = sc.nextInt();
ar=new int[N];
ob.inputSingleDimArray();
ob.SortMatrix();
ob.inputElementsToTwoDimMatrix();
ob.displayMatrix();
else
System.out.println("INVALID INPUT:");
if(i+j < N)
Mat[i][j]=ar[j];
else
Mat[i][j]=ar[(i+j)-N];
}
public void inputSingleDimArray() {
for(int i=0;i<N;i++) {
ar[i]=sc.nextInt();
if(ar[i] <= 0) {
i--;
continue;
int temp;
for(int j=i;j<N;j++) {
temp = ar[j];
ar[j]=ar[i];
ar[i]=temp;
for(int k=0;k<N;k++)
System.out.print(" "+ar[k]);
System.out.println();
System.out.print(Mat[i][j]+" ");
System.out.println();
Write a program to accept a sentence which may be terminated by either ‘.’ , ‘?’ or ‘!’ only. The words are to be
separated by a single blank space and are in UPPER CASE. Perform the following tasks: (a) Check for the
validity of the accepted sentence.
(b) Convert the non-palindrome words of the sentence into palindrome words by concatenating the
word by its reverse (excluding the last character). Example: The reverse of the word HELP would be
LEH (omitting the last alphabet) and by concatenating both, the new palindrome word is
HELPLEH. Thus, the word HELP becomes HELPLEH. Note: The words which end with repeated
alphabets, for example ABB would become ABBA and not ABBBA and XAZZZ becomes
XAZZZAX
A Goldbach number is a positive even integer that can be expressed as the sum of two odd primes. Note: All
even integer numbers greater than 4 are Goldbach numbers. Write a program to accept an even integer ‘N’
where N > 9 and N < 50. Find all the odd prime pairs whose sum is equal to the number ‘N’
import java.util.*;
class Q1_2018
for(int x=2;x<=n/2;x++)
if(n%x==0)
return false;
}
return true;
void print(int n)
for(int x=2;x<=n;x++)
for(int y=x;y<=n;y++)
if(isPrime(x)&&isPrime(y)&&x+y==n)
System.out.println(x+","+y);
int n=sc.nextInt();
if(n%2==0)
ob.print(n);
else
{
System.out.println("INVALID INPUT.NUMBER OUT OF RANGE");
else
Write a program to declare a matrix A[ ] [ ] of order (M N) where ‘M’ is the number of rows and ‘N’ is the
number of columns such that the values of both ‘M’ and ‘N’ must be greater than 2 and less than 10. Allow the
user to input integers into this matrix. Perform the following tasks on the matrix: (a) Display the original
matrix. (b) Sort each row of the matrix in ascending order using any standard sorting technique. (c)
Display the changed matrix after sorting each row.
import java.util.*;
int i, j, n = a.length, tmp; //a.length gives the number of values in the 1D array
for(i=0;i<n;i++)
if(a[j]>a[j+1])
tmp = a[j];
a[j] = a[j+1];
a[j+1] = tmp;
}
}
int i, j;
for(j=0;j<a[i].length;j++) //a[i] gives one row at a time. a[i].length gives the number
of values in each row
System.out.print(a[i][j]+"\t");
System.out.println();
{ this function.
int i, j;
for(i=0;i<a.length;i++)
sort(a[i]);
}
m = sc.nextInt();
System.out.println("Enter the number of columns: ");
n = sc.nextInt();
if(m<3||m>9||n<3||n>9)
System.exit(0);
}
a = new int[m][n];
System.out.println("Enter the values for the matrix: ");
for(i=0;i<m;i++)
for(j=0;j<n;j++)
a[i][j] = sc.nextInt();
obj.display(a);
obj.sort2D(a);
System.out.println("Matrix after sorting rows: ");
obj.display(a);
}
import java.util.*;
String ar[];
int n, x,y;
n = sc.nextInt();
ar = new String[n];
for(x=0;x<n;x++)
ar[x] = sc.next();
int max = 0;
for(x=0;x<n;x++)
if(max<ar[x].length())
System.out.println("OUTPUT:" );
for(x=0;x<max;x++)
for(y=0;y<n;y++)
* than the length of the string else only tabular space will be printed
*/
if(x<ar[y].length())
{
System.out.print(ar[y].charAt(x)+"\t");
else
System.out.print("\t");
System.out.println();
else
System.out.println("INVALID INPUT");