Computer Last Year Program
Computer Last Year Program
1.
import java.util.Scanner;
int rev = 0;
while (num != 0)
rev = rev * 10 + d;
num /= 10;
return rev;
int c = 0;
{
if (num % i == 0)
c++;
return c == 2;
int m = in.nextInt();
int n = in.nextInt();
int count = 0;
if (m >= n)
System.out.println("INVALID INPUT");
return;
if (adam)
if (prime)
count++;
}
if (count == 0)
System.out.print("NIL");
System.out.println();
2.
import java.util.Scanner;
int m = in.nextInt();
int n = in.nextInt();
System.out.println("OUT OF RANGE");
return;
{
System.out.println("ENTER ELEMENTS FOR ROW " + (i + 1) + ": ");
a[i][j] = in.nextInt();
System.out.println("INVALID INPUT");
return;
int decNum = 0;
System.out.print("\t\t" + decNum);
System.out.println();
3.
import java.util.*;
{
StringTokenizer st = new StringTokenizer(ipStr);
strArr[i] = st.nextToken();
String t = strArr[j];
strArr[j] = strArr[j+1];
strArr[j+1] = t;
String t = strArr[j];
strArr[j] = strArr[j+1];
strArr[j+1] = t;
sb.append(strArr[i]);
sb.append(" ");
}
return sb.toString().trim();
System.out.println("Enter a sentence:");
System.out.println();
System.out.println("INVALID INPUT");
return;
System.out.println(str);
System.out.println(sortedStr);
//2019
1.
import java.util.Scanner;
if (y % 400 == 0) {
ret = true;
else if (y % 100 == 0) {
ret = false;
else if (y % 4 == 0) {
ret = true;
else {
ret = false;
return ret;
int monthDays[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
if (leap) {
monthDays[1] = 29;
int i = 0;
int daySum = 0;
break;
sb.append(date);
sb.append("TH ");
sb.append(monthNames[i]);
sb.append(", ");
sb.append(year);
return sb.toString();
System.out.print("YEAR: ");
int n = in.nextInt();
return;
}
if (n < 1 || n > 100) {
return;
nYear = nYear + 1;
nYear = nYear + 1;
System.out.println();
2.
import java.util.Scanner;
public class Array
int n = arr.length;
int t = arr[j];
arr[j] = arr[j+1];
arr[j+1] = t;
int n = in.nextInt();
return;
sortArray(a);
System.out.println("SORTED ARRAY:");
b[r][j] = a[j];
System.out.println();
System.out.println("FILLED MATRIX:");
System.out.println();
3.
import java.util.*;
public class Palindrome
palin = false;
break;
return palin;
int i = len - 1;
i--;
sb.append(word.charAt(j));
}
return sb.toString();
if (lastChar != '.'
System.out.println("INVALID INPUT");
return;
while (st.hasMoreTokens()) {
if (isPalinWord) {
sb.append(word);
else {
sb.append(palinWord);
}
sb.append(" ");
System.out.println();
System.out.println(ipStr);
System.out.println(convertedStr);
//2018
1.
import java.util.Scanner;
int c = 0;
if (num % i == 0) {
c++;
return c == 2;
int n = in.nextInt();
return;
if (n % 2 != 0) {
return;
int a = 3;
int b = 0;
while (a <= n / 2) {
b = n - a;
a += 2;
2.
import java.util.Scanner;
public class ArraySort
int m = in.nextInt();
int n = in.nextInt();
return;
a[i][j] = in.nextInt();
System.out.println("ORIGINAL MATRIX");
System.out.println();
int t = a[i][k];
a[i][k] = a[i][k+1];
a[i][k+1] = t;
System.out.println();
3.
import java.util.Scanner;
int n = in.nextInt();
in.nextLine();
if (n <= 2 || n >= 9) {
System.out.println("INVALID INPUT");
return;
int highLen = 0;
teams[i] = in.nextLine();
highLen = teams[i].length();
if (i >= len) {
System.out.print(" \t");
else {
System.out.print(teams[j].charAt(i) + "\t");
System.out.println();
}
//2017
1.
import java.util.Scanner;
int n = in.nextInt();
System.out.println("INVALID INPUT");
return;
int total = 0;
int t = n;
t = t % cartonSizes[i];
total += cartonCount;
if (cartonCount != 0) {
if (t != 0) {
System.out.println("Remaining boxes = " + t
total++;
else {
2.
import java.util.Scanner;
int n = in.nextInt();
return;
answers[i][j] = in.next().charAt(0);
key[i] = in.next().charAt(0);
int hScore = 0;
System.out.println("Scores:");
if (answers[i][j] == key[j]) {
score[i]++;
hScore = score[i];
System.out.println("Highest Score:");
3.
import java.util.Scanner;
System.out.println("INVALID LENGTH");
return;
char ch = str.charAt(i);
if ((ch >= 'A' && ch <= 'M') || (ch >= 'a' && ch <= 'm')) {
sb.append((char)(ch + 13));
else if ((ch >= 'N' && ch <= 'Z') || (ch >= 'n' && ch <= 'z')) {
sb.append((char)(ch - 13));
}
else {
sb.append(ch);
System.out.println(cipher);
//2016
1.
import java.util.Scanner;
int c = 0;
if (num % i == 0) {
c++;
return c == 2;
int c = 0;
while (num != 0) {
c++;
num /= 10;
return c;
int n = in.nextInt();
if (n <= 0) {
System.out.println("INVALID INPUT");
return;
if (isPrime(n)) {
System.out.println(n);
int n2 = n;
int t1 = n2 / divisor;
int t2 = n2 % divisor;
n2 = t2 * 10 + t1;
System.out.println(n2);
if (!isPrime(n2)) {
isCircularPrime = false;
break;
else {
isCircularPrime = false;
if (isCircularPrime) {
else {
2.
import java.util.Scanner;
int m = in.nextInt();
return;
a[i][j] = in.nextInt();
if (a[i][j] < 0) {
System.out.println("INVALID INPUT");
return;
System.out.println("ORIGINAL MATRIX");
printMatrix(a, m);
sortNonBoundaryMatrix(a, m);
System.out.println("REARRANGED MATRIX");
printMatrix(a, m);
computePrintDiagonalSum(a, m);
int k = 0;
b[k++] = a[i][j];
}
for (int i = 0; i < k - 1; i++) {
int t = b[j];
b[j] = b[j+1];
b[j+1] = t;
k = 0;
a[i][j] = b[k++];
int sum = 0;
System.out.println("DIAGONAL ELEMENTS");
if (i == j || i + j == m - 1) {
sum += a[i][j];
System.out.print(a[i][j] + "\t");
else {
System.out.print("\t");
}
}
System.out.println();
System.out.print(a[i][j] + "\t");
System.out.println();
3.
import java.util.*;
if (lastChar != '.'
System.out.println("INVALID INPUT");
return;
int c = 0;
while (st.hasMoreTokens()) {
if (isVowel(word.charAt(0))
c++;
sbVowel.append(word);
sbVowel.append(" ");
else {
sb.append(word);
sb.append(" ");
System.out.println(newStr);
}
public static boolean isVowel(char ch) {
ch = Character.toUpperCase(ch);
if (ch == 'A'
|| ch == 'E'
|| ch == 'I'
|| ch == 'O'
|| ch == 'U')
ret = true;
return ret;
//2015
1.
import java.util.*;
class Number
private int M, N;
String output;
this.M = M;
this.N = N;
output = "";
status = false;
{
int M = this.M;
int sum = 0;
do {
sum = sumOfDigits(M);
if (sum == N)
status = true;
M++;
if (M == Integer.MAX_VALUE)
status = false;
break;
return status;
int sum = 0;
return sum;
}
int count = 0;
count++;
return count;
return output;
class ISC2015Q1
System.out.print("INPUT:\tM = ");
int M = in.nextInt();
System.out.print("\tN = ");
int N = in.nextInt();
System.out.println("OUTPUT:\tINVALID INPUT");
} else
num.findSolution();
if (num.hasSolution())
System.out.println(num);
} else
in.close();
2.
import java.util.*;
class Matrix
public Matrix(int M)
A = new int[M][M];
this.M = M;
A[row][col] = in.nextInt();
}
in.close();
output += "\t";
output += A[row][col];
if (col < M)
output += "\t";
output += "\n";
return output;
temp = A[M-x-1][i];
A[M-x-1][i]=A[M-i-1][M-x-1];
A[M-i-1][M-x-1]=A[x][M-i-1];
A[x][M-i-1]=A[i][x];
A[i][x]=temp;
}
}
return A[0][0]+A[0][M-1]+A[M-1][M-1]+A[M-1][0];
System.out.print("INPUT:\tM = ");
int M = in.nextInt();
objMatrix.getInput();
System.out.println("OUTPUT:");
System.out.println("ORIGINAL MATRIX");
System.out.println(objMatrix);
objMatrix.rotate();
System.out.println(objMatrix);
else
in.close();
}
3.
import java.util.*;
class Sentence
this.sentence = sentence;
return output.trim();
}
private static boolean isConsonant(char ch)
char ch;
vowels = 0; consonants = 0;
ch = titleCase.charAt(position);
if (isVowel(ch))
vowels++;
else if (isConsonant(ch))
consonants++;
class ISC2015Q3
System.out.print("INPUT:\t");
System.out.print("OUTPUT:\t");
if (objSentence.isValid())
System.out.println(objSentence);
objSentence.displayStats();
} else
System.out.println("INVALID INPUT");
in.close();
//2014
1.
import java.util.*;
class CompositeMagicNumber
String output;
this.m = m;
this.n = n;
{
frequency = 0;
frequency++;
output+=i+", ";
output=output.substring(0,output.length()-2);
return output;
return frequency;
if (n < 2)
return false;
else if (n == 2)
return true;
else if (n % 2 == 0)
return false;
else
if (n % divisor == 0)
return false;
return true;
return !isPrimeNumber(n);
return n % 9 == 1;
class ISC2014Q1
System.out.print("INPUT:\tm = ");
int m = in.nextInt();
System.out.print("\tn = ");
int n = in.nextInt();
System.out.print("OUTPUT:\t");
if (m < n)
obj.process();
System.out.println(obj);
} else
System.out.println("INVALID INPUT");
in.close();
2.
import java.util.*;
class Matrix
public Matrix(int M)
this.M = M;
A = new int[M][M];
output += "\t";
output += A[row][col];
if (col < M - 1)
output += "\t";
}
output += "\n";
return output;
A[row][col]=in.nextInt();
in.close();
return true;
sumOfLeftDiagonal+=A[i][i];
sumOfRightDiagonal+=A[i][M-1-i];
class ISC2014Q2
System.out.print("INPUT:\tM = ");
int M = in.nextInt();
objMatrix.getInput();
System.out.println("OUTPUT:\tORIGINAL MATRIX");
System.out.println(objMatrix);
if(objMatrix.isSymmetric())
}else
objMatrix.computeAndDisplaySumOfDiagonals();
} else
{
System.out.println("OUTPUT:\tTHE MATRIX SIZE IS OUT OF RANGE");
in.close();
3.
import java.util.*;
class Sentence
this.source = source;
terminator = source.charAt(source.length()-1);
answer="";
System.out.println(Arrays.toString(wordList));
int wordCount=0;
if(word.length()==0) continue;
wordCount++;
return answer.trim();
class ISC2014Q3
System.out.print("INPUT:\t");
if(objSentence.isValid())
objSentence.delete(wordToBeDeleted,position);
System.out.println("OUTPUT:\t"+objSentence);
else
System.out.println("OUTPUT:\tINVALID INPUT.");
in.close();
}
}
//2013
1.
import java.util.*;
class ISBN
this.isbn = isbn;
if (isbn.length() != 10)
if (!Character.isDigit(isbn.charAt(position)))
computeSum();
int digit;
{
digit = isbn.charAt(position) - '0';
return sum;
class ISC2013Q1
System.out.print("INPUT CODE:\t");
try
if (objISBN.getSum() % 11 == 0)
} else
catch (IllegalArgumentException e)
{
System.out.println("OUTPUT : INVALID INPUT");
in.close();
2.
import java.util.*;
class Matrix
private int M;
public Matrix(int M)
this.M = M;
A=new int[M][M];
A[row][col]=in.nextInt();
in.close();
String output="";
for( int row=0; row<M;row++)
output+="\t";
output+=A[row][col];
if(col<M-1)
output+="\t";
output+="\n";
return output;
int temp;
temp=A[row][col];
A[row][col]=A[row][M-1-col];
A[row][M-1-col]=temp;
{
Scanner in = new Scanner(System.in);
System.out.print("INPUT:\tM = ");
int M = in.nextInt();
objMatrix.getInput();
System.out.println("OUTPUT:\tORIGINAL MATRIX");
System.out.println(objMatrix);
objMatrix.mirror();
System.out.println(objMatrix);
else
in.close();
3.
import java.util.*;
class Palindrome
this.sentence = sentence;
frequency = 0;
answer = "";
process();
return false;
return true;
char ch;
ch = sentence.charAt(position);
if(delimters.indexOf(ch)>=0)
if(isPalindrome(word))
answer+=word+" ";
frequency++;
word="";
else
word+=ch;
}
return frequency;
return answer.trim();
System.out.print("INPUT:\t");
System.out.print("OUTPUT:\t");
if(objPalindrome.getFrequency()>0)
System.out.println(objPalindrome);
else
in.close();
}
//2012
1.
import java.util.*;
class ISBN
this.isbn = isbn;
if (isbn.length() != 10)
if (!Character.isDigit(isbn.charAt(position)))
computeSum();
int digit;
for (int position = 0; position < isbn.length(); position++)
return sum;
class ISC2013Q1
System.out.print("INPUT CODE:\t");
try
if (objISBN.getSum() % 11 == 0)
else
}
}
catch (IllegalArgumentException e)
in.close();
2.
import java.util.*;
class Matrix
private int M;
public Matrix(int M)
this.M = M;
A=new int[M][M];
A[row][col]=in.nextInt();
in.close();
}
public String toString()
String output="";
output+="\t";
output+=A[row][col];
if(col<M-1) output+="\t";
output+="\n";
return output;
int temp;
temp=A[row][col];
A[row][col]=A[row][M-1-col];
A[row][M-1-col]=temp;
{
public static void main(String[] args)
System.out.print("INPUT:\tM = ");
int M = in.nextInt();
objMatrix.getInput();
System.out.println("OUTPUT:\tORIGINAL MATRIX");
System.out.println(objMatrix);
objMatrix.mirror();
System.out.println(objMatrix);
else
in.close();
3.
import java.util.*;
class Palindrome
this.sentence = sentence;
frequency = 0;
answer = "";
process();
return false;
return true;
char ch;
ch = sentence.charAt(position);
if(delimters.indexOf(ch)>=0)
if(isPalindrome(word))
answer+=word+" ";
frequency++;
word="";
else
{
word+=ch;
return frequency;
return answer.trim();
System.out.print("INPUT:\t");
System.out.print("OUTPUT:\t");
if(objPalindrome.getFrequency()>0)
System.out.println(objPalindrome);
else
in.close();
//2012
1.
import java.util.*;
class PrimePalindrome
this.m=m;
this.n=n;
process();
if(n<2)
return false;
else if(n==2)
return true;
else if(n%2==0)
return false;
else
if(n%divisor==0)
return false;
return true;
int reverse=0;
reverse=reverse*10+(temp%10);
return n==reverse;
output="";
frequency=0;
frequency++;
output+=number+", ";
output=output.substring(0,output.length()-2);
return output;
}
return frequency;
class ISC2012Q1
System.out.print("INPUT:\tm = ");
int m = in.nextInt();
System.out.print("\tn = ");
int n = in.nextInt();
System.out.println(obj);
else
System.out.println("OUTPUT:\tOUT OF RANGE");
in.close();
2.
import java.util.*;
class Sentence
this.sentence=sentence.substring(0, sentence.length()-1);
process();
length=word.length;
sort(word);
output="";
output+=w+" ";
output=output.trim();
String temp;
boolean swapped;
swapped=false;
if(word[pos+1].compareTo(word[pos])<0)
{
temp=word[pos+1];
word[pos+1]=word[pos];
word[pos]=temp;
swapped=true;
if(!swapped)
break;
return length;
return output;
System.out.print("INPUT:\n\t");
System.out.println("\tREARRANGED SENTENCE");
System.out.println("\t"+obj);
in.close();
3.
import java.util.*;
class Matrix
A = new int[M][N];
this.M = M;
this.N = N;
A[row][col] = in.nextInt();
in.close();
min = A[startRow][startCol];
minRow = startRow;
minCol = startCol;
for (int row = startRow; row < M; row++)
startCol = 0;
min = A[row][col];
minRow = row;
minCol = col;
max = A[startRow][startCol];
maxRow = startRow;
maxCol = startCol;
startCol=0;
max = A[row][col];
maxRow = row;
maxCol = col;
}
}
output += "\t";
output += A[row][col];
if (col<N-1)
output += "\t";
output += "\n";
return output;
computeMaxiumPosition(0,0);
computeMinimumPosition(0,0);
int temp;
computeMinimumPosition(row, col);
temp = A[minRow][minCol];
A[minRow][minCol] = A[row][col];
A[row][col] = temp;
System.out.print("INPUT:\tM = ");
int M = in.nextInt();
System.out.print("\tN = ");
int N = in.nextInt();
obj.getInput();
System.out.println("OUPUT:");
System.out.println("ORIGINAL MATRIX");
System.out.println(obj);
obj.showMaxDetails();
obj.showMinDetails();
obj.sortAscending();
System.out.println("REARRANGED MATRIX");
System.out.println(obj);
else
in.close();
//2012
1.
import java.util.*;
class Number
private int n;
public Number(int n)
this.n = n;
answer ="";
convertToWords();
String arr1[] = { "ONE", "TWO", "THREE", "FOUR", "FIVE", "SIX","SEVEN", "EIGHT", "NINE",
"TEN", "ELEVEN", "TWELVE","THIRTEEN", "FOURTEEN", "FIFTEEN", "SIXTEEN", "SEVENTEEN",
"EIGHTEEN", "NINETEEN", "TWENTY", "THIRTY", "FOURTY", "FIFTY", "SIXTY", "SEVENTY", "EIGHTY",
"NINETY" };
if (quotient > 0)
else
if (ones != 0)
else
if(number ==0)
break;
}
return answer.trim();
class ISC2011Q1
System.out.print("INPUT:\t");
int n=in.nextInt();
if(n>0&&n<1000)
System.out.println("OUTPUT:\t"+obj);
else
in.close();
2.
import java.util.*;
class Encrypt
{
private String sentence[],answer;
this.sentence = sentence.clone();
answer = "";
encrypt();
int lineCount = 0;
char ch;
output ="";
lineCount++;
if (lineCount % 2 == 1)
ch = line.charAt(position);
if (Character.isLetter(ch))
output=output+ch;
}
else
words=line.split(" ");
output=output.trim();
output+=".";
answer+=output+"\n";
return answer;
class ISC2011Q2
System.out.print("INPUT:\tn=");
int n=in.nextInt();
in.nextLine();
{
sentence[i] = in.nextLine();
System.out.println("OUTPUT:");
System.out.println(obj);
else
System.out.println("OUTPUT\t:INVALID ENTRY");
in.close();
3.
import java.util.*;
class MyDate
private static int days[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
this.dd = dd;
this.mm = mm;
this.yyyy = yyyy;
if (isLeap())
days[1] = 29;
if (yyyy < 0)
return false;
return false;
return false;
return true;
dayNumber += days[i];
return dayNumber;
class ISC2011Q3
System.out.print("\t");
dd = in.nextInt();
System.out.print("\t");
mm = in.nextInt();
System.out.print("\t");
yyyy = in.nextInt();
if (obj.isValidDate())
else
System.out.println("Output:\n\tINVALID DATE");
in.close();