100% found this document useful (1 vote)
168 views1,045 pages

Hands On Merged

1. The document contains code snippets for 7 different Java programs that deal with topics like calculating LCM, word repetition score, battery charging time, odd numbered students, billing amount calculation, uppercase/lowercase string conversion, and rating scores. 2. It provides the input and output for each program and includes the full Java code to find the LCM, calculate word repetition score, determine battery charging time, print odd numbered students, generate a billing amount, convert a string to uppercase/lowercase format, and calculate rating scores. 3. Alternative methods are also presented for some of the programs, like calculating LCM and word repetition score.

Uploaded by

BABAI GHOSH
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
168 views1,045 pages

Hands On Merged

1. The document contains code snippets for 7 different Java programs that deal with topics like calculating LCM, word repetition score, battery charging time, odd numbered students, billing amount calculation, uppercase/lowercase string conversion, and rating scores. 2. It provides the input and output for each program and includes the full Java code to find the LCM, calculate word repetition score, determine battery charging time, print odd numbered students, generate a billing amount, convert a string to uppercase/lowercase format, and calculate rating scores. 3. Alternative methods are also presented for some of the programs, like calculating LCM and word repetition score.

Uploaded by

BABAI GHOSH
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1045

JAVA

1. LCM OF DAY INTERVAL/LUNCH TOGETHER/DINNER TOGETHER

INPUT: Enter the day interval of Tony : 4


Enter the day interval of Potts: 6

OUTPUT: Tony and Potts will have dinner together on 12th day.

import java.util.Scanner;
public class lcm {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the day interval of Sam:");
int n1 = sc.nextInt();
System.out.println("Enter the day interval of Riya:");
int n2 = sc.nextInt();
if(n1<=0 || n2<=0)
{
System.out.println("Given interval is not valid");
return;
}
int lcm;
lcm = (n1 > n2) ? n1 : n2;
while(true) {
if( lcm % n1 == 0 && lcm % n2 == 0 ) {
System.out.printf("Sam and Riya will have their dinner on day "+lcm);
break;
}
++lcm;
}
}
}

ALTERNATE METHOD

import java.util.Scanner;
public class Lunchlcm {
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the day interval of Tony");
int n1=sc.nextInt();
System.out.println("Enter the day interval of Potts");
int n2=sc.nextInt();
if(n1<=0 && n2<=0)
{
System.out.println("Given interval is not valid");
return;
}
int a=n1;
int b=n2;
while(n2>0)
{
if (n1 > n2)
{
n1 = n1 - n2;
} else
{
n2 = n2 - n1;
}
}
int gcd = n1;
int lcm = (a * b) / gcd;

System.out.println("Tony and Potts will have lunch together on " + lcm + " day");
}
}

*********************************************************************************************
*********************************************************************************************
**
2.SCORE OF REPEATING WORDS/ WORD REPETITION

INPUT: Enter the String: GOOD


Enter the sentence: GOOD FOOD GOOD LIFE

OUTPUT: Score is 2

import java.util.*;
class PrintMessage
{
public static void main (String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the string");
String s=sc.next();
int count=0;
int sum=2;
for(int i=0;i<s.length();i++)
{
if(Character.isDigit(s.charAt(i)) || Character.isLetter(s.charAt(i)) || s.charAt(i)==' ')
{
continue;
}
else
{
System.out.println(s+" is not valid String");
return;
}
}
System.out.println("Enter the sentence");
sc.nextLine();
String sentence=sc.nextLine();
String[] w=sentence.split(" ");
for(int i=0;i<w.length;i++)
{
if(w[i].equalsIgnoreCase(s))
{
count++;
if(count>2)
{
sum=sum*2;
}
}
}
if(count>2)
{
System.out.println("Score is "+sum);
}
else
{
System.out.println("Score is"+count);
}
}
}

*ALTERNATE METHOD

import java.util.Scanner;
public class CountWords {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String word, sentence;ed
int count = 0;
System.out.println("Enter a word:");
word = in.nextLine();
System.out.println("Enter a sentence");
sentence = in.nextLine();

if (!(word.matches("[a-z]+"))) {
System.out.println("Invalid Input");
return;
}
String words[] = sentence.toLowerCase().split(" ");
for (int i = 0; i < words.length; i++) {
if (word.equals(words[i])) {
count++;
}
}
System.out.println("Score is:" + ((int) Math.pow(2, count - 1)));
}
}
*********************************************************************************************
*********************************************************************************************
***

3. BATTERY CAPACITY

INPUT: Enter battery capacity :1230


Enter charging current value: 400

OUTPUT: 3.69 Hours

import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter battery capacity:");
double capacity = sc.nextDouble();
if(!(capacity>=1000 && capacity<=10000)) {
System.out.println("Invalid battery capacity");
return;
}
System.out.println("Enter charging current value:");
double current = sc.nextDouble();
if(!(current>=300 && current<=2100)) {
System.out.println("Invalid output current");
return;
}
double time=0.0f;
time = (capacity/current)*1.2;
System.out.println(String.format("%.2f",time)+" Hours");
}

*********************************************************************************************
*********************************************************************************************
***
4.STUDENTS WHOSE ROLLNO ARE ODD

INPUT: Entr the set of students :5


Enter the roll number :1
3
4
5
6

OUTPUT: 135

import java.util.*;
public class Main
{
public static void main(String[] args) {
System.out.println("Enter the set of students");
Scanner s=new Scanner(System.in);
int setn=s.nextInt();
if(setn<=0)
{
System.out.println(setn+" is an invalid size");
return;
}
System.out.println("Enter the roll number");
int[] rolls=new int[setn];
int oddflag=0;
for(int i=0;i<setn;i++)
{
rolls[i]=s.nextInt();
if(rolls[i]<0)
{
System.out.println(rolls[i]+" is an invalid roll number");
return;
}
if(rolls[i]%2!=0)
{
oddflag=1;
}
}
if(oddflag==0)
{
System.out.println("The "+setn+" numbers are not odd");
return;
}
String str="";
for(int i=0;i<setn;i++)
{
if(rolls[i]%2!=0)
{
str=str+rolls[i];
}
}
for(int n=0;n<str.length();n++)
{
System.out.println(str.charAt(n)+" ");
}
}
}
*********************************************************************************************
*********************************************************************************************
**

5.CALCULATING BILL AMOUNT

INPUT : Enter your name : Sam


Enter the time duration: 13
List of payment options
1)Visa card
2)Rupay card
3)Master card
Choose an option : 2

OUTPUT: Dear Sam your bill amount is 1294.80

import java.util.*;
public class Main
{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter your name");
String s=sc.nextLine();double sal=0;double disc=0;
for(int i=0;i<s.length();++i)
{
if(!Character.isLetter(s.charAt(i)))
{
System.out.println("Invalid Name");
return;
}
}
System.out.println("Enter the time duration");
int n=sc.nextInt();int n1;
if(n<=0 || n>24)
{
System.out.println("Invalid duration");
return;
}
System.out.println("List of payment options");
System.out.println("1)Visa card");
System.out.println("2)Rupay card");
System.out.println("3)Master card");
System.out.println("Chosse an option");
while(true)
{
n1=sc.nextInt();
if(n1<0||n1>3)
{
System.out.println("Try again");
}
else
{
break;
}
}
if( n1==1)
{
if(n>=5)
{
sal=120*n;
disc=(sal*0.25);
sal=sal-disc;
}
else
{
sal=n*120;
}
}
if(n1==2)
{
if(n>=5)
{
sal=120*n;
disc=(sal*0.17);
sal=(120*n)-disc;
}
else
{
sal=n*120;
}
}
if(n1==3)
{
sal=n*120;
}
System.out.print("Dear "+s+" your bill amount is ");
System.out.printf("%.2f", sal);
}
}

*********************************************************************************************
*********************************************************************************************
***
6.ODD POSITION CHAR WILL BE IN UPPERCASE & EVEN WILL BE LOWERCASE-

INPUT : school

OUTPUT : sChOol

import java.util.Scanner;
public class UPLC{
public static void main(String []args){
Scanner sc = new Scanner(System.in);
String str = sc.next();
int strlen = str.length();
for(int i = 0 ; i < str.length(); i++){
char ch = str.charAt(i);
if(!(ch >= 'a' && ch <='z' || ch >= 'A' && ch <='Z' )){
System.out.println(str+ " is an invalid input");
return;
}
}

if(strlen >= 5 && strlen <= 20){


StringBuffer updateString = new StringBuffer();
char[] charArr = str.toCharArray();
for(int i = 0 ; i < charArr.length; i++){
char ch = charArr[i];
if(i % 2 != 0){
ch = Character.toUpperCase(ch);
}
updateString.append(ch);
}
System.out.println(updateString.toString());
}
else {
System.out.println(str+ " is an invalid Length");
}
}
}

*********************************************************************************************
*********************************************************************************************
****
7) RATING SCORE

INPUT: ENTER JESSON SCORE


1
2
3
4
8
ENTER JAMES SCORE
0
2
6
5
6

OUTPUT: JESSON SCORE : 2


JAMES SCORE : 2

import java.util.Scanner;
public class Ratingscore {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter Jesson Score");
int[] a1 = new int[5];
int[] a2 = new int[5];
int f = 0;
int t = 0;
int sum = 0;
int sum1 = 0;
for (int i = 0; i < 5; i++) {
a1[i] = sc.nextInt();
if (a1[i] < 0) {
f = 1;
t = a1[i];
break;
}
}
if (f == 1) {
System.out.println(t + " is invalid");
} else {
System.out.println("Enter James Score");
for (int j = 0; j < 5; j++) {
a2[j] = sc.nextInt();
if (a2[j] < 0) {
f = 1;
t = a2[j];
break;
}
}
if (f == 1) {
System.out.println(t + " is invalid");
} else {
for (int k = 0; k < 5; k++) {
if (a1[k] > a2[k]) {
sum++;
}
if (a1[k] < a2[k]) {
sum1++;
}
}
System.out.println("Jesson Score");
System.out.println(sum);
System.out.println("James Score");
System.out.println(sum1);
}
}
}
}

**ALTERNATE METHOD:

import java.util.Scanner;
public class minmax {
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
int jesson=0,james=0,c=0;
int a[]=new int[5];
int b[]=new int[5];
System.out.println("Enter Jesson Score");
for(int i=0;i<a.length;i++)
{
a[i]=sc.nextInt();
if(a[i]<0)
{
System.out.println("Invalid");
Runtime.getRuntime().halt(0);
}
}
System.out.println("Enter James Score");
for(int i=0;i<b.length;i++)
{
b[i]=sc.nextInt();
if(b[i]<0)
{
System.out.println("Invalid");
Runtime.getRuntime().halt(0);
}
}
if(a.length==b.length)
{
for(int i=0;i<a.length;i++)
{
if(a[i]>b[i])
{
jesson++;
}
else if(a[i]<b[i])
{
james++;
}
else if(a[i]==b[i])
{
c++;
}
}
System.out.println("Jesson Score: "+jesson);
System.out.println("James Score: "+james);
}
else{
System.out.println("Length not same");
}
}
}

*********************************************************************************************
*******************************************************************************

8.COUNT OF UPPERCASE AND COUNT OF LOWERCASE & OUTPUT WILL BE IN THE FORM OF (UP-LC
)

INPUT : HosTEL

OUTPUT: 4-2=2

import java.util.Scanner;

public class ContNext {


public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the string");
String str=sc.nextLine();
int uc=0,lc=0;
if(str.matches("[A-Za-z ]+")&&str.length()<10) {
for(int i=0;i<str.length();i++)
if(Character.isUpperCase(str.charAt(i))) {
uc++;
}
else if(Character.isLowerCase(str.charAt(i))){
lc++;
}
System.out.println(uc-lc);
}
}
}
*********************************************************************************************
*******************************************************************************
9) PRODUCT of COUNT of UPPERcase and LOWERcase letters

INPUT: ABsdEr

OUTPUT: 6 (3*3)

import java.util.Scanner;
public class minmax {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the String");
String s = sc.nextLine();
int upper = 0;
int lower = 0;
int i;
if (s.matches("[a-zA-Z]+")) {
for (i = 0; i < s.length(); i++) {
char c = s.charAt(i);
if (c >= 'A' && c <= 'Z') {
upper++;
}
if (c >= 'a' && c <= 'z') {
lower++;
}
}
System.out.println(upper * lower);
}
else
{
System.out.println("Invalid String");
}

}
}

*********************************************************************************************
******************************************************************************
10.Count of UPPERcase and LOWERcase and their difference

Enter the String: ColLEgE


Count of uppercase is : 4
Count of lowercase is : 3
Hence the ans is : 1

import java.util.Scanner;
public class MyClass {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the String ");
String str = sc.next();
int strlen = str.length();
for(int i =0; i < str.length() ; i++){
char ch = str.charAt(i);
if(!(ch >='a' && ch <= 'z' || ch >= 'A' && ch <= 'Z')){
System.out.println(str + " is an invalid String");
return;
}
}

if(strlen > 0 && strlen <= 10){


int upper = 0, lower = 0, ans = 0;

for(int i = 0; i < str.length(); i++)


{
char ch = str.charAt(i);
if (ch >= 'A' && ch <= 'Z')
upper++;
else if(ch >= 'a' && ch <= 'z')
lower++;
}
ans = upper - lower;
System.out.println("count of uppercase is :"+ upper);
System.out.println("count of lowercase is :"+ lower);
System.out.println("Hence the ans is :"+ ans);
}
else {
System.out.println(str + " is an invalid String");
}
}
}
*********************************************************************************************
*******************************************************************************
11.PUBLIC DISTRIBUTION

INPUT : OKR

OUTPUT : 90

import java.util.*;
public class Main
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
String str = in.nextLine();
int l=str.length();
if(l>5 || l<2)
{
System.out.println("Invalid Input");
}
else
{
int sum=0,flag=0;
for(int i=0;i<l;i++)
{
char c=str.charAt(i);
if(c=='O')
{
sum=sum+24;
}
else if(c=='K')
{
sum=sum+36;
}
else if(c=='S')
{
sum=sum+42;
}
else if(c=='R')
{
sum=sum+30;
}
else if(c=='W')
{
sum=sum+44;
}
else
{
flag=1;
}
}
if(flag==1)
{
System.out.println("Invalid Input");
}
else
{
System.out.println(sum);
}
}
}
}
*********************************************************************************************
******************************************************************************

12.LOTTERY TICKETS

INPUT: Enter the Starting range


23467
Enter the Ending range
23477

OUTPUT: 23469
23472

import java.util.*;
public class Main {
public static void main(String args[])
{
int i,c,n,sum,count;
sum=0;count=0;n=0;c=0;i=0;
Scanner sc = new Scanner(System.in);
System.out.println("Enter the Starting range");
int a = sc.nextInt();
String str = Integer.toString(a);
if(str.length()!=5)
{
System.out.println(str + " is an invalid input");
System.exit(0);
}

System.out.println("Enter the Ending range");


int b = sc.nextInt();
String str1 = Integer.toString(b);
if(str1.length()!=5)
{
System.out.println(str1 + "is an invalid input");
System.exit(0);
}

if(a>b)
{
System.out.println(a+" and "+b+" are invalid serial numbers");
System.exit(0);

}
for(i=a;i<=b;i++)
{
n=i;
while(n!=0)
{
c=n%10;
sum=sum+c;
n=n/10;
}
if((sum%3==0)&&((sum/3)%2==0))
{
System.out.println(i + " ");
count++;
}
sum=0;
}
if(count==0)
{
System.out.println("Eligible tickets are not available from "+a+" to "+b);
System.exit(0);
}
}
}

*********************************************************************************************
******************************************************************************
13.COFFEE STALL NUMEROLOGY

INPUT : Enter the Staff Name


Coffee Bar

OUTPUT : Coffee Bar satisfies the numerology logic

import java.util.*;
public class Main{
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the Staff Name");
String name = sc.nextLine();
int count=0;
for(int i=0;i<name.length();i++){
if(Character.isAlphabetic(name.charAt(i)) || name.charAt(i)==' '){
count++;
}
}
if(count==name.length()){
String str = name.replace(" ","");
int sum=0;
for(int i=0;i<str.length();i++){
sum += i;
}
if(sum%2==0){
System.out.println(name+" satisfies the numerology logic");
}else{
System.out.println(name+" does not satisfy the numerology logic");
}
}else{
System.out.println("Invalid Input");
}
}
}

*ALTERNATE METHOD USING -matches for same question

import java.util.*;
public class Main{
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the Staff Name");
String name = sc.nextLine();
if(name.matches("[a-zA-Z ]+")){
String str = name.replace(" ","");
int sum=0;
for(int i=0;i<str.length();i++){
sum += i;
}
if(sum%2==0){
System.out.println(name+" satisfies the numerology logic");
}else{
System.out.println(name+" does not satisfy the numerology logic");
}
}else{
System.out.println("Invalid Input");
}
}
}

*ALTERNATE METHOD

import java.util.Scanner;
public class CoffeeHouse {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the Stall Name");
String name = sc.nextLine();
if (name.matches("^[A-Za-z ]*$")) {
int sum = 0;
String fName = name.replaceAll(" ", "");
for (int i = 0; i < fName.length(); i++)
sum = sum + i;
if (sum % 2 == 0) {
System.out.println(name + " satisfies the numerology logic");
} else {
System.out.println(name + " not satisfies the numerology logic");
}
} else
System.out.println("Invalid Input");
}
}

*********************************************************************************************
******************************************************************************

14.ANAGRAM OR TWO WORDS OF SAME LETTER

INPUT : cat
act

OUTPUT: Same

import java.util.Arrays;
import java.util.Scanner;
public class minmax {
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter sentence 1");
String s1=sc.next();
s1=s1.toLowerCase();
System.out.println("Enter sentence 2");
String s2=sc.next();
s2=s2.toLowerCase();
if(s1.length()!=s2.length())
{
System.out.println("Invalid");
}
if(s1.matches("^[a-zA-Z]*")){
char c1[] = s1.toLowerCase().toCharArray();
char c2[] = s2.toLowerCase().toCharArray();
Arrays.sort(c1);
Arrays.sort(c2);
if (Arrays.equals(c1, c2)) {
System.out.println(s1 + " and " + s2 + " contain the same characters");
} else {
System.out.println(s1 + " and " + s2 + " contain the different characters");
}
}
else
{
System.out.println("Invalid");
}
}
}

ALTERNATE METHOD:

import java.util.*;
public class Main{
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
String first=sc.next();
String secound=sc.next();
String word1=Main.checker(first);
String word2=Main.checker(secound);
if(word1.equals(word2)){
System.out.println("Same");
}else{
System.out.println("Different");
}
}
public static String checker(String word){
char arr[]=word.toCharArray();
Arrays.sort(arr);
int index=0;
for(int i=0;i<arr.length;i++){
int j;
for(j=0;j<i;j++){
if(arr[j]==arr[i]){
break;
}
}
if(i==j){
arr[index++]=arr[i];
}
}
char arr1[]=Arrays.copyOf(arr,index);
String newword= new String(arr1);
return newword;
}
}

ALTERNATE METHOD

import java.util.*;
public class arraysquare {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int f1=0,f2=0;
String s1=sc.nextLine();
char c1[]=s1.toCharArray();
String s2=sc.nextLine();
char c2[]=s2.toCharArray();
for(int i=0;i<c1.length;i++)
{
f1=0;
for(int j=0;j<c2.length;j++)
{
if(c1[i]==c2[j])
{
f1=1;
break;
}
}
if(f1==0)
{
break;
}
}
for(int i=0;i<c2.length;i++)
{
f2=0;
for(int j=0;j<c1.length;j++)
{
if(c2[i]==c1[j])
{
f2=1;
break;
}
}
if(f2==0)
{
break;
}
}
if(f1==1 && f2==1)
{
System.out.println("Same Char");
}
else{
System.out.println("Different char");
}
}
}

*********************************************************************************************
*****************************************************************************
15.SUMMATION OF EVEN NUMBERS IN THE ARRAY

INPUT : Enter array size


4
Enter array elements in 1st array
2
4
6
8
Enter array elements in 2nd array
1
2
5
2

OTPUT: 0
6
0
10

import java.util.*;
public class Main
{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter array size");
int n=sc.nextInt();
if(n>=10 || n<1)
{
System.out.println(n+" is an invalid input");
Runtime.getRuntime().halt(0);
}
int arr1[]=new int[n];
int arr2[]=new int[n];
int result[]=new int[n];
System.out.println("Enter array elements in 1st array");
for(int i=0;i<n;i++)
{
arr1[i]=sc.nextInt();
}
System.out.println("Enter array elements in 2nd array");
for(int i=0;i<n;i++)
{
arr2[i]=sc.nextInt();
}
//PROGRAM LOGIC
int count=0;
for(int i=0;i<n;i++)
{
if((arr1[i]%2==0 || arr1[i]==0) && (arr2[i]%2==0 || arr2[i]==0))
{
result[i]=arr1[i]+arr2[i];
count++;
}
else
{
result[i]=0;
}
}
if(count==0)
{
System.out.println("No even number is present in an Array");
}
for(int i=0;i<n;i++)
{
System.out.println(result[i]);
}
}
}

*********************************************************************************************
******************************************************************************
16.RUNNERS COMPETITION

INPUT :Enter the number of runners


5

Enter the runner details


Robert,9.38
Richard,9.35
Christiano,9.35
Williams,9.36
Vinix,9.35

OUTPUT: Richard
Christiano
Vinix

import java.util.*;
public class Main{
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
sc.useDelimiter("\n");
System.out.println("Enter the number of runners");
int n = sc.nextInt();
if(n<=0 || n>10){
System.out.println(n+" is an invalid number of runners");
Runtime.getRuntime().halt(0);
}
String temp = "";
String name[] = new String[n];
float time[] = new float[n];
System.out.println("Enter the runner details");
for(int i=0;i<n;i++){
temp = sc.next();
String temparr[] = temp.split(",");
name[i] = temparr[0];
time[i] = Float.parseFloat(temparr[1]);
if(time[i]>12 || time[i]<8){
System.out.println(time[i]+" is an invalid input");
Runtime.getRuntime().halt(0);
}
}
int maxcount = 0;
float maxrep = 0;
for(int i=0;i<n;i++){
int count = 0;
for(int j=i+1;j<n;j++){
if(time[i]==time[j]){
count++;
}
}
if(count>=maxcount){
maxcount = count;
maxrep = time[i];
}
}
if(maxcount==n){
System.out.println(n+" runners have same timing");
}
else if(maxcount==0){
System.out.println("No runners with same time.");
}
else{
for(int i=0;i<n;i++){
if(maxrep == time[i]){
System.out.println(name[i]);
}
}
}
}
}
*********************************************************************************************
******************************************************************************

17.REEDME

INPUT : Enter the customer name


Abi
Enter the category
History
Enter the quantity of books ordered
2900

OUTPUT : Total cost is 334080.0


import java.util.*;
public class Main{
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the customer name");
String name = sc.nextLine();
System.out.println("Enter the category");
String category = sc.nextLine();
category = category.toLowerCase();

if(!category.equals("adventure") && !category.equals("comics") && !category.equals("history") && !categ


ory.equals("thriller")){
System.out.println(category+" is invalid category");
Runtime.getRuntime().halt(0);
}
System.out.println("Enter the quantity of books ordered");
int quantity = sc.nextInt();
if(quantity <= 0){
System.out.println(quantity+" is an invalid quantity");
Runtime.getRuntime().halt(0);
}
int discount = 0;
int price = 0;
if(category.equals("adventure")){
price = 150;
if(quantity>=1700)
discount = 5;
}
else if(category.equals("comics")){
price = 230;
if(quantity>=1950)
discount = 5;
}
else if(category.equals("history")){
price = 120;
if(quantity>=2600)
discount = 4;
}
else if(category.equals("thriller") && quantity>=1700){
price = 190;
if(quantity>=6300)
discount = 3;
}
float totalcost = (price*quantity) - (price*quantity*discount/100);
System.out.println("Total cost is "+totalcost);
}
}

*********************************************************************************************
******************************************************************************
18. HARSHAD NUMBER (Sum of digit completely divide that number)

For example: 18= 1+8=9 and in 18/9 remainder is 0


INPUT: Enter array size: 5
Enter array elements : 18 14 12 24 13

OUTPUT: 18 12 24

import java.util.Scanner;
public class Harshad {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the number of values");
int n = sc.nextInt();
int i;
System.out.println("Enter the numbers");
int[] a = new int[n];
if (n > 0)
{
int flag = 0;
int k = 0;
for (i = 0; i < n; i++)
{
k = sc.nextInt();
if (k > 9)
a[i] = k;
else
{
flag = 1;
break;
}
}
if (flag != 1)
{
int c = 0;
for (i = 0; i < n; i++)
{
int x = a[i];
int sum = 0;
do {
int r = x % 10;
sum = sum + r;
x = x / 10;
}
while (x != 0);
if (a[i] % sum == 0)
{
c++;
System.out.println(a[i]);
}
}
if (c == 0)
System.out.println("The " + n + " values are not harshad number");
}
else
System.out.println("Provided " + k + " is not valid");
} else
System.out.println(n + " is an invalid input");
}
}

ALTERNATE METHOD:

import java.util.Scanner;
class Main
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number of values");
int n=sc.nextInt();
System.out.println("Enter the numbers");
int a[]=new int[n];
if(n>0)
{
int flag=0;
int k=0;
for(int i=0;i<n;i++)
{
k=sc.nextInt();
if(k>9) a[i]=k; else
{
flag=1;
break;
}
}
if(flag!=1)
{
int c=0;
for(int i=0;i<n;i++)
{
int x=a[i];
int sum=0;
do
{
int r=x%10; sum=sum+r; x=x/10;
}while(x!=0);
if(a[i]%sum==0)
{ c++;
System.out.println(a[i]);
}
}
if(c==0)
System.out.println("The "+n+" values are not harshad number");
}else
System.out.println("Provided "+k+" is not valid");
}else
System.out.println(n+" is an invalid input");
}
}
*********************************************************************************************
*********************************************************************************************
*******
19.VIDEO GAME (PS1)

INPUT : Enter the amount


18000
Enter the Video Game Player Type
PS4

OUTPUT: You can buy PS4

public class PS {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the amount");
int amount = sc.nextInt();
if (amount >= 3000) {
System.out.println("Enter the Video Game Player Type");
String type = sc.next();
if (type.matches("[P][S][1-5]")) {
if (type.equals("PS1")) {
if (amount >= 5000) {
System.out.println("You can buy PS1");
} else {
System.out.println("You need more money to buy a PS1");
}
} else if (type.equals("PS2")) {
if (amount >= 7800) {
System.out.println("You can buy PS2");
} else {
System.out.println("You need more money to buy a PS2");
}
} else if (type.equals("PS3")) {
if (amount >= 9500) {
System.out.println("You can buy PS3");
} else {
System.out.println("You need more money to buy a PS3");
}
} else if (type.equals("PS4")) {
if (amount >= 12000) {
System.out.println("You can buy PS4");
} else {
System.out.println("You need more money to buy a PS4");
}
} else if (type.equals("PS5")) {
if (amount >= 15000) {
System.out.println("You can buy PS5");
} else {
System.out.println("You need more money to buy a PS5");
}
}
} else {
System.out.println(type + " is Invalid Type");
}
} else {
System.out.println(amount + " is too less");
}
}
}

*********************************************************************************************
*********************************************************************************************
****
20.ALTERNATE SUM DIFFERENCE

INPUT :Enter number


6
Enter values
12
13
6
8
9
7
(((( logic: (12-7=a
13-9=b
6-8=c
a+b+c=ans)))))

OUTPUT 2
3
4
5
5-2=3
4-3=1
So 3+1= 4
*/

import java.util.*;
public class AltDiff {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int sum=0;
int n=sc.nextInt();
int a[]=new int[n];
for(int i=0;i<n;i++)
{
a[i]=sc.nextInt();
}
for(int i=0;i<n/2;i++)
{
sum+=Math.abs(a[i]-a[n-i-1]);
}
System.out.println(sum);
}
}
*********************************************************************************************
*********************************************************************************************
*****
21.CHARACTER ADD

INPUT : Enter : 3
Enter the sentences:
ks436
Agh73
7222

OUTPUT: 222
240
0

import java.util.*;
public class arraysquare{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int sum=0;
System.out.println("Enter:");
int n=sc.nextInt();
if(n<=0)
{
System.out.println("The number of sentences "+n+" is invalid");
return;
}
System.out.println("Enter the sentences:");
String str[]=new String[n];
for(int i=0;i<n;i++)
{
str[i]=sc.next();
}
for(int i=0;i<str.length;i++)
{
String s=str[i].replaceAll("[0-9]","");
for(int j=0;j<s.length();j++)
{
char c=s.charAt(j);
int ascii=c;
sum+=ascii;
}
System.out.println(sum);
sum=0;
}

}
}

*********************************************************************************************
*********************************************************************************************
******
22.MIDDLE LETTER/Reverse first half of the string if string length is ODD

Input:
if length of string is even, the reverse the string:
Ex: Food
Output:
dooF

Input:
If length of the string is odd,then find the middle char and then ,reverse the string till mid char and print remain char
acters as it is.
Ex: Samsung
Output:
maSsung

package FinalAss;
import java.util.*;
public class MidLett {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
String str=sc.nextLine();//rahul
int len=str.length();
if(len%2==0)
{
StringBuilder sb=new StringBuilder(str);
sb.reverse();
System.out.println(sb.toString());
}
else if(len%2!=0)
{
System.out.println("Length of string is " +len);
int mid=len/2;
mid++;
System.out.println("Substring of string is "+mid);
String substr=str.substring(0,mid-1);
String remainSub=str.substring(mid-1,len);
StringBuilder sb=new StringBuilder(substr);
sb.reverse();
System.out.println(sb.toString()+remainSub);

}
}
}

ALTERNATE METHOD:::

import java.util.Scanner;
import java.util.regex.Pattern;
public class minmax {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
String str=sc.nextLine();//rahul
if(!Pattern.matches("[A-Za-z]+",str))
{
System.out.println(str+" is not a valid string");
return;
}
else if(str.length()<2)
{
System.out.println("Size of string "+str.length()+" is too small");
return;
}
int len=str.length();
if(len%2==0)
{
StringBuilder sb=new StringBuilder(str);
sb.reverse();
System.out.println(sb.toString());
}
else if(len%2!=0)
{
int mid=len/2;
String substr=str.substring(0,mid);
String remainSub=str.substring(mid,len);
StringBuilder sb=new StringBuilder(substr);
sb.reverse();
System.out.println(sb.toString()+remainSub);

}
}
}

*********************************************************************************************
*********************************************************************************************
*****

23 .ONLINE SHOPPING

input:
enter the product
laptop
Actual price
45000
exchange?
yes
bill amount:
27000.00

import java.util.*;
public class arraysquare {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the Product:");
String prod=sc.nextLine();
int ed=0,pd=0;
if(prod.equals("Mobile"))
{
ed=15;
pd=15;
}
else if(prod.equals("Laptop"))
{
ed=20;
pd=20;
}
else if(prod.equals("Headset"))
{
ed=0;
pd=10;
}
else if(prod.equals("Charger"))
{
ed=0;
pd=5;
}
else{
System.out.println("Not available");
return;
}
System.out.println("Enter the actual Price: ");
int price=sc.nextInt();
if(price<100)
{
System.out.println("Invalid Price");
return;
}
System.out.println("Do u want to Exchange?");
String exc=sc.next();
if(exc.equals("Yes") || exc.equals("yes"))
{
double ap=price-(price*pd)/100;
double ev=(price*ed)/100;
double total=ap-ev;
System.out.printf("Total=%.2f",total);
}
else if(exc.equals("No") || exc.equals("no"))
{
double total=price-(price*pd)/100;
System.out.printf("Total=%.2f",total);
}
else
{
System.out.println("Invalid Option");
}
}
}

*********************************************************************************************
*********************************************************************************************
*****
24 .OPERATOR FOUND

input:
45
23

22
output
45-23=22

import java.util.*;
public class arraysquare {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter n1 and n2:");
int n1=sc.nextInt();
if(n1>0)
{
int n2=sc.nextInt();
if(n2>0)
{
System.out.println("Enter n3:");
int n3=sc.nextInt();
if(n3>0)
{
if(n1+n2==n3)
{
System.out.println(n1+"+"+n2+"="+n3);
}
else if(n1-n2==n3)
{
System.out.println(n1+"-"+n2+"="+n3);
}
else if(n1*n2==n3)
{
System.out.println(n1+"*"+n2+"="+n3);
}
else if(n1/n2==n3)
{
System.out.println(n1+"/"+n2+"="+n3);
}
else
{
System.out.println(n3+" is an invalid answer");
}
}
else{
System.out.println("Invalid");
}
}
else{
System.out.println("Invalid");
}
}
else{
System.out.println("Invalid");
}

}
}

*********************************************************************************************
*********************************************************************************************
****

25 .PRODUCT EQUAL SUM

INPUT : Enter the array size


4
Enter the elements of the first array
12
35
56
34
Enter the elements of the second array
261
195
112
813
OUTPUT: 35,195
34,813

import java.util.*;
public class arraysquare
{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the array size");
int n=sc.nextInt();
if(n<=0)
{
System.out.println("Invalid array size");
return;
}
int a[]=new int[n];
System.out.println("Enter the elements of the first array");
for(int i=0;i<n;i++)
{
a[i]=sc.nextInt();
}
System.out.println("Enter the elements of the second array");
int b[]=new int[n];
for(int i=0;i<n;i++)
{
b[i]=sc.nextInt();
}
int x[]=new int[n];
int y[]=new int[n];
for(int i=0;i<n;i++)
{
int c=a[i];
int prod=1;
while(c!=0)
{
prod*=(c%10);
c/=10;
}
x[i]=prod;
prod=0;
}
for(int i=0;i<n;i++)
{
int s=b[i];
int sum=0;
while(s!=0)
{
sum+=(s%10);
s/=10;
}
y[i]=sum;
sum=0;
}
for(int i=0;i<n;i++)
{
if(x[i]==y[i])
{
System.out.println(a[i]+","+b[i]);
}
}
}
}

*********************************************************************************************
*********************************************************************************************
*

26.UNIQUE CHAR

input:
LIfe is inherently risky

output:
life is ihrtly risky

package FinalAss;
import java.util.*;
public class nonuniquetwo {
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
String sentence = sc.nextLine();
String[] words = sentence.split(" ");
for(String word : words)
{
System.out.print(getUnique(word) + " ");
}
sc.close();
}
public static String getUnique(String str)
{
StringBuffer sb = new StringBuffer();
for(int i = 0; i<str.length(); i++)
{
if(countFrequency(str.charAt(i), str) == 1)
{
sb.append(str.charAt(i));
}
}
String result = sb.toString();
return result;
}
public static int countFrequency(char c, String str)
{
int count = 0 ;
for(int i = 0; i<str.length(); i++)
{
if(str.charAt(i) == c)
{
count++;
}
}
return count;
}
}

*********************************************************************************************
*********************************************************************************************
*
27. BOX SIZE

INPUT : Enter the box size


6
Enter the numbers
5
55
3
59
42
8
OUTPUT: 32 is even its a valid box

import java.util.Scanner;
public class minmax {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the box size");
int a=sc.nextInt();
if(a<=0)
{
System.out.println(a+" is an invalid box size");
return;
}
int b[]=new int[a];
int c=0,sum=0,temp=0;
System.out.println("Enter the numbers");
for(int i=0;i<a;i++)
{
b[i]=sc.nextInt();
if(b[i]<=0)
{
System.out.println(b[i]+" is an invalid input");
return;
}
}
for(int i=0;i<a;i++)
{
c=b[i]%10;
sum+=c;
c=0;
}
if(sum%2==0)
{
System.out.println(sum+" is even its a valid box");
return;
}
else
{
System.out.println(sum+" is odd its an invalid box");
return;
}

}
}
*********************************************************************************************
*********************************************************************************************
***

28. ORDER IDENTIFICATION:(check where elements are in ascending order)

INPUT : Enter the array size : 5


Enter the elements: 32
44
55
66
77

OUTPUT : 32 44 55 66 77 are in ascending order

import java.util.Arrays;
import java.util.Scanner;

public class orderidentification {


public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the array size");
int a=sc.nextInt();
if(a<2 || a>10)
{
System.out.println(a+" is not a valid array size");
return;
}
int b[]=new int[a];
int count=0;
System.out.println("Enter the elements");
for(int i=0;i<a;i++)
{
b[i]=sc.nextInt();
}
int d[]= Arrays.copyOf(b,b.length);
Arrays.sort(d);

if(Arrays.equals(b,d))
{
count++;
}
if(count>0)
{
for(int i=0;i<b.length;i++)
{
System.out.print(b[i]+" ");

}
System.out.print("are in ascending order");
return;
}
else
{
for(int i=0;i<a;i++)
{
System.out.print(b[i]+" ");
}
System.out.print("are not in ascending order");
return;
}
}
}
*********************************************************************************************
**************************************************************
29) DATE ,MONTH AND YEAR

INPUT:13081995

OUTPUT: date: 13
month: 08
year: 1998

import java.util.Scanner;
public class minmax {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
String str=sc.nextLine();
int n=str.length();
for(int i=0;i<str.length() ;i++)
{
if(!(str.charAt(i)>='0' && str.charAt(i)<='9'))
{
System.out.println("Invalid input");
return;
}
if(n!=8)
{
System.out.println("Enter valid date");
return;
}
}
String date=str.substring(0,2);
String mon=str.substring(2,4);
String year=str.substring(4,8);

System.out.println("date:"+date);
System.out.println("Month:"+mon);
System.out.print("Year:"+year);

}
}

*********************************************************************************************
*********************************************************************************************
*
30) MEGA MART CUSTOMER IDENTIFICATION(String and SUBSTRING)

import java.util.*;
public class arraysquare{
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the customer id");
String cid = sc.next();
String shop = cid.substring(0,4);
//System.out.println("shop");
if(!shop.equals("Mega")){
System.out.println("Invalid Shop Name");
Runtime.getRuntime().halt(0);
}
String type = cid.substring(4,cid.length()-3);
//System.out.println(type);
if(!type.equals("Silver") && !type.equals("Gold") && !type.equals("Platinum")){
System.out.println("Invalid Customer Type");
Runtime.getRuntime().halt(0);
}
int mid = Integer.parseInt(cid.substring(cid.length()-3,cid.length()));
//System.out.println(mid);
if(mid<=99 || mid>=1000){
System.out.println("Invalid Member id");
Runtime.getRuntime().halt(0);
}
System.out.println("Welcome Mega Mart "+type+" Customer");

}
}

*********************************************************************************************
***********************************
31) .MALE AND FEMALE COUNT

INPUT: MmFMff

OUTPUT: 3 MALE
3 FEMALE

import java.util.Scanner;
import java.util.regex.*;
public class minmax {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
String s=sc.nextLine();
int count1=0;
int count2=0;
if(Pattern.matches("[MmFf ]+",s)){
for (int i = 0; i < s.length(); i++) {
if (s.charAt(i) == 'M' || s.charAt(i) == 'm') {
count1++;
} else if (s.charAt(i) == 'F' || s.charAt(i) == 'f') {
count2++;
}
}
System.out.println(count1 + " Male");
System.out.println(count2 + " Female");
}
else
{
System.out.println("Invalid Input");
}
}
}
*********************************************************************************************
*********************************************************************************************
***
32. RAINFALL

INPUT: Enter the length of the roof in meters: 4


Enter the breadth of the roof in meters: 3
Enter the rainfall level: 3

OUTPUT: 360.00 Litres

import java.util.Scanner;
public class minmax {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
System.out.println("Enter the length of the roof in meters");
double l=sc.nextDouble();
if(l<=0)
{
System.out.println("Invalid Length");
return;
}
System.out.println("Enter the breadth of the roof in meters");
double b=sc.nextDouble();
if(b<=0)
{
System.out.println("Invalid breadth");
return;
}
System.out.println("Enter the rainfall level");
double r=sc.nextDouble();
if(r<=0)
{
System.out.println("Invalid rainfall");
return;
}
double h;
h=(l*b) *(r*10);
System.out.println(String.format("%.2f",h)+"Litres");
}
}

*********************************************************************************************
*********
33) NUMEROLOGY NAME CHECKING

import java.util.*;
import java.util.regex.Pattern;

public class arraysquare{


public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the name");
String a=sc.next();
if(!Pattern.matches("[A-Za-z]+",a))
{
System.out.println(a+" is an Invalid name");
return;
}
int sum=0;
char b[]=a.toCharArray();
for(int i=0;i<b.length;i++)
{
if(b[i]=='A'||b[i]=='a')
{
sum+=1;
}
else if(b[i]=='B'||b[i]=='b')
{
sum+=2;
}
else if(b[i]=='C'||b[i]=='c')
{
sum+=3;
}
else if(b[i]=='D'||b[i]=='d')
{
sum+=4;
}
else if(b[i]=='E'||b[i]=='e')
{
sum+=5;
}
else if(b[i]=='F'||b[i]=='f')
{
sum+=6;
}
else if(b[i]=='G'||b[i]=='g')
{
sum+=7;
}
else if(b[i]=='H'||b[i]=='h')
{
sum+=8;
}
else if(b[i]=='I'||b[i]=='i')
{
sum+=9;
}
else if(b[i]=='J'||b[i]=='j')
{
sum+=10;
}
else if(b[i]=='K'||b[i]=='k')
{
sum+=11;
}
else if(b[i]=='L'||b[i]=='l')
{
sum+=12;
}
else if(b[i]=='M'||b[i]=='m')
{
sum+=13;
}
if(b[i]=='N'||b[i]=='n')
{
sum+=14;
}
if(b[i]=='O'||b[i]=='o')
{
sum+=15;
}
if(b[i]=='P'||b[i]=='p')
{
sum+=16;
}
if(b[i]=='Q'||b[i]=='q')
{
sum+=17;
}
if(b[i]=='R'||b[i]=='r')
{
sum+=18;
}
if(b[i]=='S'||b[i]=='s')
{
sum+=19;
}
if(b[i]=='T'||b[i]=='t')
{
sum+=20;
}
if(b[i]=='U'||b[i]=='u')
{
sum+=21;
}
if(b[i]=='V'||b[i]=='v')
{
sum+=22;
}
if(b[i]=='W'||b[i]=='w')
{
sum+=23;
}
if(b[i]=='X'||b[i]=='x')
{
sum+=24;
}
if(b[i]=='Y'||b[i]=='y')
{
sum+=25;
}
if(b[i]=='Z'||b[i]=='z')
{
sum+=26;
}
}
System.out.println(sum);
if(sum%3==0 && sum%2==0)
{
System.out.println(a+" is a numerology name");
}
else
{
System.out.println(a+" is not a numerology name");
}
}
}

*******************************************************************************

34)OMR

import java.util.Scanner;
public class arraysquare{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int i;
System.out.println("Enter the No of questions");
int a=sc.nextInt();
if(a<0)
{
System.out.println("Invalid Number");
return;
}
int count=0;
int mark=0;
char b[]=new char[a];
System.out.println("Enter the answer key");
for (i=0;i<a;i++) {
b[i] = sc.next().charAt(0);

if ((b[i] >= 'a' && b[i] <= 'e')||(b[i] > 'E')) {


System.out.println("Invalid Answers");
return;
}
}
char c[]=new char[a];
System.out.println("Enter the student answers");
for (i=0;i<a;i++)
{
c[i]=sc.next().charAt(0);
if ((c[i] >= 'a' && c[i] <= 'e')||(b[i]>'E')) {
System.out.println("Invalid Answers");
return;
}
}

for(i=0;i<a;i++)
{
if(b[i]==c[i])
{
count++;
}
}
if(count>0)
System.out.println("Correct answers are "+count);
mark=(count*100)/a;
if(count<1)
System.out.println("All answers are wrong");
System.out.println("Mark is "+mark);

}
}
JAVA END
*********************************************************************************************
*********************************************************************************************
********

RDBMS IMPORTANT CODES(NOT TESTED)

1.)Select concat(concat(customer_name,'has taken a


policy on'),date_of_policy) as Enrollment_details
from customer JOIN Policy using (customer_id)
order by customer_name,date_of_policy;

2.)select plolicy_id,policy_name,rate_of_interest, bonus_percentage


from policy
where minimum_primeium_amount = 1200
order by policy_d;

3.)select fine_range,fine_amount
CASE
When fine_range=L1
then 5+fine_amount
when fine_range=L2
then 10+fine_amount
When fine_range=M1
then 15+fine_amount
when fine_range=M2
then 20+fine_amount
When fine_range=H1
then 25+fine_amount
when fine_range=H2
then 30+fine_amount
END as NEW_FINE_AMOUNT

4.)select leave_type,allocated_days
CASE
when leave_type='CASUAL'
then allocated_days+2
when leave_type='SICK'
then allocated_days+5
when leave_type='MATERNITY'
then allocated_days+90
when leave_type='MARRIAGE'
then allocated_days+3
when leave_type='STUDY'
then allocated_days-2
END as NEW_ALLOCATED_TYPES
from table_name
order by leave_type;

5.) select emp_id,emp_name,department_id,department_name


from Department JOIN Employee using (department_id)
JOIN Leave+Avail_details using (Emp_id)
JOIN Leave using (Leave_type)
where Allocated_days = 0
order by emp_id;
*********************************************************************************************
**

1.) Account Info - "HDVL002"


select account_type, count(account_id) as TOTAL_ACCOUNTS
from Acount_Info where IFC_Code = 'HDVL002'
group by account_type order by account_type;

2.)select customer_id,customer_name,phone_no,order_date
from Customer_info JOIN Orders using (customer_id)
where order_amount > 500
order by customer_id,order_date;

3.) select distinct customer_id,customer_name,phone_no,loan_amount as


total_loan_amount from customers JOIN loans_taken using
(customer_id)
order by customer_id;

4.) select distinct boat_id,seat_capacity,count(ride_id) as ride_count


From Boat_details JOIN Ride_details using (boat_id)
order by boat_id;

5.) select customer_id,customer_name,contact_no,mail_id


from Coustomer_details where Gender = 'M'
order by customer_id;
6.) select customer_name,total_amount_paid
from Customer_master JOIN Booking_details using (customer_id)
where total_amount_paid < (select max(total_amount_paid) from booking_details
where total_amount_paid < (select max(total_amount_paid) from booking_details))
order by customer_name;

7.) select book_code,book_title, author,rack_num


from book_details where category = 'JAVA'
order by book_code;

8.) select customer_name,policy_enrollment as Enrollment_details


from customer JOIN policy_enrolmment using (customer_id)
order by customer_name,date_of_enrollment;

9.)DECODE QUESTION
select fine_range, fine_amount,
decode(fine_range, 'L1',fine_amount+5,
'L2',fine_amount+10,
'M1',fine_amount+10,
'M2',fine_amount+10,
'H1',fine_amount+10,
'H2',fine_amount+10)new_fine_amount
from fine_details;

10.)select customer_name||" has taken policy on"|| date_of_enrollment as


enrollment_details form customer
join policyenrollent using (customer_id)
order by customr_name,date_of_enrollment;

11.)select policy_id,policy_name,rate_of_interest,bonus_percentage
from policy where mimum_premium_amount = 1200
order by policy_id;

12.) select customer_id,customer_name, street,phone_no,email


from Customers JOIN loan_taken using (customer_id)
where loan_amount > = 500000 and loan_amonunt <1500000
order by customer_id;

13.)select distinct boat_id, boat_name,boat_type


from boat_details JOIN ride_details using (boat_id)
where DOT LIKE '%-AUG-%' and Shift = 'evening'
order by boat_id;

14.) select policy_id,policy_name,rate_of_interest


from policy where miniimum_ppremium_amount < 3000 AND bonus_percent > 85
order by policy_id;

RDBMS ANSWERS

1.1)Write a query to display boat_type and number of boats running under each type. Give an alias name as 'NO_OF
_BOATS'.
Note: Boat_type can be 'DELUXE' or 'SUPER DELUXE'.

select boat_type,count(Boat_id) as NO_OF_BOATS


from boat_details
group by Boat_type;

1.2) select boat_name,boat_type from boat_details


where seat_capacity between 100 and 200
order by boat_name desc;

2.1)select vehicle_type,count(vehicle_id)
from vehicle_details
group by vehicle_type
order by vehicle_type;

2.2)select driver_id,driver_name,phone_no,Driver_rating
from driver_details where driver_rating between 3 and 5
order by driver_rating desc;

3.1)select coursename from course


c join registration r on
c.courseid=r.courseid
having count(studid)>=2
group by coursename
order by coursename;

3.2)select s.studid,sum(fees) as TOTALFEES


from student s join registration r
on s.studid=r.studid join course c
on r.courseid=c.courseid
group by s.studid
order by s.studid;

3.3)select studid,count(CourseID) as NOOFCOURSES


from registration
group by Studid
order by NOOFCOURSES desc,Studid;

3.4)select student.stuid,firstname from student


join registration on registration.stuid=student.stuid
where lower(to_char(doj,'MON'))='jan';

3.5)select courseid,coursename from


course where duration between 10 and 15;

3.6)select courseid,registration.stuid from registration


join student on registration.stuid=student.stuid
where lower(to_char(doj,'MON'))=lower(to_char(dob,'MON'));
1

1. Gender determination ……………………………………….. 2


2. LCM lunch/dinner together …………………………………2-3
3. Product equals sum ………………………………………………3-5
4. Count of occurences of substring in a given string… ..5-6
5. Fun count……………………………………………………………….. 6
6. Speed Estimation…………………………………………………… 7
7. Prime number………………………………………………………. 7-8
8. Theatre seat ………………………………………………………… 8-9
9. Customer details …………………………………………………. 10-11
10. Team win/loose ………………………………………………… 11
11. Holiday fun ……………………………………………………….. 11-12
12. Reverse-prime …………………………………………………… 12-13
13. Even number addition in arrays…………………………. 14
14. Groceries bill …………………………………………………….. 15
15. Cake order …………………………………………………………. 16-17
2

Gender Determination :

import java.util.*;
public class Main {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
String s=sc.next();
int count=0,count1=0;
if(!(s.matches("[mfMF]+")))
{
System.out.println("Invalid Input");
return;
}
else
for(int i=0;i<s.length();i++)
{
if(s.charAt(i)=='m' ||s.charAt(i)=='M')
count++;
else
count1++;
}
System.out.println(count+" "+"Male");
System.out.println(count1+" "+"Female");
}}
LCM OF DAY INTERVAL/LUNCH/DINNER TOGETHER :

import java.util.*;
public class Main {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
System.out.println("Enter the day interval of person 1:");
int a=sc.nextInt();
System.out.println("Enter the day interval of person 2:");
int b=sc.nextInt();
if(a<=0 || b<=0)
{
System.out.println("Given interval is not valid");
return;
3

}
int lcm;
lcm=(a>b)?a:b;
while(true){
if(lcm%a==0 && lcm%b==0){
System.out.println("person 1 and person 2 will have
their dinner on day "+lcm);
break;
}
lcm++;
}
}}

PRODUCT EQUALS SUM

import java.util.*;

public class Main{

public static void main(String args[]){

Scanner sc=new Scanner(System.in);

System.out.println("Enter the array size:");

int n=sc.nextInt();

int count=0;

if(n<1 || n>10){

System.out.print("Invalid array size");

System.exit(0);

else{

int[] a1=new int[n];

int[] a2=new int[n];

System.out.println("Enter the elements of the first array");


4

for(int i=0;i<n;i++){

int b=sc.nextInt();

if(b>10 && b<999)

a1[i]=b;

else{

System.out.print("Invalid input");

System.exit(0);

}}

System.out.println("Enter the elements of the second


array");

for(int i=0;i<n;i++){

int c=sc.nextInt();

if(c>10 && c<999)

a2[i]=c;

else{

System.out.print("Invalid input");

System.exit(0);

}}

for(int i=0;i<n;i++){

int mul=1,r=0,x=a1[i];

while(x>0){

r=x%10;

mul*=r;
5

x=x/10;

for(int j=0;j<n;j++){

int sum=0,p=0,y=a2[j];

while(y>0){

p=y%10;

sum+=p;

y=y/10;

if(mul==sum){

count++;

System.out.print(a1[i]+","+a2[j]);

System.out.println(" ");

}}}

if(count==0){

System.out.print("No pair found");

System.exit(0);

}}}}

Count of Occurrences of Substring in a String

import java.util.*;
public class Main {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
String s1=sc.next();
String s2=sc.next();
int index=0;
6

int count=0;
while((index=s1.indexOf(s2,index))!=-1){
index=index+1;
count+=1;
}
System.out.println(count);
}
}

Fun Count

import java.util.*;
public class Main {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
if(n<=0){
System.out.println("Invalid Input");
return;
}
if(n>15){
System.out.println("Number exceeds the limit");
return;
}
Map<String,Integer> a=new HashMap<>();
for(int i=0;i<n;i++){
String s=sc.next().toLowerCase();
if(a.containsKey(s))
a.put(s,1+a.get(s));
else
a.put(s,1);
}
Map<String,Integer> tm=new TreeMap<>(a);
for(Map.Entry<String,Integer>data:tm.entrySet()){
System.out.println(data.getKey()+"= "+data.getValue());
}
}
}
7

SPEED ESTIMATION :
import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
System.out.println("Enter the distance in kilometer");
int km=sc.nextInt();
if(km<0) {
System.out.println("Invalid Input");
return;
}
System.out.println("Enter the time to reach in hours");
int hours=sc.nextInt();
if(hours<0){
System.out.println("Invalid Input");
return;
}
int speed=km/hours;
if(speed<30){
System.out.println("You drive a car at normal speed");
return;
}
int inc=speed-30;
System.out.println("You want to increase a speed "+inc+"
km/hr from a normal speed");
}}

Prime Number

import java.util.Scanner;

public class Main{

public static void main(String[] args){

Scanner sc=new Scanner(System.in);

int a = sc.nextInt();

int b = sc.nextInt();

int count=0;
8

if(a<0 || b<0){

System.out.println("Negative integers cannot be prime");

return;

for(int i=a;i<=b;i++){

count = 0;

for(int j=2;j<=i;j++){

if(i % j == 0)

count = count+1;

if(count == 1)

System.out.print(i+" ");

if(count!=1)

System.out.println("There are no prime numbers in the range


"+a+" to "+b);

Theatre

import java.util.*;
public class Main {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
String s=sc.next();
if(s.length()==6)
{
9

String a=s.substring(0,1);
if(a.matches("[NEWS]+"))
{
String b=s.substring(1,2);
if(b.matches("[ABCDE]+"))
{
String c=s.substring(2,3);
if(c.matches("[1-4]+"))
{
String d=s.substring(3,6);
int num=Integer.parseInt(d);
if(num>0 && num<500)
{
System.out.println("Name "+a);
System.out.println("Block "+b);
System.out.println("Floor number "+c);
System.out.println("Seat number
"+num);
}
else
System.out.println("Invalid Seat number");
}
else
System.out.println("Invalid Floor number");
}
else
System.out.println("Invalid Block");
}
else
System.out.println("Invalid Name");
}
else
System.out.println("Invalid size");
}}
10

Customer details

import java.util.Scanner;

public class Main{


public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number of customers:");
int cust=sc.nextInt();
if(cust<0)
{
System.out.println("Invalid Input");
return;
}
if(cust<3)
{
System.out.println("Customer count is too low");
return;
}
if(cust>50)
{
System.out.println("Customer count is too high");
return;
}
System.out.println("Enter the customer details:");
String[] arr=new String[cust];
for (int i=0;i<cust;i++)
{
arr[i]=sc.next();
}
System.out.println("Enter the plan to be searched");
String plan=sc.next();
for (int i=0;i<cust;i++)
{
String[] custdetails=arr[i].split(":");
if(plan.equals(custdetails[1]))
{
System.out.println(custdetails[2]+" "+custdetails[3]);
11

}
}
}
}

Team Win/Loose
import java.util.*;
public class Main {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
String str=sc.next();
int count=0;
if(str.length()<3) {
System.out.println("Invalid input");
return;
}
if(str.matches("[htHT]+")) {
String s=str.toLowerCase();
for(int i=0;i<s.length()-2;i++){
if(s.charAt(i)!=s.charAt(i+1) &&
s.charAt(i)==s.charAt(i+2))
count++;
}
if(count==s.length()-2)
System.out.println("Team will win");
else
System.out.println("Team may loose");
}
else {
System.out.println("Invalid Input");
return;
}
}}

Holiday Fun

import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
12

int sum=0,sum1=0;
int n=sc.nextInt();
if(n>0){
String[] a=new String[n];
for(int i=0;i<n;i++){
a[i]=sc.next();
}
for(int i=0;i<n;i++){
int len=a[i].length();
if(len%2==0)
{
for(int j=1;j<len;j++){

sum=sum+Integer.parseInt(String.valueOf(a[i].charAt(j)));
j++;
}}
else
{
for(int k=0;k<len;k++){

sum1=sum1+Integer.parseInt(String.valueOf(a[i].charAt(k)));
k++;
}}
}
System.out.println(sum+sum1);
}
else
System.out.println("Invalid size");
}}

Reverse Prime

import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
int count=0,c=0,f=0,r=0,prime=0;
int n=sc.nextInt();
if(n>0) {
int[] a=new int[n];
13

for(int i=0;i<n;i++) {
int num=sc.nextInt();
if(num>9)
a[i]=num;
else {
System.out.println("Provided "+num+" is not valid");
return;
}}
for(int i=0;i<n;i++) {
count=0;
for(int j=2;j<a[i];j++)
{
if(a[i]%j==0)
count++;
}
if(count==0) {
prime++;
f=a[i];
r=0;
while(a[i]!=0) {
r=r*10;
r=r+a[i]%10;
a[i] =a[i]/10;
}
for(int k=2;k<r;k++) {
if(r%k==0)
c++;
}
if(c==0)
System.out.println(f);
}}}
else {
System.out.println(n+" is less than a limit");
return;
}
if(prime==0)
System.out.println(n+" values are not prime numbers");
}}
14

Even number addition in arrays

import java.util.*;
public class Main {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
int count=0;
System.out.println("Enter the size of array ");
int n=sc.nextInt();
int[] sum=new int[n];
if(n>=1 && n<=10)
{
int[] a=new int[n];
System.out.println("Enter the elements of the first array ");
for(int i=0;i<n;i++)
a[i]=sc.nextInt();
int[] b=new int[n];
System.out.println("Enter the elements of second array ");
for(int i=0;i<n;i++)
b[i]=sc.nextInt();
for(int i=0;i<n;i++)
{
if(a[i]%2==0 && b[i]%2==0)
{
count++;
sum[i]=a[i]+b[i];
}
else
sum[i]=0;
}
if(count==0)
System.out.println("There are no even elements");
else
for(int result:sum)
System.out.println(result);
}
else
System.out.println("Invalid");
}}
15

Groceries Bill

import java.util.*;
public class Main {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
String s=sc.next();
int a=0,b=0,c=0,d=0,count=0;
if(s.matches("[ORWKorwk]+")) {
for(int i=0;i<s.length();i++) {
for(int j=0;j<s.length();j++) {
if(s.charAt(i)==s.charAt(j))
count++;
}}
if(count==s.length()) {
for(int k=0;k<s.length();k++)
{
if(s.charAt(k)=='O')
a=4*20;
else if(s.charAt(k)=='R')
b=3*5;
else if(s.charAt(k)=='W')
c=2*10;
else
d=5*15;
}
System.out.println(a+b+c+d);
}
else
System.out.println("Duplicates are not allowed");
}
else
System.out.println("Invalid");
}}
16

Cake Order

import java.util.*;

public class CakeProgram {

public static void main(String[] args) {


Scanner sc=new Scanner(System.in);
System.out.println("Enter the Customer instructions: ");
String cd=sc.nextLine();

if (cd.matches("[a-zA-Z0-9]*")) {
String w=cd.substring(0, 4);

if(!w.matches("[0-9]*")){
System.out.println("Invalid weight");
return;
}

float wg=Integer.parseInt(w);
if (wg>999) {
float fwg=wg/1000;
double weight= (Math.round(fwg * 100.0) / 100.0);

String o=cd.substring(cd.length()-3);
if (!o.matches("[0-9]*")) {
System.out.println("Invalid order number");
return;
}
int on=Integer.parseInt(o);
if(on>99) {
String flavour=cd.substring(4,cd.length()-3);

System.out.println("Weight of Cake in Kgs:


"+String.format("%.2f", weight));
System.out.println("Order No: "+on);
System.out.println("Flavour Name: "+flavour);

double cakePrice=450*weight;
17

System.out.printf("Cake Price is: %.2f


Rupees",cakePrice);
}
else {
System.out.println("Invalid order number");
}
}
else {
System.out.println("Invalid weight");
}
}
else {
System.out.println("Invalid Input");
}
}

}
1. Maze Runner

Amy wants to create a game. Her game had 2 players, according to the movement of the players
points will vary. According to the direction, characters will be assigned. Only four characters can
be assigned, L-left, R-right, B-bonus, F-foul, if the direction is left add 50 points, if the direction is
right subtract 50 points, if there is a bonus double the points or if there is foul reduce the total
points to its half.

So according to the string calculate the points and compare it among the players. At the end of
the game, if the player1 have scored more points than player 2, print “Player 1 Wins” or else print
“Player 2 Wins”. At the end of the game, if both have secured equal points print “Draw Nobody
Wins” .Initial points are awarded to the players and the score calculation is done with that initial
points.

Note: Characters L,R,B,F are valid. If there is any other character present in the string print
“Invalid Input”. Number of characters must be same between the players or else print “Invalid
Input”. Initial points can be between 1000 to 5000 or else print “Invalid Input”.

Sample input 1:

Enter the points of the first player:

1200

Enter the string:

LLRRF

Enter the points of the second player:

1000

Enter the string:

RRLFB

Sample output 1:

Player 2 Wins

Explanation: (1200+50+50-50-50)/2=600, ((1000-50-50+50)/2)*2=950, Thus player 2 Wins the


game.

Sample input 2:

Enter the points of the first player:

7000

Sample output 2:
Invalid Input

Sample input 3:

Enter the points of the first player:

1900

Enter the string:

LLRKF

Sample output 3:

Invalid Input

2. Holiday Trip:

Ana wants to book a ticket to Mumbai. She want to call few of her friends with her. Help her to
calculate the ticket amount by which they can go for their trip within their budget. There are
different flights like Air India, Spice Jet, Go Air, IndiGo.

According to the flight name travel cost varies. Each flight will have divisions like Economy class,
Travel class and Business class. Cost of the ticket will vary for each class. If the passenger pays
the ticket cost using card there is a percentage of reduction in the cost of the ticket. If the number
of passengers are more than 5, 10% discount is given and if it is more than 10, 15% discount is
given for IndiGo and Spice Jet alone from the final amount.

Air India:

Travel class:3200

Economy class:6950

Business class:10,340

Card Payment:10.5%

Spice Jet:

Travel class:3450

Economy class:7945

Business class:9500

Card Payment:7.5%
Go Air:

Travel class:3300

Economy class:7250

Business class:9890

Card Payment:9.5%

IndiGo:

Travel class:3490

Economy class:7560

Business class:9990

Card Payment:8.5%

Sample input 1:

Enter the flight name:

Air India

Enter the class:

Travel class

Enter the number of seats:

Card Payment:

Sample output 1:

22912

Explanation: (3200*8)-(3200*8*(10.5/100))

3. Tell the time


John has planned to automate the process of sending the next notification to his colleagues for
the day. He knows the time, when the first notification has to be sent and the time interval, after
which the next notifications has to be sent.

Write a java program to get two input from the user, the first input will be a string holding time in
24 hours format(HH:MM) and the second input will be an integer that holds the time interval in
minutes (MM). And display the time at which the next notifications has to be sent for that day. If
the time to send the next notification exceeds for the day display “Notification cannot be sent for
the day”.

If the range of hours (HH) in time should be between 00 and 23 (both inclusive) and the range of
minutes (MM) should be between 00 and 59(both inclusive). If not display “Input is not valid” and
terminate the program.

Assumption: Day starts 00:00 (HH:MM) and ends at 23:59(HH:MM)

Adhere to the sample input and output.

Sample Input 1:

22:00

05

Sample Output 1:

22:05

Sample Input 2:

23:45

20

Sample Output 2:

Notification cannot be sent for the day

Sample Input 3:

25:50

Sample Output 3:

Input is not valid


Sample Input 4:

23:50

60

Sample Output 4:

Input is not valid

4.Fuel Quantity Calculation

David fueled his vehicle in a fuel station. He remembered that he asked the filling person to fill
the fuel for certain amount in rupees. But he don’t know the quantity of fuel in liters. Help him to
calculate the fuel in Liters from amount in Rupees by getting the rate per liter as input.

Note that, both the inputs must be a positive number. Otherwise print “Invalid Input”

Output must have only two decimal places.

The result should be in two decimal places. To get two decimal places refer the below-mentioned
print statement :

float cost=1105.00f;

System.out.printf(“%.2f”,cost);

Sample Input 1:

Enter the amount in Rupees:

1000

Fuel rate per liter:

89.35

Sample Output 1:

11.19 Liters

Sample Input 2:

Enter the amount in Rupees:

-1000

Sample Output 2:
Invalid Input

5.Vowel Pair Removal

Nancy was playing with her daughter, they were playing with words. That day her daughter was
taught vowels in her class. So they were playing with vowels. Nancy asked her daughter to
remove the vowels from the word, if they are present in continuous pattern alone.

Note: The word should not have more than 8 letters if so print “Word length exceeds the limit”
and less than 3 letters, if so print “Word length is too short”. Word cannot have numbers or
special character, if so print “Invalid Input”.

Sample input 1:

Enter the word:

solution

Sample output 1:

solutn

Sample input 2:

Enter the word:

hi

Sample output 2:

Word length is too short

Sample input 3:

Enter the word:

absurdity

Sample output 3:

Word length exceeds the limit

Sample input 4:
Enter the word:

ba&ery

Sample output 4:

Invalid Input

6. MAC Validation

A MAC (Media Access Control) address is the unique identifier that is assigned by the
manufacturer to a piece of network hardware.

A MAC address consists of six sets of two characters, each separated by a colon.
00:1B:44:11:3A:B7 is an example of a MAC address. Each character should hold only
hexadecimal values ( 0 to 9 and A to F).

Write a java program to check the given string is a valid MAC address or not, if the given string is
valid then display “Valid MAC address” else display “Invalid MAC address”.

Note: If the given string contains less than six sets of two characters, each separated by a colon
display “String is too short”. If the given string contains more than six sets of two characters,
each separated by a colon display “String is too long”. If the given string contains any other
symbols other than colon (:) display “Invalid Input”.

Assumption: Each set in the given string will have only two characters and alphabets in the
Upper case.

Sample Input 1:

56:41:AB:5A:A5:60

Sample Output 1:

Valid MAC address

Sample Input 2:

62:55:VB:ZZ:A5:S6

Sample Output 2:

Invalid MAC address

Sample Input 3:
62:55:CB

Sample Output 3:

String is too short

Sample Input 4:

62:55:CB:62:55:CB:23

Sample Output 4:

String is too long

Sample Input 5:

62&55*CB%62:55@CB

Sample Output 5:

Invalid Input

7. Unique products

John runs a department store and has multiple items in it. Each items will have a 3 digit bar code
ID to identify the items. He wants to segregate items which has Unique number in the 3 digit bar
code ID. A Unique number is a positive integer with no duplicate digits. For example 135, 214 are
all unique numbers whereas 311, 300 are not.Help him by your java skills.

Note: The number of items should be between the range 5 and 20 (both inclusive) else display
“Invalid item count” and terminate the program. The bar code ID of each item should be only a 3
digit number, if not display “Invalid bar code ID” and terminate the program. If there is no bar
code ID with Unique number then display “There are no item with Unique number in the bar code
ID”.

Adhere to the Sample Input and Output

Sample Input 1:

Enter the number of items:

10

Enter the bar code ID for 10 items:

111

222

123
125

654

354

844

141

200

201

Sample Output 1:

123

125

654

354

201

There are 5 items with Unique number in the bar code ID

Sample Input 2:

Enter the number of items:

Enter the bar code ID for 5 items:

111

222

110

333

100

Sample Output 2:

There are no item with Unique number in the bar code ID


Sample Input 3:

Enter the number of items:

25

Sample Output 3:

Invalid item count

Sample Input 4:

Enter the number of items:

Enter the bar code ID for 5 items:

111

1000

Sample Output 4:

Invalid bar code ID

8.Toggle word

Reema is an English teacher, she teaches upper case and lower case letters to her students.
She wanted to test her students, whether her students have understood the concept. She wanted
to conduct it as a game. If the students perform well, she would like to present gifts. Help her to
conduct the game using Java program.

If a word is given, each alternate character in the word should be converted in to upper case ie,
In the given word, the first character should start with upper case followed by each alternate
character as upper case.

For example:

If the input is string, then the output should be StRiNg

Note: Word should not have more than 8 letters if so print “Word length exceeds the limit” and
less than 3 letters, if so print “Word length is too short”. Word cannot have numbers or special
character, if so print “Invalid Input”.

Sample input 1:

Enter the word:

aviation
Sample output 1:

AvIaTiOn

Sample input 2:

Enter the word:

it

Sample output 2:

Word length is too short

Sample input 3:

Enter the word:

abundance

Sample output 3:

Word length exceeds the limit

Sample input 4:

Enter the word:

m@ngo

Sample output 4:

Invalid Input

9.Prime Number Multiples

Write a program to find the product of the prime digits in the given input number.

If the input number is negative or greater than 32767 Print it as "Invalid Input".

If the input number does not have any prime digits,print it as “No Prime Digit Found”

If the input number has single prime digit,then print that prime digit.

Please note that '1' and '0' are neither prime nor composite.
Input and Output Format:

Input consists of an integer.

Output consists of an integer.

Refer sample output for formatting specifications.

Sample Input 1:

2017

Sample Output 1:

14

Explanation:

Number '2' and '7' are the prime digits in the given input and number '1' and '0' are neither prime
nor composite hence the product of prime digits will results in 14(2*7).

Sample Input 2:

483

Sample Output 2:

Sample Input 3:

-67

Sample Output 3:

Invalid Input

10.Estimated Parcel Delivery Time

James needs to find the estimated delivery time of his parcel. Get the distance(in Km) between
the seller and buyer as input. Consider that the delivery vehicle can travel with 10 meter per
second as average speed. Calculate the delivery time and display the output in Minutes (rounded
value) as given in sample data.

Formula: T = D / S

where, S = speed (in meters/second)


D = distance (in meters)

T = time (in seconds)

(1Km=1000m, 1min=60sec).

Note that, the input should be in Kilometers and output should be in minutes.

Write a Java program to calculate the above. Input must be a positive number, otherwise print
“Invalid Input”.

The result should be in two decimal places. To get two decimal places refer the below-mentioned
print statement :

float cost=1105.00f;

System.out.printf(“%.2f”,cost);

Sample Input 1:

Enter the distance in Km:

100

Sample Output 1:

Estimated Time:

166.67 Minutes

Sample Input 2:

Enter the distance in Km:

-50

Sample Output 2:

Invalid Input
1. Maze Runner

Solution:

import java.util.*;

class Main

public static void main(String args[])

Scanner sc=new Scanner(System.in);

System.out.println("Enter the points of the first player:");

int points1=sc.nextInt();

if(points1<1000 || points1>5000)

System.out.println("Invalid Input");

else

System.out.println("Enter the string:");

String s1=sc.next();

int flag=0;

char ch1[]=s1.toCharArray();

for(char c:ch1)

if(c=='L' || c=='R' || c=='F' ||c=='B')

//System.out.println(c);

flag++;

}
}

if(flag!=s1.length())

System.out.println("Invalid Input");

else

System.out.println("Enter the points of the second player:");

int points2=sc.nextInt();

if(points2<1000 || points2>5000)

System.out.println("Invalid Input");

else

System.out.println("Enter the string:");

String s2=sc.next();

if(s1.length()!=s2.length())

System.out.println("Invalid Input");

else

int flag1=0;

char ch2[]=s2.toCharArray();

for(char c:ch2)

{
if(c=='L' ||c=='R' || c=='F' ||c=='B')

flag1++;

if(flag1!=s2.length())

System.out.println("Invalid Input");

else

for(char c:ch1)

if(c=='L')

points1+=50;

if(c=='R')

points1-=50;

if(c=='B')

points1*=2;

if(c=='F')

{
points1/=2;

for(char c:ch2)

if(c=='L')

points2+=50;

if(c=='R')

points2-=50;

if(c=='B')

points2*=2;

if(c=='F')

points2/=2;

if(points1>points2)

System.out.println("Player 1 Wins");

else if(points1<points2)
{

System.out.println("Player 2 Wins");

else

System.out.println("Draw Nobody Wins");

2. Holiday Trip:

Solution:

import java.util.*;

public class Main{

public static void main(String[] args){

Scanner sc=new Scanner(System.in);

Scanner sc1=new Scanner(System.in);

System.out.println("Enter the flight name:");

String fname=sc.nextLine();
System.out.println("Enter the class:");

String fclass=sc.nextLine();

System.out.println("Enter the number of seats:");

int no=sc.nextInt();

System.out.println("Card Payment:");

char pay=sc.next().charAt(0);

int cost=0;

switch(fname){

case "Air India":

// System.out.println("Hai1111");

switch(fclass){

case "Travel class":{

//System.out.println("Hai");

cost=3200;

break;

case "Economy class":{

cost=6950;

break;

case "Business class":{

cost=10340;

break;

}
}

break;

case "Spice Jet":

switch(fclass){

case "Travel class":{

if(no<=5){

cost=3450;

else if(no>5&&no<=10){

cost=(int)(3450*0.9);

else{

cost=(int)(3450*0.85);

break;

case "Economy class":{

if(no<=5){

cost=7945;

else if(no>5&&no<=10){

cost=(int)(7945*0.9);

else{

cost=(int)(7945*0.85);
}

break;

case "Business class":{

if(no<=5){

cost=9500;

else if(no>5&&no<=10){

cost=(int)(9500*0.9);

else{

cost=(int)(9500*0.85);

break;

break;

case "Go Air":

switch(fclass){

case "Travel class":{

cost=3300;

break;

case "Economy class":{


cost=7250;

break;

case "Business class":{

cost=9890;

break;

break;

case "IndiGo":{

switch(fclass){

case "Travel class":{

if(no<=5){

cost=3490;

else if(no>5&&no<=10){

cost=(int)(3490*0.9);

else{

cost=(int)(3490*0.85);

break;

case "Economy class":{

if(no<=5){
cost=7560;

else if(no>5&&no<=10){

cost=(int)(7560*0.9);

else{

cost=(int)(7560*0.85);

break;

case "Business class":{

if(no<=5){

cost=9990;

else if(no>5&&no<=10){

cost=(int)(9990*0.9);

else{

cost=(int)(9990*0.85);

break;

break;

int res=cost*no;
if(pay=='Y')

switch(fname){

case "Air India":

res=(int)(res*0.895);

break;

case "Spice Jet":

res=(int)(res*0.925);

break;

case "Go Air":

res=(int)(res*0.905);

break;

case "IndiGo":

res=(int)(res*0.915);

break;

System.out.println(res);
}

3. Tell the time

Solution:

import java.util.Scanner;

public class Main

public static void main(String args[])

Scanner sc=new Scanner(System.in);

//System.out.println("Enter the word:");

String s=sc.next();

String ch[]=s.split(":");

int m[]=new int[2];int count=0;

for(int i=0;i<2;i++)

int m1=Integer.valueOf(ch[i]);

m[i]=m1;

if(m[0]>=00 && m[0]<=23 && m[1]>=00 && m[1]<=59)

{ int n=sc.nextInt();

if(n<=59 && n>=0)


{

int k=m[1]+n;

if(k>59)

{ int l=m[0]+1; m[1]=k-60;

if(l>23)

System.out.println("Notification cannot be sent for the day");

else

{m[0]=l;

count++;}

else

{ m[1]=k;

count++; }

if(count!=0 && m[1]<=9)

System.out.println(m[0]+":0"+m[1]);

if(count!=0 && m[1]>9)

System.out.println(m[0]+":"+m[1]);

else

System.out.println("Input is not valid");

else

System.out.println("Input is not valid");

}
4.Fuel Quantity Calculation

Solution:

import java.util.*;

public class Main

public static void main(String[] args)

Scanner read=new Scanner(System.in);

System.out.println("Enter the amount in Rupees:");

int rs=read.nextInt();

if(rs<1)

System.out.println("Invalid Input");

else

System.out.println("Fuel rate per liter:");

float liter=read.nextFloat();

if(liter<0)

System.out.println("Invalid Input");

else

float petrol=rs/liter;

System.out.printf("%.2f Liters",petrol);

}
}

}}

5.Vowel Pair Removal

Solution:

import java.util.Scanner;

public class Main

public static void main(String args[])

Scanner sc=new Scanner(System.in);

System.out.println("Enter the word:");

String s=sc.next();int count=0;

if(s.length()>=3 && s.length()<=8)

for(int i=0;i<s.length();i++)

if(Character.isLetter(s.charAt(i)))

count++;

if(count==s.length())

for(int i=0;i<s.length();i++)

{ if(i<s.length())

if(((s.charAt(i)=='a')||(s.charAt(i)=='e')||(s.charAt(i)=='i')||(s.charAt(i)=='o')||(s.charAt(i)=='u')
)&&

((s.charAt(i+1)=='a')||(s.charAt(i+1)=='e')||(s.charAt(i+1)=='i')||(s.charAt(i+1)=='o')||(s.char
At(i+1)=='u')))
{i++;

continue;

else

System.out.print(s.charAt(i));

else

System.out.print(s.charAt(i));

//System.out.println(s);

else

System.out.println("Invalid Input");

if(s.length()>8)

System.out.println("Word length exceeds the limit");

if(s.length()<3)

System.out.println("Word length is too short");

6. MAC Validation

Solution:

import java.lang.*;

import java.util.*;

public class Main{


public static void main(String[] args){

Scanner sc=new Scanner(System.in);

String s=sc.nextLine();

int len=s.length();

int dc=0,cc=0,colonc=0,flag=0;

if(len==17){

char[] a=s.toCharArray();

for(char b:a){

if(Character.isLetter(b)){

if(b>=65&&b<=70)

cc++;

if(Character.isDigit(b)){

dc++;

if(b==':'){

colonc++;

if(!(Character.isLetter(b)||Character.isDigit(b)||b==':')){

flag++;

break;

}
}

if(flag==1){

System.out.println("Invalid Input");

// System.exit(0);

if(flag==0){

int res=cc+dc+colonc;

if(res==17){

System.out.println("Valid MAC address");

else{

System.out.println("Invalid MAC address");

else if(len<17){

System.out.println("String is too short");

else{

System.out.println("String is too long");

}
}

7. Unique products

Solution:

import java.util.Scanner;

public class Main {

public static void main(String[] args)

Scanner sc=new Scanner(System.in);

System.out.println("Enter the number of items:");

int item_count=sc.nextInt();

if(item_count<5 || item_count>20)

System.out.println("Invalid item count");

else

int item[]=new int[item_count];

int flag=1;

System.out.println("Enter the bar code ID for "+item_count+" items:");

int count=0;
for(int i=0;i<item_count;i++)

int it=sc.nextInt();

if(it<100 || it>999)

System.out.println("Invalid bar code ID");

flag=0;

break;

else

item[i]=it;

if(flag!=0)

for(int j:item)

String s="";

s=s.valueOf(j);

if(s.charAt(0)!=s.charAt(1)&&s.charAt(0)!=s.charAt(2)&&s.charAt(2)!=
s.charAt(1))

System.out.println(j);

count++;
}

if(count==0)

System.out.println("There are no item with Unique number in


the bar code ID");

else

System.out.println("There are "+count+" items with Unique


number in the bar code ID");

8.Toggle word

Solution:

import java.util.*;
class Main

public static void main(String args[])

Scanner sc=new Scanner(System.in);

System.out.println("Enter the word:");

String s=sc.next();

int length=s.length();

if(length<3)

System.out.println("Word length is too short");

else if(length>8)

System.out.println("Word length exceeds the limit");

else

char c[]=s.toCharArray();

int flag=0;

for(char c1:c)

if(Character.isLetter(c1))

flag++;

}
if(flag!=length)

System.out.println("Invalid Input");

else

int i=0;

for(char c1:c)

if(i%2==0)

System.out.print(Character.toUpperCase(c1));

i++;

else

System.out.print(c1);

i++;

9.Prime Number Multiples

Solution:
import java.util.*;

class Main

public static void main(String args[])

Scanner sc=new Scanner(System.in);

int num=sc.nextInt();

int product=1;

if(num<0 || num>32767)

System.out.println("Invalid Input");

else

while(num>0)

int a=num%10;

if(a==2 || a==3 ||a==5 || a==7)

product*=a;

num=num/10;

if(product==1)

System.out.println("No Prime Digit Found");

}
else

System.out.println(product);

10.Estimated Parcel Delivery Time

Solution:

import java.util.*;

public class Main

public static void main(String[] args)

Scanner read=new Scanner(System.in);

System.out.println("Enter the distance in Km:");

int distance=read.nextInt();

if(distance<1)

System.out.println("Invalid Input");

else

float dism=distance*1000;

float div=dism/10;

float time=div/60;

System.out.println("Estimated Time:");

System.out.printf("%.2f Minutes",time);

}}}
JAVA

1. LCM OF DAY INTERVAL/LUNCH TOGETHER/DINNER TOGETHER

INPUT: Enter the day interval of Tony : 4


Enter the day interval of Potts: 6

OUTPUT: Tony and Potts will have dinner together on 12th day.

import java.util.Scanner;
public class lcm {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the day interval of Sam:");
int n1 = sc.nextInt();
System.out.println("Enter the day interval of Riya:");
int n2 = sc.nextInt();
if(n1<=0 || n2<=0)
{
System.out.println("Given interval is not valid");
return;
}
int lcm;
lcm = (n1 > n2) ? n1 : n2;
while(true) {
if( lcm % n1 == 0 && lcm % n2 == 0 ) {
System.out.printf("Sam and Riya will have their dinner on day "+lcm);
break;
}
++lcm;
}
}
}

ALTERNATE METHOD

import java.util.Scanner;
public class Lunchlcm {
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the day interval of Tony");
int n1=sc.nextInt();
System.out.println("Enter the day interval of Potts");
int n2=sc.nextInt();
if(n1<=0 && n2<=0)
{
System.out.println("Given interval is not valid");
return;
}
int a=n1;
int b=n2;
while(n2>0)
{
if (n1 > n2)
{
n1 = n1 - n2;
} else
{
n2 = n2 - n1;
}
}
int gcd = n1;
int lcm = (a * b) / gcd;

System.out.println("Tony and Potts will have lunch together on " + lcm + " day");
}
}

*********************************************************************************************
*********************************************************************************************
**
2.SCORE OF REPEATING WORDS/ WORD REPETITION

INPUT: Enter the String: GOOD


Enter the sentence: GOOD FOOD GOOD LIFE

OUTPUT: Score is 2

import java.util.*;
class PrintMessage
{
public static void main (String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the string");
String s=sc.next();
int count=0;
int sum=2;
for(int i=0;i<s.length();i++)
{
if(Character.isDigit(s.charAt(i)) || Character.isLetter(s.charAt(i)) || s.charAt(i)==' ')
{
continue;
}
else
{
System.out.println(s+" is not valid String");
return;
}
}
System.out.println("Enter the sentence");
sc.nextLine();
String sentence=sc.nextLine();
String[] w=sentence.split(" ");
for(int i=0;i<w.length;i++)
{
if(w[i].equalsIgnoreCase(s))
{
count++;
if(count>2)
{
sum=sum*2;
}
}
}
if(count>2)
{
System.out.println("Score is "+sum);
}
else
{
System.out.println("Score is"+count);
}
}
}

*ALTERNATE METHOD

import java.util.Scanner;
public class CountWords {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String word, sentence;ed
int count = 0;
System.out.println("Enter a word:");
word = in.nextLine();
System.out.println("Enter a sentence");
sentence = in.nextLine();

if (!(word.matches("[a-z]+"))) {
System.out.println("Invalid Input");
return;
}
String words[] = sentence.toLowerCase().split(" ");
for (int i = 0; i < words.length; i++) {
if (word.equals(words[i])) {
count++;
}
}
System.out.println("Score is:" + ((int) Math.pow(2, count - 1)));
}
}
*********************************************************************************************
*********************************************************************************************
***

3)BATTERY CAPACITY

INPUT: Enter battery capacity :1230


Enter charging current value: 400

OUTPUT: 3.69 Hours

import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter battery capacity:");
double capacity = sc.nextDouble();
if(!(capacity>=1000 && capacity<=10000)) {
System.out.println("Invalid battery capacity");
return;
}
System.out.println("Enter charging current value:");
double current = sc.nextDouble();
if(!(current>=300 && current<=2100)) {
System.out.println("Invalid output current");
return;
}
double time=0.0f;
time = (capacity/current)*1.2;
System.out.println(String.format("%.2f",time)+" Hours");
}

*********************************************************************************************
*********************************************************************************************
***
4) COMBINE NUMBERS / STUDENTS WHOSE ROLLNO ARE ODD

INPUT: Entr the set of students :5


Enter the roll number :1
3
4
5
6

OUTPUT: 135

import java.util.*;
public class Main
{
public static void main(String[] args) {
System.out.println("Enter the set of students");
Scanner s=new Scanner(System.in);
int setn=s.nextInt();
if(setn<=0)
{
System.out.println(setn+" is an invalid size");
return;
}
System.out.println("Enter the roll number");
int[] rolls=new int[setn];
int oddflag=0;
for(int i=0;i<setn;i++)
{
rolls[i]=s.nextInt();
if(rolls[i]<0)
{
System.out.println(rolls[i]+" is an invalid roll number");
return;
}
if(rolls[i]%2!=0)
{
oddflag=1;
}
}
if(oddflag==0)
{
System.out.println("The "+setn+" numbers are not odd");
return;
}
String str="";
for(int i=0;i<setn;i++)
{
if(rolls[i]%2!=0)
{
str=str+rolls[i];
}
}
for(int n=0;n<str.length();n++)
{
System.out.println(str.charAt(n)+" ");
}
}
}
*********************************************************************************************
*********************************************************************************************
**

5) BIKE RENT / CALCULATING BILL AMOUNT

INPUT : Enter your name : Sam


Enter the time duration: 13
List of payment options
1)Visa card
2)Rupay card
3)Master card
Choose an option : 2

OUTPUT: Dear Sam your bill amount is 1294.80

import java.util.*;
public class Main
{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter your name");
String s=sc.nextLine();double sal=0;double disc=0;
for(int i=0;i<s.length();++i)
{
if(!Character.isLetter(s.charAt(i)))
{
System.out.println("Invalid Name");
return;
}
}
System.out.println("Enter the time duration");
int n=sc.nextInt();int n1;
if(n<=0 || n>24)
{
System.out.println("Invalid duration");
return;
}
System.out.println("List of payment options");
System.out.println("1)Visa card");
System.out.println("2)Rupay card");
System.out.println("3)Master card");
System.out.println("Chosse an option");
while(true)
{
n1=sc.nextInt();
if(n1<0||n1>3)
{
System.out.println("Try again");
}
else
{
break;
}
}
if( n1==1)
{
if(n>=5)
{
sal=120*n;
disc=(sal*0.25);
sal=sal-disc;
}
else
{
sal=n*120;
}
}
if(n1==2)
{
if(n>=5)
{
sal=120*n;
disc=(sal*0.17);
sal=(120*n)-disc;
}
else
{
sal=n*120;
}
}
if(n1==3)
{
sal=n*120;
}
System.out.print("Dear "+s+" your bill amount is ");
System.out.printf("%.2f", sal);
}
}

*********************************************************************************************
*********************************************************************************************
***
6) ODD POSITION CHAR WILL BE IN UPPERCASE & EVEN WILL BE LOWERCASE-

INPUT : school

OUTPUT : sChOol

import java.util.Scanner;
public class UPLC{
public static void main(String []args){
Scanner sc = new Scanner(System.in);
String str = sc.next();
int strlen = str.length();
for(int i = 0 ; i < str.length(); i++){
char ch = str.charAt(i);
if(!(ch >= 'a' && ch <='z' || ch >= 'A' && ch <='Z' )){
System.out.println(str+ " is an invalid input");
return;
}
}

if(strlen >= 5 && strlen <= 20){


StringBuffer updateString = new StringBuffer();
char[] charArr = str.toCharArray();
for(int i = 0 ; i < charArr.length; i++){
char ch = charArr[i];
if(i % 2 != 0){
ch = Character.toUpperCase(ch);
}
updateString.append(ch);
}
System.out.println(updateString.toString());
}
else {
System.out.println(str+ " is an invalid Length");
}
}
}

*********************************************************************************************
*********************************************************************************************
****
7) RATING SCORE

INPUT: ENTER JESSON SCORE


1
2
3
4
8
ENTER JAMES SCORE
0
2
6
5
6

OUTPUT: JESSON SCORE : 2


JAMES SCORE : 2

import java.util.Scanner;
public class Ratingscore {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter Jesson Score");
int[] a1 = new int[5];
int[] a2 = new int[5];
int f = 0;
int t = 0;
int sum = 0;
int sum1 = 0;
for (int i = 0; i < 5; i++) {
a1[i] = sc.nextInt();
if (a1[i] < 0) {
f = 1;
t = a1[i];
break;
}
}
if (f == 1) {
System.out.println(t + " is invalid");
} else {
System.out.println("Enter James Score");
for (int j = 0; j < 5; j++) {
a2[j] = sc.nextInt();
if (a2[j] < 0) {
f = 1;
t = a2[j];
break;
}
}
if (f == 1) {
System.out.println(t + " is invalid");
} else {
for (int k = 0; k < 5; k++) {
if (a1[k] > a2[k]) {
sum++;
}
if (a1[k] < a2[k]) {
sum1++;
}
}
System.out.println("Jesson Score");
System.out.println(sum);
System.out.println("James Score");
System.out.println(sum1);
}
}
}
}

**ALTERNATE METHOD:

import java.util.Scanner;
public class minmax {
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
int jesson=0,james=0,c=0;
int a[]=new int[5];
int b[]=new int[5];
System.out.println("Enter Jesson Score");
for(int i=0;i<a.length;i++)
{
a[i]=sc.nextInt();
if(a[i]<0)
{
System.out.println("Invalid");
Runtime.getRuntime().halt(0);
}
}
System.out.println("Enter James Score");
for(int i=0;i<b.length;i++)
{
b[i]=sc.nextInt();
if(b[i]<0)
{
System.out.println("Invalid");
Runtime.getRuntime().halt(0);
}
}
if(a.length==b.length)
{
for(int i=0;i<a.length;i++)
{
if(a[i]>b[i])
{
jesson++;
}
else if(a[i]<b[i])
{
james++;
}
else if(a[i]==b[i])
{
c++;
}
}
System.out.println("Jesson Score: "+jesson);
System.out.println("James Score: "+james);
}
else{
System.out.println("Length not same");
}
}
}

*********************************************************************************************
*******************************************************************************

8.COUNT OF UPPERCASE AND COUNT OF LOWERCASE & OUTPUT WILL BE IN THE FORM OF
(UP-LC)

INPUT : HosTEL

OUTPUT: 4-2=2

import java.util.Scanner;

public class ContNext {


public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the string");
String str=sc.nextLine();
int uc=0,lc=0;
if(str.matches("[A-Za-z ]+")&&str.length()<10) {
for(int i=0;i<str.length();i++)
if(Character.isUpperCase(str.charAt(i))) {
uc++;
}
else if(Character.isLowerCase(str.charAt(i))){
lc++;
}
System.out.println(uc-lc);
}
}
}
*********************************************************************************************
*******************************************************************************
9) PRODUCT of COUNT of UPPERcase

andLOWERcaseletters

INPUT: ABsdEr

OUTPUT: 6 (3*3)

import java.util.Scanner;
public class minmax {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the String");
String s = sc.nextLine();
int upper = 0;
int lower = 0;
int i;
if (s.matches("[a-zA-Z]+")) {
for (i = 0; i < s.length(); i++) {
char c = s.charAt(i);
if (c >= 'A' && c <= 'Z') {
upper++;
}
if (c >= 'a' && c <= 'z') {
lower++;
}
}
System.out.println(upper * lower);
}
else
{
System.out.println("Invalid String");
}

}
}

*********************************************************************************************
******************************************************************************
10.Count of UPPERcase and LOWERcase and their difference

Enter the String: ColLEgE


Count of uppercase is : 4
Count of lowercase is : 3
Hence the ans is : 1

import java.util.Scanner;
public class MyClass {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the String ");
String str = sc.next();
int strlen = str.length();
for(int i =0; i < str.length() ; i++)
{ char ch = str.charAt(i);
if(!(ch >='a' && ch <= 'z' || ch >= 'A' && ch <= 'Z')){
System.out.println(str + " is an invalid String");
return;
}
}

if(strlen > 0 && strlen <= 10){


int upper = 0, lower = 0, ans = 0;

for(int i = 0; i < str.length(); i++)


{
char ch = str.charAt(i);
if (ch >= 'A' && ch <= 'Z')
upper++;
else if(ch >= 'a' && ch <= 'z')
lower++;
}
ans = upper - lower;
System.out.println("count of uppercase is :"+ upper);
System.out.println("count of lowercase is :"+ lower);
System.out.println("Hence the ans is :"+ ans);
}
else {
System.out.println(str + " is an invalid String");
}
}
}
*********************************************************************************************
*******************************************************************************
11.PUBLIC DISTRIBUTION

INPUT : OKR

OUTPUT : 90

import java.util.*;
public class Main
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
String str = in.nextLine();
int l=str.length();
if(l>5 || l<2)
{
System.out.println("Invalid Input");
}
else
{
int sum=0,flag=0;
for(int i=0;i<l;i++)
{
char c=str.charAt(i);
if(c=='O')
{
sum=sum+24;
}
else if(c=='K')
{
sum=sum+36;
}
else if(c=='S')
{
sum=sum+42;
}
else if(c=='R')
{
sum=sum+30;
}
else if(c=='W')
{
sum=sum+44;
}
else
{
flag=1;
}
}
if(flag==1)
{
System.out.println("Invalid Input");
}
else
{
System.out.println(sum);
}
}
}
}
*********************************************************************************************
******************************************************************************

12.LOTTERY TICKETS

INPUT: Enter the Starting range


23467
Enter the Ending range
23477

OUTPUT: 23469
23472

import java.util.*;
public class Main {
public static void main(String args[])
{
int i,c,n,sum,count;
sum=0;count=0;n=0;c=0;i=0;
Scanner sc = new Scanner(System.in);
System.out.println("Enter the Starting range");
int a = sc.nextInt();
String str = Integer.toString(a);
if(str.length()!=5)
{
System.out.println(str + " is an invalid input");
System.exit(0);
}

System.out.println("Enter the Ending range");


int b = sc.nextInt();
String str1 = Integer.toString(b);
if(str1.length()!=5)
{
System.out.println(str1 + "is an invalid input");
System.exit(0);
}

if(a>b)
{
System.out.println(a+" and "+b+" are invalid serial numbers");
System.exit(0);

}
for(i=a;i<=b;i++)
{
n=i;
while(n!=0)
{
c=n%10;
sum=sum+c;
n=n/10;
}
if((sum%3==0)&&((sum/3)%2==0))
{
System.out.println(i + " ");
count++;
}
sum=0;
}
if(count==0)
{
System.out.println("Eligible tickets are not available from "+a+" to "+b);
System.exit(0);
}
}
}

*********************************************************************************************
******************************************************************************
13.COFFEE STALL NUMEROLOGY

INPUT : Enter the Staff Name


Coffee Bar

OUTPUT : Coffee Bar satisfies the numerology logic

import java.util.*;
public class Main{
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the Staff Name");
String name = sc.nextLine();
int count=0;
for(int i=0;i<name.length();i++){
if(Character.isAlphabetic(name.charAt(i)) || name.charAt(i)==' '){
count++;
}
}
if(count==name.length()){
String str = name.replace(" ","");
int sum=0;
for(int i=0;i<str.length();i++){
sum += i;
}
if(sum%2==0){
System.out.println(name+" satisfies the numerology logic");
}else{
System.out.println(name+" does not satisfy the numerology logic");
}
}else{
System.out.println("Invalid Input");
}
}
}

*ALTERNATE METHOD USING -matches for same question

import java.util.*;
public class Main{
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the Staff Name");
String name = sc.nextLine();
if(name.matches("[a-zA-Z ]+")){
String str = name.replace(" ","");
int sum=0;
for(int i=0;i<str.length();i++){
sum += i;
}
if(sum%2==0){
System.out.println(name+" satisfies the numerology logic");
}else{
System.out.println(name+" does not satisfy the numerology logic");
}
}else{
System.out.println("Invalid Input");
}
}
}

*ALTERNATE METHOD

import java.util.Scanner;
public class CoffeeHouse {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the Stall Name");
String name = sc.nextLine();
if (name.matches("^[A-Za-z ]*$")) {
int sum = 0;
String fName = name.replaceAll(" ", "");
for (int i = 0; i < fName.length(); i++)
sum = sum + i;
if (sum % 2 == 0) {
System.out.println(name + " satisfies the numerology logic");
} else {
System.out.println(name + " not satisfies the numerology logic");
}
} else
System.out.println("Invalid Input");
}
}

*********************************************************************************************
******************************************************************************

14.ANAGRAM OR TWO WORDS OF SAME LETTER

INPUT : cat
act

OUTPUT: Same

import java.util.Arrays;
import java.util.Scanner;
public class minmax {
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter sentence 1");
String s1=sc.next();
s1=s1.toLowerCase();
System.out.println("Enter sentence 2");
String s2=sc.next();
s2=s2.toLowerCase();
if(s1.length()!=s2.length())
{
System.out.println("Invalid");
}
if(s1.matches("^[a-zA-Z]*")){
char c1[] = s1.toLowerCase().toCharArray();
char c2[] = s2.toLowerCase().toCharArray();
Arrays.sort(c1);
Arrays.sort(c2);
if (Arrays.equals(c1, c2)) {
System.out.println(s1 + " and " + s2 + " contain the same characters");
} else {
System.out.println(s1 + " and " + s2 + " contain the different characters");
}
}
else
{
System.out.println("Invalid");
}
}
}

ALTERNATE METHOD:

import java.util.*;
public class Main{
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
String first=sc.next();
String secound=sc.next();
String word1=Main.checker(first);
String word2=Main.checker(secound);
if(word1.equals(word2)){
System.out.println("Same");
}else{
System.out.println("Different");
}
}
public static String checker(String word){
char arr[]=word.toCharArray();
Arrays.sort(arr);
int index=0;
for(int i=0;i<arr.length;i++){
int j;
for(j=0;j<i;j++){
if(arr[j]==arr[i]){
break;
}
}
if(i==j){
arr[index++]=arr[i];
}
}
char arr1[]=Arrays.copyOf(arr,index);
String newword= new String(arr1);
return newword;
}
}

ALTERNATE METHOD

import java.util.*;
public class arraysquare {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int f1=0,f2=0;
String s1=sc.nextLine();
char c1[]=s1.toCharArray();
String s2=sc.nextLine();
char c2[]=s2.toCharArray();
for(int i=0;i<c1.length;i++)
{
f1=0;
for(int j=0;j<c2.length;j++)
{
if(c1[i]==c2[j])
{
f1=1;
break;
}
}
if(f1==0)
{
break;
}
}
for(int i=0;i<c2.length;i++)
{
f2=0;
for(int j=0;j<c1.length;j++)
{
if(c2[i]==c1[j])
{
f2=1;
break;
}
}
if(f2==0)
{
break;
}
}
if(f1==1 && f2==1)
{
System.out.println("Same Char");
}
else{
System.out.println("Different char");
}
}
}

*********************************************************************************************
*****************************************************************************
15.SUMMATION OF EVEN NUMBERS IN THE ARRAY

INPUT : Enter array size


4
Enter array elements in 1st array
2
4
6
8
Enter array elements in 2nd array
1
2
5
2

OTPUT: 0
6
0
10

import java.util.*;
public class Main
{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter array size");
int n=sc.nextInt();
if(n>=10 || n<1)
{
System.out.println(n+" is an invalid input");
Runtime.getRuntime().halt(0);
}
int arr1[]=new int[n];
int arr2[]=new int[n];
int result[]=new int[n];
System.out.println("Enter array elements in 1st array");
for(int i=0;i<n;i++)
{
arr1[i]=sc.nextInt();
}
System.out.println("Enter array elements in 2nd array");
for(int i=0;i<n;i++)
{
arr2[i]=sc.nextInt();
}
//PROGRAM LOGIC
int count=0;
for(int i=0;i<n;i++)
{
if((arr1[i]%2==0 || arr1[i]==0) && (arr2[i]%2==0 || arr2[i]==0))
{
result[i]=arr1[i]+arr2[i];
count++;
}
else
{
result[i]=0;
}
}
if(count==0)
{
System.out.println("No even number is present in an Array");
}
for(int i=0;i<n;i++)
{
System.out.println(result[i]);
}
}
}

*********************************************************************************************
******************************************************************************
16.RUNNERS COMPETITION

INPUT :Enter the number of runners


5

Enter the runner details


Robert,9.38
Richard,9.35
Christiano,9.35
Williams,9.36
Vinix,9.35

OUTPUT: Richard
Christiano
Vinix

import java.util.*;
public class Main{
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
sc.useDelimiter("\n");
System.out.println("Enter the number of runners");
int n = sc.nextInt();
if(n<=0 || n>10){
System.out.println(n+" is an invalid number of runners");
Runtime.getRuntime().halt(0);
}
String temp = "";
String name[] = new String[n];
float time[] = new float[n];
System.out.println("Enter the runner details");
for(int i=0;i<n;i++){
temp = sc.next();
String temparr[] = temp.split(",");
name[i] = temparr[0];
time[i] = Float.parseFloat(temparr[1]);
if(time[i]>12 || time[i]<8){
System.out.println(time[i]+" is an invalid input");
Runtime.getRuntime().halt(0);
}
}
int maxcount = 0;
float maxrep = 0;
for(int i=0;i<n;i++){
int count = 0;
for(int j=i+1;j<n;j++){
if(time[i]==time[j]){
count++;
}
}
if(count>=maxcount){
maxcount = count;
maxrep = time[i];
}
}
if(maxcount==n){
System.out.println(n+" runners have same timing");
}
else if(maxcount==0){
System.out.println("No runners with same time.");
}
else{
for(int i=0;i<n;i++){
if(maxrep == time[i]){
System.out.println(name[i]);
}
}
}
}
}

****ALTERNATE METHOD****

public static void main(String[] args) {


// TODO code application logic here
Scanner sc=new Scanner(System.in);
System.out.println("Enter the no of students");
int n=sc.nextInt();
if(n>10)
{
System.out.println(n+" is an invalid nuber of runners");
return;
}
String input;
String name[]=new String[n]; //name array
Double time[]=new Double[n]; //another time array
System.out.println("Enter the details");
for(int i=0;i<n;i++)
{
input=sc.next();
String[] a=input.split(","); // a[0] stores name a[1] stores time
name[i]=a[0]; //string->string
time[i]=Double.parseDouble(a[1]); //double<-string
if(time[i]<8 || time[i]>12)
{
System.out.println(time[i]+" is an invalid input");
return;
}

}
boolean flag = true;

double min=time[0];
int index=0;

for(int i=0;i<n;i++)
{
if(time[i]<min)
{
min=time[i];
//index=i;
}

if(min!=time[i])
{
flag=false;
System.out.println(name[i-1]);
}

}
if (flag) System.out.println(n+" runners have same timing");
}

}
*********************************************************************************************
******************************************************************************
17.REEDME

INPUT : Enter the customer name


Abi
Enter the category
History
Enter the quantity of books ordered
2900

OUTPUT : Total cost is 334080.0


import java.util.*;
public class Main{
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the customer name");
String name = sc.nextLine();
System.out.println("Enter the category");
String category = sc.nextLine();
category = category.toLowerCase();

if(!category.equals("adventure") && !category.equals("comics") && !category.equals("history") && !categ


ory.equals("thriller")){
System.out.println(category+" is invalid category");
Runtime.getRuntime().halt(0);
}
System.out.println("Enter the quantity of books ordered");
int quantity = sc.nextInt();
if(quantity <= 0){
System.out.println(quantity+" is an invalid quantity");
Runtime.getRuntime().halt(0);
}
int discount = 0;
int price = 0;
if(category.equals("adventure")){
price = 150;
if(quantity>=1700)
discount = 5;
}
else if(category.equals("comics")){
price = 230;
if(quantity>=1950)
discount = 5;
}
else if(category.equals("history")){
price = 120;
if(quantity>=2600)
discount = 4;
}
else if(category.equals("thriller") && quantity>=1700){
price = 190;
if(quantity>=6300)
discount = 3;
}
float totalcost = (price*quantity) - (price*quantity*discount/100);
System.out.println("Total cost is "+totalcost);
}
}

*********************************************************************************************
******************************************************************************
18)HARSHAD NUMBER (Sum of digit completely divide that

number) For example: 18= 1+8=9 and in 18/9 remainder is 0

INPUT: Enter array size: 5


Enter array elements : 18 14 12 24 13

OUTPUT: 18 12 24

import java.util.Scanner;
public class Harshad {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the number of values");
int n = sc.nextInt();
int i;
System.out.println("Enter the numbers");
int[] a = new int[n];
if (n > 0)
{
int flag = 0;
int k = 0;
for (i = 0; i < n; i++)
{
k = sc.nextInt();
if (k > 9)
a[i] = k;
else
{
flag = 1;
break;
}
}
if (flag != 1)
{
int c = 0;
for (i = 0; i < n; i++)
{
int x = a[i];
int sum = 0;
do {
int r = x % 10;
sum = sum + r;
x = x / 10;
}
while (x != 0);
if (a[i] % sum == 0)
{
c++;
System.out.println(a[i]);
}
}
if (c == 0)
System.out.println("The " + n + " values are not harshad number");
}
else
System.out.println("Provided " + k + " is not valid");
} else
System.out.println(n + " is an invalid input");
}
}
****ALTERNATE METHOD******

import java.util.Scanner;
class Main
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number of values");
int n=sc.nextInt();
System.out.println("Enter the numbers");
int a[]=new int[n];
if(n>0)
{
int flag=0;
int k=0;
for(int i=0;i<n;i++)
{
k=sc.nextInt();
if(k>9) a[i]=k; else
{
flag=1;
break;
}
}
if(flag!=1)
{
int c=0;
for(int i=0;i<n;i++)
{
int x=a[i];
int sum=0;
do
{
int r=x%10; sum=sum+r; x=x/10;
}while(x!=0);
if(a[i]%sum==0)
{ c++;
System.out.println(a[i]);
}
}
if(c==0)
System.out.println("The "+n+" values are not harshad number");
}else
System.out.println("Provided "+k+" is not valid");
}else
System.out.println(n+" is an invalid input");
}
}
*********************************************************************************************
*********************************************************************************************
*******
19) VIDEO GAME PLAYER (PS1)

INPUT : Enter the amount


18000
Enter the Video Game Player Type
PS4

OUTPUT: You can buy PS4

public class PS {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the amount");
int amount = sc.nextInt();
if (amount >= 3000) {
System.out.println("Enter the Video Game Player Type");
String type = sc.next();
if (type.matches("[P][S][1-5]")) {
if (type.equals("PS1")) {
if (amount >= 5000) {
System.out.println("You can buy PS1");
} else {
System.out.println("You need more money to buy a PS1");
}
} else if (type.equals("PS2")) {
if (amount >= 7800) {
System.out.println("You can buy PS2");
} else {
System.out.println("You need more money to buy a PS2");
}
} else if (type.equals("PS3")) {
if (amount >= 9500) {
System.out.println("You can buy PS3");
} else {
System.out.println("You need more money to buy a PS3");
}
} else if (type.equals("PS4")) {
if (amount >= 12000) {
System.out.println("You can buy PS4");
} else {
System.out.println("You need more money to buy a PS4");
}
} else if (type.equals("PS5")) {
if (amount >= 15000) {
System.out.println("You can buy PS5");
} else {
System.out.println("You need more money to buy a PS5");
}
}
} else {
System.out.println(type + " is Invalid Type");
}
} else {
System.out.println(amount + " is too less");
}
}
}

*********************************************************************************************
*********************************************************************************************
****
20) ABSOLUTE DIFFERENCE / ALTERNATE SUM DIFFERENCE

INPUT :Enter number


6
Enter values
12
13
6
8
9
7
(((( logic: (12-7=a
13-9=b
6-8=c
a+b+c=ans)))))

OUTPUT 2
3
4
5
5-2=3
4-3=1
So 3+1= 4
*/

import java.util.*;
public class AltDiff {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int sum=0;
int n=sc.nextInt();
int a[]=new int[n];
for(int i=0;i<n;i++)
{
a[i]=sc.nextInt();
}
for(int i=0;i<n/2;i++)
{
sum+=Math.abs(a[i]-a[n-i-1]);
}
System.out.println(sum);
}
}
*********************************************************************************************
*********************************************************************************************
*****
21.CHARACTER
ADDITION

INPUT : Enter : 3
Enter the sentences:
ks436
Agh73
7222

OUTPUT: 222
240
0

import java.util.*;
public class arraysquare{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int sum=0;
System.out.println("Enter:");
int n=sc.nextInt();
if(n<=0)
{
System.out.println("The number of sentences "+n+" is invalid");
return;
}
System.out.println("Enter the sentences:");
String str[]=new String[n];
for(int i=0;i<n;i++)
{
str[i]=sc.next();
}
for(int i=0;i<str.length;i++)
{
String s=str[i].replaceAll("[0-9]","");
for(int j=0;j<s.length();j++)
{
char c=s.charAt(j);
int ascii=c;
sum+=ascii;
}
System.out.println(sum);
sum=0;
}

}
}

*********************************************************************************************
******************************************************************************************
22. REVERSE FIRST HALF/MIDDLE LETTER of the string if string length is ODD

Input:
if length of string is even, the reverse the string:
Ex: Food
Output:
dooF

Input:
If length of the string is odd,then find the middle char and then ,reverse the string till mid char and print remain char
acters as it is.
Ex: Samsung
Output:
maSsung

package FinalAss;
import java.util.*;
public class MidLett {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
String str=sc.nextLine();//rahul
int len=str.length();
if(len%2==0)
{
StringBuilder sb=new StringBuilder(str);
sb.reverse();
System.out.println(sb.toString());
}
else if(len%2!=0)
{
System.out.println("Length of string is " +len);
int mid=len/2;
mid++;
System.out.println("Substring of string is "+mid);
String substr=str.substring(0,mid-1);
String remainSub=str.substring(mid-1,len);
StringBuilder sb=new StringBuilder(substr);
sb.reverse();
System.out.println(sb.toString()+remainSub);

}
}
}

ALTERNATE METHOD:::

import java.util.Scanner;
import java.util.regex.Pattern;
public class minmax {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
String str=sc.nextLine();//rahul
if(!Pattern.matches("[A-Za-z]+",str))
{
System.out.println(str+" is not a valid string");
return;
}
else if(str.length()<2)
{
System.out.println("Size of string "+str.length()+" is too small");
return;
}
int len=str.length();
if(len%2==0)
{
StringBuilder sb=new StringBuilder(str);
sb.reverse();
System.out.println(sb.toString());
}
else if(len%2!=0)
{
int mid=len/2;
String substr=str.substring(0,mid);
String remainSub=str.substring(mid,len);
StringBuilder sb=new StringBuilder(substr);
sb.reverse();
System.out.println(sb.toString()+remainSub);

}
}
}

*********************************************************************************************
*********************************************************************************************
*****

23 .ONLINE SHOPPING

input:
enter the product
laptop
Actual price
45000
exchange?
yes
bill amount:
27000.00

import java.util.*;
public class arraysquare {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the Product:");
String prod=sc.nextLine();
int ed=0,pd=0;
if(prod.equals("Mobile"))
{
ed=15;
pd=15;
}
else if(prod.equals("Laptop"))
{
ed=20;
pd=20;
}
else if(prod.equals("Headset"))
{
ed=0;
pd=10;
}
else if(prod.equals("Charger"))
{
ed=0;
pd=5;
}
else{
System.out.println("Not available");
return;
}
System.out.println("Enter the actual Price: ");
int price=sc.nextInt();
if(price<100)
{
System.out.println("Invalid Price");
return;
}
System.out.println("Do u want to Exchange?");
String exc=sc.next();
if(exc.equals("Yes") || exc.equals("yes"))
{
double ap=price-(price*pd)/100;
double ev=(price*ed)/100;
double total=ap-ev;
System.out.printf("Total=%.2f",total);
}
else if(exc.equals("No") || exc.equals("no"))
{
double total=price-(price*pd)/100;
System.out.printf("Total=%.2f",total);
}
else
{
System.out.println("Invalid Option");
}
}
}

*********************************************************************************************
********************************************************************************************
24 .OPERATOR FOUND

input:
45
23

22
output
45-23=22

import java.util.*;
public class arraysquare {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter n1 and n2:");
int n1=sc.nextInt();
if(n1>0)
{
int n2=sc.nextInt();
if(n2>0)
{
System.out.println("Enter n3:");
int n3=sc.nextInt();
if(n3>0)
{
if(n1+n2==n3)
{
System.out.println(n1+"+"+n2+"="+n3);
}
else if(n1-n2==n3)
{
System.out.println(n1+"-"+n2+"="+n3);
}
else if(n1*n2==n3)
{
System.out.println(n1+"*"+n2+"="+n3);
}
else if(n1/n2==n3)
{
System.out.println(n1+"/"+n2+"="+n3);
}
else
{
System.out.println(n3+" is an invalid answer");
}
}
else{
System.out.println("Invalid");
}
}
else{
System.out.println("Invalid");
}
}
else{
System.out.println("Invalid");
}

}
}

***ALNERNATE METHOD****

import java.util.*;
public class Main{
public static void main(String args[]){
Scanner sc = new Scanner(System.in);

System.out.println("Enter the n1 and n2");


int n1 = sc.nextInt();
if(n1<=0){
System.out.println(n1+" is an invalid number");
return;
}
int n2 = sc.nextInt();
if(n2<0){
System.out.println(n2+" is an invalid number");
return;
}
boolean b = false;
System.out.println("Function answer n3");
int n3 = sc.nextInt();

if((n1+n2)==n3){
System.out.println(n1+"+"+n2+"="+n3);
b=true;
}
if((n1-n2)==n3){
System.out.println(n1+"-"+n2+"="+n3);
b=true;
}
if((n1*n2)==n3){
System.out.println(n1+"*"+n2+"="+n3);
b=true;
}
if((n1/n2)==n3){
System.out.println(n1+"/"+n2+"="+n3);
b=true;
}
if(b== false){
System.out.println(n3+" is an invalid number");
}
}
}

*********************************************************************************************
*********************************************************************************************
****

25 .PRODUCT EQUAL SUM

INPUT : Enter the array size


4
Enter the elements of the first array
12
35
56
34
Enter the elements of the second array
261
195
112
813
OUTPUT: 35,195
34,813

import java.util.*;
public class arraysquare
{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the array size");
int n=sc.nextInt();
if(n<=0)
{
System.out.println("Invalid array size");
return;
}
int a[]=new int[n];
System.out.println("Enter the elements of the first array");
for(int i=0;i<n;i++)
{
a[i]=sc.nextInt();
}
System.out.println("Enter the elements of the second array");
int b[]=new int[n];
for(int i=0;i<n;i++)
{
b[i]=sc.nextInt();
}
int x[]=new int[n];
int y[]=new int[n];
for(int i=0;i<n;i++)
{
int c=a[i];
int prod=1;
while(c!=0)
{
prod*=(c%10);
c/=10;
}
x[i]=prod;
prod=0;
}
for(int i=0;i<n;i++)
{
int s=b[i];
int sum=0;
while(s!=0)
{
sum+=(s%10);
s/=10;
}
y[i]=sum;
sum=0;
}
for(int i=0;i<n;i++)
{
if(x[i]==y[i])
{
System.out.println(a[i]+","+b[i]);
}
}
}
}

*********************************************************************************************
*********************************************************************************************
*

26. UNIQUE CHAR

input:
LIfe is inherently risky

output:
life is ihrtly risky

package FinalAss;
import java.util.*;
public class nonuniquetwo {
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
String sentence = sc.nextLine();
String[] words = sentence.split(" ");
for(String word : words)
{
System.out.print(getUnique(word) + " ");
}
sc.close();
}
public static String getUnique(String str)
{
StringBuffer sb = new StringBuffer();
for(int i = 0; i<str.length(); i++)
{
if(countFrequency(str.charAt(i), str) == 1)
{
sb.append(str.charAt(i));
}
}
String result = sb.toString();
return result;
}
public static int countFrequency(char c, String str)
{
int count = 0 ;
for(int i = 0; i<str.length(); i++)
{
if(str.charAt(i) == c)
{
count++;
}
}
return count;
}
}

***ALTERNATE METHOD*****

import java.util.*;
public class Main
{
public static void main(String[] args)
{
System.out.println("Enter the String");
Scanner sc=new Scanner(System. in);
String str=sc.nextLine();
String output="";
String[] word=str.split(" ");
for(int i=0;i<word.length;i++)
{
for(int j=0;j<word[i].length();j++)
{
int count=0;
char c=word[i].charAt(j);
for(int k=0;k<word[i].length();k++)
{
if(c==word[i].charAt(k))
count++;
}
if(count==1)
{
output+=Character.toLowerCase(c);
}
}
output+=" ";
}
System.out.println(output);
}
}

*********************************************************************************************
*********************************************************************************************
*
27. BOX SIZE

INPUT : Enter the box size


6
Enter the numbers
5
55
3
59
42
8
OUTPUT: 32 is even its a valid box

import java.util.Scanner;
public class minmax {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the box size");
int a=sc.nextInt();
if(a<=0)
{
System.out.println(a+" is an invalid box size");
return;
}
int b[]=new int[a];
int c=0,sum=0,temp=0;
System.out.println("Enter the numbers");
for(int i=0;i<a;i++)
{
b[i]=sc.nextInt();
if(b[i]<=0)
{
System.out.println(b[i]+" is an invalid input");
return;
}
}
for(int i=0;i<a;i++)
{
c=b[i]%10;
sum+=c;
c=0;
}
if(sum%2==0)
{
System.out.println(sum+" is even its a valid box");
return;
}
else
{
System.out.println(sum+" is odd its an invalid box");
return;
}

}
}
****ALTERNATE METHOD***********

Box consists of n numbers and n>0


Enter the numbers and numbers should be greater than 0 and add all the last digits of the numbers.If the sum is
even print valid box else invalid box

Input:
Enter size:5
Enter numbers:
2
34
456
67
123

22 is even it's a valid box

Explanation:
22=(2+4+6+7+3)
Similarly for invalid box also

public class BoxGame {

public static void main(String[] args) {


Scanner sc = new Scanner(System.in);
System.out.println("Enter the box size");
int size = sc.nextInt();
int n=0;
int sum=0;
if(size<=0) {
System.out.println(size+" is an invalid box size");
return;
} else {
System.out.println("Enter the numbers");
int [] arr = new int [size];
for(int i=0;i<size;i++) {
arr[i] = sc.nextInt();
}
for(int i=0;i<size;i++) {
if(arr[i]<=0) {
System.out.println(arr[i]+" is an invalid input");
return;
}
}
for(int i=0;i<size;i++) {
n = arr[i]%10;
sum = sum+n;
}
if(sum%2==0) {
System.out.println(sum+" is even its a valid box");
}else {
System.out.println(sum+" is odd its an invalid box");
}
}

}
********************************************************************************************
****************************************************
28. ORDER IDENTIFICATION:(check where elements are in ascending

order) INPUT : Enter the array size : 5


Enter the elements: 32
44
55
66
77

OUTPUT : 32 44 55 66 77 are in ascending order

import java.util.Arrays;
import java.util.Scanner;

public class orderidentification {


public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the array size");
int a=sc.nextInt();
if(a<2 || a>10)
{
System.out.println(a+" is not a valid array size");
return;
}
int b[]=new int[a];
int count=0;
System.out.println("Enter the elements");
for(int i=0;i<a;i++)
{
b[i]=sc.nextInt();
}
int d[]= Arrays.copyOf(b,b.length);
Arrays.sort(d);

if(Arrays.equals(b,d))
{
count++;
}
if(count>0)
{
for(int i=0;i<b.length;i++)
{
System.out.print(b[i]+" ");

}
System.out.print("are in ascending order");
return;
}
else
{
for(int i=0;i<a;i++)
{
System.out.print(b[i]+" ");
}
System.out.print("are not in ascending order");
return;
}
}
***ALTERNATE METHOD***

public class ascendingDesceding {


public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter array size: ");
int n = sc.nextInt();
int[] arr = new int[n];
int[] temp = new int[n];
if (n < 2 || n > 10) {
System.out.println("Invalid size");
return;
}
for (int i = 0; i < n; i++) {
arr[i] = sc.nextInt();
temp[i]=arr[i]; //store the array elements in temp array for comaparison later
}
Arrays.sort(arr); //sort the original array
int count=0;
for(int i=0;i<n;i++) {
if(arr[i]==temp[i]){ //checking if elements of sorted array is equal to
temp array
count++;
} else {
count=0;
break;
}}
if(count!=0) {
System.out.println("All elements are in ascending order");
} else {
System.out.println("Elements are not in ascending order");
}}}

********************************************************************************************
********************************************************************************************
********************************
29) DATE ,MONTH AND

YEAR INPUT:13081995

OUTPUT: date: 13
month: 08
year: 1998

import java.util.Scanner;
public class minmax {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
String str=sc.nextLine();
int n=str.length();
for(int i=0;i<str.length() ;i++)
{
if(!(str.charAt(i)>='0' && str.charAt(i)<='9'))
{
System.out.println("Invalid input");
return;
}
if(n!=8)
{
System.out.println("Enter valid date");
return;
}
}
String date=str.substring(0,2);
String mon=str.substring(2,4);
String year=str.substring(4,8);

System.out.println("date:"+date);
System.out.println("Month:"+mon);
System.out.print("Year:"+year);

}
}

*********************************************************************************************
*********************************************************************************************
*
30) MEGA MART CUSTOMER IDENTIFICATION(String and SUBSTRING)

import java.util.*;
public class arraysquare{
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the customer id");
String cid = sc.next();
String shop = cid.substring(0,4);
//System.out.println("shop");
if(!shop.equals("Mega")){
System.out.println("Invalid Shop Name");
Runtime.getRuntime().halt(0);
}
String type = cid.substring(4,cid.length()-3);
//System.out.println(type);
if(!type.equals("Silver") && !type.equals("Gold") && !type.equals("Platinum")){
System.out.println("Invalid Customer Type");
Runtime.getRuntime().halt(0);
}
int mid = Integer.parseInt(cid.substring(cid.length()-3,cid.length()));
//System.out.println(mid);
if(mid<=99 || mid>=1000){
System.out.println("Invalid Member id");
Runtime.getRuntime().halt(0);
}
System.out.println("Welcome Mega Mart "+type+" Customer");

}
}

*********************************************************************************************
***********************************
31) MALE AND FEMALE COUNT

INPUT: MmFMff
OUTPUT: 3 MALE
3 FEMALE

import java.util.Scanner;
import java.util.regex.*;
public class minmax {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
String s=sc.nextLine();
int count1=0;
int count2=0;
if(Pattern.matches("[MmFf ]+",s)){
for (int i = 0; i < s.length(); i++) {
if (s.charAt(i) == 'M' || s.charAt(i) == 'm') {
count1++;
} else if (s.charAt(i) == 'F' || s.charAt(i) == 'f') {
count2++;
}
}
System.out.println(count1 + " Male");
System.out.println(count2 + " Female");
}
else
{
System.out.println("Invalid Input");
}
}
}
*********************************************************************************************
*********************************************************************************************
***
32) RAINFALL

INPUT: Enter the length of the roof in meters: 4


Enter the breadth of the roof in meters: 3
Enter the rainfall level: 3

OUTPUT: 360.00 Litres

import java.util.Scanner;
public class minmax {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
System.out.println("Enter the length of the roof in meters");
double l=sc.nextDouble();
if(l<=0)
{
System.out.println("Invalid Length");
return;
}
System.out.println("Enter the breadth of the roof in meters");
double b=sc.nextDouble();
if(b<=0)
{
System.out.println("Invalid breadth");
return;
}
System.out.println("Enter the rainfall level");
double r=sc.nextDouble();
if(r<=0)
{
System.out.println("Invalid rainfall");
return;
}
double h;
h=(l*b) *(r*10);
System.out.println(String.format("%.2f",h)+"Litres");
}
}

*********************************************************************************************
*********
33) NUMEROLOGY NAME CHECKING

import java.util.*;
import java.util.regex.Pattern;

public class arraysquare{


public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the name");
String a=sc.next();
if(!Pattern.matches("[A-Za-z]+",a))
{
System.out.println(a+" is an Invalid name");
return;
}
int sum=0;
char b[]=a.toCharArray();
for(int i=0;i<b.length;i++)
{
if(b[i]=='A'||b[i]=='a')
{
sum+=1;
}
else if(b[i]=='B'||b[i]=='b')
{
sum+=2;
}
else if(b[i]=='C'||b[i]=='c')
{
sum+=3;
}
else if(b[i]=='D'||b[i]=='d')
{
sum+=4;
}
else if(b[i]=='E'||b[i]=='e')
{
sum+=5;
}
else if(b[i]=='F'||b[i]=='f')
{
sum+=6;
}
else if(b[i]=='G'||b[i]=='g')
{
sum+=7;
}
else if(b[i]=='H'||b[i]=='h')
{
sum+=8;
}
else if(b[i]=='I'||b[i]=='i')
{
sum+=9;
}
else if(b[i]=='J'||b[i]=='j')
{
sum+=10;
}
else if(b[i]=='K'||b[i]=='k')
{
sum+=11;
}
else if(b[i]=='L'||b[i]=='l')
{
sum+=12;
}
else if(b[i]=='M'||b[i]=='m')
{
sum+=13;
}
if(b[i]=='N'||b[i]=='n')
{
sum+=14;
}
if(b[i]=='O'||b[i]=='o')
{
sum+=15;
}
if(b[i]=='P'||b[i]=='p')
{
sum+=16;
}
if(b[i]=='Q'||b[i]=='q')
{
sum+=17;
}
if(b[i]=='R'||b[i]=='r')
{
sum+=18;
}
if(b[i]=='S'||b[i]=='s')
{
sum+=19;
}
if(b[i]=='T'||b[i]=='t')
{
sum+=20;
}
if(b[i]=='U'||b[i]=='u')
{
sum+=21;
}
if(b[i]=='V'||b[i]=='v')
{
sum+=22;
}
if(b[i]=='W'||b[i]=='w')
{
sum+=23;
}
if(b[i]=='X'||b[i]=='x')
{
sum+=24;
}
if(b[i]=='Y'||b[i]=='y')
{
sum+=25;
}
if(b[i]=='Z'||b[i]=='z')
{
sum+=26;
}
}
System.out.println(sum);
if(sum%3==0 && sum%2==0)
{
System.out.println(a+" is a numerology name");
}
else
{
System.out.println(a+" is not a numerology name");
}
}
}

*******************************************************************************

34)OMR

import java.util.Scanner;
public class arraysquare{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int i;
System.out.println("Enter the No of questions");
int a=sc.nextInt();
if(a<0)
{
System.out.println("Invalid Number");
return;
}
int count=0;
int mark=0;
char b[]=new char[a];
System.out.println("Enter the answer key");
for (i=0;i<a;i++) {
b[i] = sc.next().charAt(0);

if ((b[i] >= 'a' && b[i] <= 'e')||(b[i] > 'E')) {


System.out.println("Invalid Answers");
return;
}
}
char c[]=new char[a];
System.out.println("Enter the student answers");
for (i=0;i<a;i++)
{
c[i]=sc.next().charAt(0);
if ((c[i] >= 'a' && c[i] <= 'e')||(b[i]>'E')) {
System.out.println("Invalid Answers");
return;
}
}

for(i=0;i<a;i++)
{
if(b[i]==c[i])
{
count++;
}
}
if(count>0)
System.out.println("Correct answers are "+count);
mark=(count*100)/a;
if(count<1)
System.out.println("All answers are wrong");
System.out.println("Mark is "+mark);

}
}

****ALTERNATE METHOD****

import java.util.*;
public class OMREvaluation {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the No of questions");
int no = sc.nextInt();
if (no <= 0) {
System.out.println("Invalid Number");
return;
} else {
char anskey[] = new char[no];
System.out.println("Enter the answer key");
for (int i = 0; i < no; i++) {
char x = sc.next().charAt(0);
if (x >= 'A' && x <= 'E')
anskey[i] = x;
else {
System.out.println("Invalid Answers");
return;
}
}
char studanskey[] = new char[no];
System.out.println("Enter the student answers");
for (int i = 0; i < no; i++) {
char y = sc.next().charAt(0);
if (y >= 'A' && y <= 'E')
studanskey[i] = y;
else {
System.out.println("Invalid Answers");
return;
}
}
int count = 0;
for (int i = 0; i < no; i++) {
if (anskey[i] == studanskey[i])
count++;
}
if (count == 0)
System.out.println("All answers are wrong \nMark is 0");
else {
System.out.println("Correct answers are " + count);
System.out.println("Mark is " + ((count * 100) / no));
}
}
}
}

**********************************************************************************************
***************************************************

35)MULTIPLY WITH POSITION

INPUT:
Enter the array size
5

Enter the elements


12
3
7
9
4

Sample Output:
12
6
21
36
20

Logic:
12*1=12
3*2=6
7*3=21
9*4=36
4*5=20

import java.util.*;
public class Main
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the array size:");
int n=sc.nextInt();
int res=0;
if(n<1 || n>10)
{
System.out.println("Invalid Array Size");
return;
}
int a[]=new int[n];
for(int i=0;i<n;i++)
{
a[i]=sc.nextInt();
}

for(int i=0;i<n;i++)
{
res=a[i]*(i+1);
System.out.println(res);
}

}
}

**********************************************************************************************
******************************************************************
36) CAR PARKING

Sample Input:
Enter the car number
ap 37 1498

Sample Output
Park the car in 3rd floor

import java.util.*;

public class CarPrking {


public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the car number");
String num = sc.nextLine();
if (num.length() != 10) {
System.out.println("Invlid State Code");
return;
}
String floor;
String code = num.substring(0, 2);
if (code.equals("TN")) {
floor = "ground";
} else if (code.equals("KA")) {
floor = "1st";
} else if (code.equals("KL")) {
floor = "2st";
} else if (code.equals("AP")) {
floor = "3st";
} else {
System.out.println("Invlid State Code");
return;
}
System.out.println("Park the car in " + floor + " floor");
}
}

ALTERNATE METHOD:

37) DIGIT COUNT

Sample Input:

Enter the number


56164

Enter the digit


6

Sample output
6 appears in 56164 is 2

Explanation:
Digit 6 appears 2 times in the number 56164

package accenture;
import java.util.*;

public class digitcount {

public static void main(String[] args) {


Scanner sc=new Scanner(System.in);
int count=0;
System.out.println("Enter the number:");
int n=sc.nextInt();
String str=String.valueOf(n);
if(n>0)
{
System.out.println("Enter the digit:");
char d=sc.next().charAt(0);
char ch[]=str.toCharArray();
for(int i=0;i<ch.length;i++)
{

if(ch[i]==d)
{
count++;
}
}
if(count>1)
{
System.out.println(d+" appears "+n+" is "+count);
}
}

38) WORD FINDING (repeated words)

Sample input:
Enter the number of words
5
Enter the words in set1:
good
bad
hello
Nothing
North

Enter the words in set2:


Bad
world
word
north
hello

package practice;
import java.util.*;
public class RepeatedWords {

public static void main(String[] args) {


// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
System.out.println("Enter the number of words");
int n = sc.nextInt();
if(n<=0){
System.out.println(n+" is less than the desired limit");
return;
}

String set1[] = new String[n];


String set2[] = new String[n];
System.out.println("Enter the words in set1:");
for(int i = 0;i<n;i++){
set1[i] = sc.next().toLowerCase();
}
System.out.println("Enter the words in set2:");
for(int i = 0;i<n;i++){
set2[i] = sc.next().toLowerCase();
}
String res[] = new String[n];
int k = 0;
for(int i = 0;i<n;i++){
int flag = 0;
for(int j = 0;j<n;j++){
if(set1[i].equals(set2[j])){
flag = 1;
break;
}
}
if(flag != 1){
res[k++] = set1[i];
}
}
/*for(int i = 0;i<n;i++){
if(set1[i] == set2[i]){
continue;
}
else{
res[k++] = set1[i];
}
}*/
System.out.println("The uncommon words are:");
for(int i = 0;i<k;i++){
System.out.println(res[i]);
}

}
**********************************************************************************************
******************************************************
39) SUM OF INTEGERS AT EVEN OR ODD PLACES

Enter size: 5
Enter numbers:
123(1+3=4)
2536(5+6=11)
2(2)
57(7)
76542(7+5+2=14)

Output:
38(4+11+2+7+14)

import java.util.*;
public class oddevenindex {
public static void main(String[] args)
{
Scanner sc = new Scanner (System.in);
System.out.println("Enter the size of the array: ");
int n = Integer.parseInt(sc.nextLine());
String[] arr = new String[n];
int[] fin = new int[n];
System.out.println("Enter the elements of the array: ");
for(int i=0;i<n;i++)
{
arr[i] = sc.nextLine();
}
int sum = 0;
int total =0;
if(n%2!=0)
{
for(int i=0;i<arr.length;i++) {
String num = arr[i];
char[] digi = num.toCharArray();
sum = 0;
if (digi.length % 2 == 0) {
for (int j = 1; j < digi.length; j += 2) {
char x = digi[j];
sum = sum + Integer.parseInt(String.valueOf(x));
}
fin[i] = sum;
}
else
{
for (int j = 0; j < digi.length; j += 2) {
char x = digi[j];
sum = sum + Integer.parseInt(String.valueOf(x));
}
fin[i] = sum;

}
}
for(int x: fin)
total +=x;
}
else{
for(int i=0;i<arr.length;i++) {
String num = arr[i];
char[] digi = num.toCharArray();
sum = 0;
if (digi.length % 2 == 0) {
for (int j = 1; j < digi.length; j += 2) {
char x = digi[j];
sum = sum + Integer.parseInt(String.valueOf(x));
}
fin[i] = sum;
}
else
{
for (int j = 0; j < digi.length; j += 2) {
char x = digi[j];
sum = sum + Integer.parseInt(String.valueOf(x));
}
fin[i] = sum;

}
}
for(int x: fin)
total +=x;
}

System.out.println("Output: "+total);

}
}

*****ALTERNATE METHOD*****

package practice;
import java.util.*;
public class SumOfEvenOrOdd {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
System.out.println("Enter the size");
int n = sc.nextInt();
if(n<=0){
System.out.println("Invalid size");
return;
}
System.out.println("Enter the elements:");
int sum = 0;
String str[] = new String[n];
for(int i=0;i<n;i++){
str[i] = sc.next();
}
for(int i = 0;i<n;i++){
String s = str[i];
if(s.length()%2 == 0){
for(int j = 1;j<s.length();j+=2){
sum+=Integer.parseInt(s.substring(j,j+1));
}
}else{
for(int j = 0;j<s.length();j+=2){
sum+=Integer.parseInt(s.substring(j,j+1));
}
}
}
System.out.println(sum);
}

}
**********************************************************************************************
**********************************************************************
40) SUM OF EVEN ELEMENTS

Here, size of the array should be taken as input, and it should be between 1 and 10 (inclusive)
If it is not in 1 and 10, print it as "invalid"
Now, by the comparing the values at the same indices of both the arrays, if both values are even, then print the sum
of the two values, otherwise print "0".
Before performing operation, make sure if no even element is present in both the arrays, then print it as "There are no
even elements in both the arrays", otherwise perform the above operation.

For example, see the following inputs and outputs:

1. Sample input:
Enter the size of array: 3
Enter the elements in first array:
2
3
4
Enter the elements in second array:
1
5
8
Sample output:
0
0
12

2. Enter the size of array: 3


Enter the elements in first array:
5
3
1
Enter the elements in second array:
1
5
9
Sample output:
There are no even elements in both the arrays

3.Sample input:
Enter the size of array: 1
Enter the elements in first array:
5
Enter the elements in second array:
1
Sample output:
There are no even elements in both the arrays

package practice;
import java.util.*;
public class SumOfEvenElements {

public static void main(String[] args) {


// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
System.out.println("Enter the size of the array:");
int n = sc.nextInt();
if(n<=0 || n>10){
System.out.println("Invalid");
return;
}
System.out.println("Enter the elements in the first array:");
int arr1[] = new int[n];
for(int i = 0;i<n;i++)
arr1[i] = sc.nextInt();
System.out.println("Enter the elements in the second array:");
int arr2[] = new int[n];
for(int i = 0;i<n;i++)
arr2[i] = sc.nextInt();
int count = 0;
for(int i = 0;i<n;i++){
if(arr1[i]%2 !=0 && arr2[i]%2 != 0){
count++;
}
}
if(count == n){
System.out.println("There are no even elements in both arrays:");
return;
}else{
for(int i = 0;i<n;i++){
if(arr1[i]%2 == 0 && arr2[i]%2 == 0){
System.out.println(arr1[i]+arr2[i]);
}else{
System.out.println("0");
}
}
}
}
}
**********************************************************************************************
*********************************************************************
41) COUNT OF OCCURRENCES OF SUBSTRING IN A STRING

Sample input:
Enter the string
Entertainment

Enter substring
en

Sample output: 2

package accenture;
import java.util.*;
import java.util.regex.*;
public class countofoccurencesofsubstringinastring {

public static void main(String[] args) {


Scanner sc=new Scanner(System.in);
int count=0;
System.out.println("Enter the string:");
String str=sc.next();
if(Pattern.matches("[a-z]+", str))
{
System.out.println("Enter pattern:");
String pat=sc.next();
if(Pattern.matches("[a-z]+", pat))
{
Pattern p=Pattern.compile(pat);
Matcher m=p.matcher(str);
while(m.find())
{
count++;
}
System.out.println("Count is: "+count);
}
else
{
System.out.println("Invalid Pattern");
}
}
else
{
System.out.println("Invalid String");
}

}
**********************************************************************************************
******************************************************************
42) LARGEST SORTED SUBSTRING FROM INPUT STRING

Find longest sorted substring from input string..


Input : abczgdpqrstubg
Output: pqrstu
*/
import java.util.*;
public class Main
{
public static void main (String[] args)
{
Scanner sc=new Scanner(System.in);
String s=sc.next();
int firstindex=0,lastindex=0,length=0;
for(int i=0;i<s.length();i++)
{
int asci=s.charAt(i);
int count=1;
for(int j=i+1;j<s.length();j++)
{
if(s.charAt(j)==++asci)
{
count++;
continue;
}
else
{
if(count>length)
{
firstindex=i;
lastindex=j;
length=count;
break;
}
}
}
}
System.out.println(s.substring(firstindex,lastindex));
}
}
**********************************************************************************************
********************************************************************
43) NON-UNIQUE ELIMINATION

package com.company;
import java.util.Scanner;

public class NonUniqueElimination {


public static void main(String[] args){
Scanner sc=new Scanner(System.in);
String name=sc.nextLine(),abc="";
int count=0;
for(int i=0;i<name.length();i++)
{
for(int j=1;j<name.length()-1;j++)
{
if(name.charAt(i)==name.charAt(j))
{
name=name.replace(String.valueOf(name.charAt(j)),"");
count+=1;
}
}
}
if(count==0) {
System.out.println("All are unique character");
return;
}
else {
System.out.println(name);
}
}
**********************************************************************************************
**********************************************************************************************
**

44) THEATER SEAT DETAILS

Sample input 1:
A2S3D06D13

Sample output 2:
Seat Number
D13
D14
D15
D16
D17

Sample input 2:
A2S3D02C01

Sample Output2:
Seat Number
C1
C2

import java.util.*;
import java.util.regex.Pattern;
public class Main{
public static void main(String args[]){
Scanner sc = new Scanner(System.in);

String str = sc.next();


if(str.length()!=10){
System.out.println("Invalid Input");
return;
}

if(Pattern.matches("[0-9]+",str.substring(5,7)) && Integer.parseInt(str.substring(5,7))>=1


&& Integer.parseInt(str.substring(5,7))<=10){
int seatnumber = Integer.parseInt(str.substring(5,7));
String eightletter = str.substring(7,8);
if(Pattern.matches("[A-Za-z]",eightletter) && Pattern.matches("[0-9]+",str.substring(8,10))){
int n = Integer.parseInt(str.substring(8,10));
for(int i=0;i<seatnumber;i++){
System.out.println(eightletter + (n++));
}
}
else{
System.out.println("Invalid Seat Number");
return;
}
}
else{
System.out.println("Invalid Count");
return;
}
}
}
**********************************************************************************************
***************************************************************************

45) CALCULATE OFFER PRICE (DISCOUNT PRICE)

import java.util.Scanner;

public class DiscountPrice {


public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
String code=sc.nextLine();
int len=code.length();
if(len<6 || len>8)
{
System.out.println("Invalid Input");
return;
}
String mrps=code.substring(4);
int mrp=Integer.parseInt(mrps);
System.out.println("MRP Price :"+mrp);
if(mrp>=1 && mrp<=10)
{
System.out.println("Offer Price: Rs"+mrp);
}
else if(mrp>=11 && mrp<=50)
{
System.out.println("Offer Price: Rs"+(mrp-5));
}
else if(mrp>=51 && mrp<=500)
{
System.out.println("Offer Price: Rs"+(mrp-15));
}
else if(mrp>= 501 && mrp<=5000)
{
System.out.println("Offer Price: Rs"+(mrp-105));
}
else if(mrp>=5001 && mrp<=9999)
{
System.out.println("Offer Price: Rs"+(mrp-1005));
}
}
}
**********************************************************************************************
*******************************************************************************

46) THREE’S

Sample input:
Enter the string
Long live

import java.util.*;
import java.lang.*;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("Enter the String");
String str =in.nextLine();
for(int i=0;i<str.length();i++)
{
if((Character.isLetter(str.charAt(i)) || Character.isWhitespace(str.charAt(i))))
continue;
else{
System.out.println(str+" is not a valid string");
return;
}
}
int sum=0;
for(int i=0;i<str.length();i++){
if((i+1)%3==0){
sum+=(int)str.charAt(i);
}
}
System.out.println("Sum is "+sum);
}
}
**********************************************************************************************
**********************************************************************************
47) EVEN POSITION CAPS (CAPITAL LETTERS)

import java.util.Scanner;
import java.util.regex.Pattern;

public class EvenPositionCaps {


public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Input string");
String s = sc.nextLine();
if (!Pattern.matches("[A-Za-z]+", s)) {
System.out.println(s + " is an invalid input");
return;
} else {
if (s.length() < 5 || s.length() > 20) {
System.out.println(s + " is an invalid length");
return;
}
String output = s.charAt(0) + "";
for (int i = 0; i < s.length() - 1; i++) {
if ((i) % 2 == 0)
output += Character.toString(s.charAt(i + 1)).toUpperCase();
else
output += s.charAt(i + 1);
}
System.out.println(output);
}
}
}

***ALTERNATE METHOD***

import java.util.*;
import java.util.regex.Pattern;
public class Main{
public static void main(String args[]){
Scanner sc = new Scanner(System.in);

System.out.println("Input string");
String str = sc.next();
if(Pattern.matches("[A-Za-z]+",str)){

if(str.length()<5 || str.length()>20){
System.out.println(str+" is an invalid length");
return;
}
String output = str.charAt(0)+"";
for(int i=0;i<str.length()-1;i++){
if(i%2==0){
output = output+ Character.toString(str.charAt(i+1)).toUpperCase();
}
else
output = output + str.charAt(i+1);
}
System.out.println(output);
}
else{
System.out.println(str+" is an invalid input");
return;
}
}
}
**********************************************************************************************
****************************************************************************************

48) FUN COUNT

public class FunCount {


public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number of toys:");
int n=sc.nextInt();
if(n<=0)
{
System.out.println("Invalid Input");
}
else if(n>15)
{
System.out.println("Number exceeds the limit");
}
else{
String[] a=new String[n];
System.out.println("Enter the toy list");
for(int i=0;i<n;i++)
{
a[i]=sc.next().toLowerCase();
}
Arrays.sort(a);
int count=0;
for(int i=0;i<n;i++)
{
count=1;
for(int j=i+1;j<n;j++)
{
if(a[i].equalsIgnoreCase(a[j]))
{
count++;
a[j]="0";
}
}
if((a[i])!="0")
{
System.out.println(a[i]+"="+count);
}

}
}
}
}
**********************************************************************************************
*******************************************************************************

49) SPEED ESTIMATION

import java.util.*;
public class Main{
public static void main(String args[]){
Scanner sc = new Scanner(System.in);

System.out.println("Enter the distance in kilometre");


int km = sc.nextInt();

if(km<=0){
System.out.println("Invalid Input");
return;
}

System.out.println("Enter the time to reach in hours");


int time = sc.nextInt();
if(time<=0){
System.out.println("Invalid Input");
return;
}

int sp = km/time;
if(sp>30){
int in_sp = sp-30;
System.out.println("You want to increase a speed "+in_sp+" km/hr from a normal speed");
}
else{
System.out.println("You drive a car at a normal speed");
}
}
}
***********************************************************************************************
*********************************************************************************
50) SUM OF SQUARES (RE-TEST)

Sample input
Enter the number of values
4
Enter the values
2
7
9
8

Sample output
130

Explanation
Odd numbers are 7,9 = 7*7 +9*9 = 49+81=130
import java.util.*;
public class Main
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number of values");
int n=sc.nextInt();
if(n<=0)
{
System.out.println(n+" is an invalid size");
return;
}
int a[]=new int[n];
int count=0;
int sum=0;
System.out.println("Enter the values");
for(int i=0;i<n;i++)
{
a[i]=sc.nextInt();
if(a[i]%2!=0)
count=count+1;
}
if(count<=0)
{
System.out.println("These "+n+" values are not a odd digit");
return;
}
else
{
for(int i=0;i<n;i++)
{
if(a[i]%2!=0)
{
sum=sum+a[i]*a[i];
}
}
System.out.println(sum);
}

}
}

JAVA END
*********************************************************************************************
*********************************************************************************************
********

RDBMS IMPORTANT CODES(NOT TESTED)


1.)Select concat(concat(customer_name,'has taken a
policy on'),date_of_policy) as Enrollment_details
from customer JOIN Policy using (customer_id)
order by customer_name,date_of_policy;

2.)select plolicy_id,policy_name,rate_of_interest, bonus_percentage


from policy
where minimum_primeium_amount = 1200
order by policy_d;

3.)select fine_range,fine_amount
CASE
When fine_range=L1
then 5+fine_amount
when fine_range=L2
then 10+fine_amount
When fine_range=M1
then 15+fine_amount
when fine_range=M2
then 20+fine_amount
When fine_range=H1
then 25+fine_amount
when fine_range=H2
then 30+fine_amount
END as NEW_FINE_AMOUNT

4.)select leave_type,allocated_days
CASE
when leave_type='CASUAL'
then allocated_days+2
when leave_type='SICK'
then allocated_days+5
when leave_type='MATERNITY'
then allocated_days+90
when leave_type='MARRIAGE'
then allocated_days+3
when leave_type='STUDY'
then allocated_days-2
END as NEW_ALLOCATED_TYPES
from table_name
order by leave_type;

5.) select emp_id,emp_name,department_id,department_name


from Department JOIN Employee using (department_id)
JOIN Leave+Avail_details using (Emp_id)
JOIN Leave using (Leave_type)
where Allocated_days = 0
order by emp_id;
*********************************************************************************************
**

1.) Account Info - "HDVL002"


select account_type, count(account_id) as TOTAL_ACCOUNTS
from Acount_Info where IFC_Code = 'HDVL002'
group by account_type order by account_type;

2.)select customer_id,customer_name,phone_no,order_date
from Customer_info JOIN Orders using (customer_id)
where order_amount > 500
order by customer_id,order_date;

3.) select distinct customer_id,customer_name,phone_no,loan_amount as


total_loan_amount from customers JOIN loans_taken using
(customer_id)
order by customer_id;

4.) select distinct boat_id,seat_capacity,count(ride_id) as ride_count


From Boat_details JOIN Ride_details using (boat_id)
order by boat_id;

5.) select customer_id,customer_name,contact_no,mail_id


from Coustomer_details where Gender = 'M'
order by customer_id;
6.) select customer_name,total_amount_paid
from Customer_master JOIN Booking_details using (customer_id)
where total_amount_paid < (select max(total_amount_paid) from booking_details
where total_amount_paid < (select max(total_amount_paid) from booking_details))
order by customer_name;

7.) select book_code,book_title, author,rack_num


from book_details where category = 'JAVA'
order by book_code;

8.) select customer_name,policy_enrollment as Enrollment_details


from customer JOIN policy_enrolmment using (customer_id)
order by customer_name,date_of_enrollment;

9.)DECODE QUESTION
select fine_range, fine_amount,
decode(fine_range, 'L1',fine_amount+5,
'L2',fine_amount+10,
'M1',fine_amount+10,
'M2',fine_amount+10,
'H1',fine_amount+10,
'H2',fine_amount+10)new_fine_amount
from fine_details;

10.)select customer_name||" has taken policy on"|| date_of_enrollment as


enrollment_details form customer
join policyenrollent using (customer_id)
order by customr_name,date_of_enrollment;

11.)select policy_id,policy_name,rate_of_interest,bonus_percentage
from policy where mimum_premium_amount = 1200
order by policy_id;

12.) select customer_id,customer_name, street,phone_no,email


from Customers JOIN loan_taken using (customer_id)
where loan_amount > = 500000 and loan_amonunt <1500000
order by customer_id;

13.)select distinct boat_id, boat_name,boat_type


from boat_details JOIN ride_details using (boat_id)
where DOT LIKE '%-AUG-%' and Shift = 'evening'
order by boat_id;

14.) select policy_id,policy_name,rate_of_interest


from policy where miniimum_ppremium_amount < 3000 AND bonus_percent > 85
order by policy_id;

RDBMS ANSWERS

1.1) Write a query to display boat_type and number of boats running under each type. Give an alias name as 'NO_OF
_BOATS'.
Note: Boat_type can be 'DELUXE' or 'SUPER DELUXE'.

select boat_type,count(Boat_id) as NO_OF_BOATS


from boat_details
group by Boat_type;

1.2) select boat_name,boat_type from boat_details


where seat_capacity between 100 and 200
order by boat_name desc;

2.1) select vehicle_type,count(vehicle_id)


from vehicle_details
group by vehicle_type
order by vehicle_type;

2.2) select driver_id,driver_name,phone_no,Driver_rating


from driver_details where driver_rating between 3 and 5
order by driver_rating desc;

3.1) select coursename from course


c join registration r on
c.courseid=r.courseid
having count(studid)>=2
group by coursename
order by coursename;

3.2) select s.studid,sum(fees) as TOTALFEES


from student s join registration r
on s.studid=r.studid join course c
on r.courseid=c.courseid
group by s.studid
order by s.studid;

3.3) select studid,count(CourseID) as NOOFCOURSES


from registration
group by Studid
order by NOOFCOURSES desc,Studid;

3.4) select student.stuid,firstname from student


join registration on registration.stuid=student.stuid
where lower(to_char(doj,'MON'))='jan';

3.5) select courseid,coursename from


course where duration between 10 and 15;

3.6) select courseid,registration.stuid from registration


join student on registration.stuid=student.stuid
where lower(to_char(doj,'MON'))=lower(to_char(dob,'MON'));
JAVA

1. LCM OF DAY INTERVAL/LUNCH TOGETHER/DINNER TOGETHER

INPUT: Enter the day interval of Tony : 4


Enter the day interval of Potts: 6

OUTPUT: Tony and Potts will have dinner together on 12th day.

import java.util.Scanner;
public class lcm {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the day interval of Sam:");
int n1 = sc.nextInt();
System.out.println("Enter the day interval of Riya:");
int n2 = sc.nextInt();
if(n1<=0 || n2<=0)
{
System.out.println("Given interval is not valid");
return;
}
int lcm;
lcm = (n1 > n2) ? n1 : n2;
while(true) {
if( lcm % n1 == 0 && lcm % n2 == 0 ) {
System.out.printf("Sam and Riya will have their dinner on day "+lcm);
break;
}
++lcm;
}
}
}

ALTERNATE METHOD

import java.util.Scanner;
public class Lunchlcm {
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the day interval of Tony");
int n1=sc.nextInt();
System.out.println("Enter the day interval of Potts");
int n2=sc.nextInt();
if(n1<=0 && n2<=0)
{
System.out.println("Given interval is not valid");
return;
}
int a=n1;
int b=n2;
while(n2>0)
{
if (n1 > n2)
{
n1 = n1 - n2;
} else
{
n2 = n2 - n1;
}
}
int gcd = n1;
int lcm = (a * b) / gcd;

System.out.println("Tony and Potts will have lunch together on " + lcm + " day");
}
}

*********************************************************************************************
*********************************************************************************************
**
2.SCORE OF REPEATING WORDS/ WORD REPETITION

INPUT: Enter the String: GOOD


Enter the sentence: GOOD FOOD GOOD LIFE

OUTPUT: Score is 2

import java.util.*;
class PrintMessage
{
public static void main (String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the string");
String s=sc.next();
int count=0;
int sum=2;
for(int i=0;i<s.length();i++)
{
if(Character.isDigit(s.charAt(i)) || Character.isLetter(s.charAt(i)) || s.charAt(i)==' ')
{
continue;
}
else
{
System.out.println(s+" is not valid String");
return;
}
}
System.out.println("Enter the sentence");
sc.nextLine();
String sentence=sc.nextLine();
String[] w=sentence.split(" ");
for(int i=0;i<w.length;i++)
{
if(w[i].equalsIgnoreCase(s))
{
count++;
if(count>2)
{
sum=sum*2;
}
}
}
if(count>2)
{
System.out.println("Score is "+sum);
}
else
{
System.out.println("Score is"+count);
}
}
}

*ALTERNATE METHOD

import java.util.Scanner;
public class CountWords {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String word, sentence;ed
int count = 0;
System.out.println("Enter a word:");
word = in.nextLine();
System.out.println("Enter a sentence");
sentence = in.nextLine();

if (!(word.matches("[a-z]+"))) {
System.out.println("Invalid Input");
return;
}
String words[] = sentence.toLowerCase().split(" ");
for (int i = 0; i < words.length; i++) {
if (word.equals(words[i])) {
count++;
}
}
System.out.println("Score is:" + ((int) Math.pow(2, count - 1)));
}
}
*********************************************************************************************
*********************************************************************************************
***

3. BATTERY CAPACITY

INPUT: Enter battery capacity :1230


Enter charging current value: 400

OUTPUT: 3.69 Hours

import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter battery capacity:");
double capacity = sc.nextDouble();
if(!(capacity>=1000 && capacity<=10000)) {
System.out.println("Invalid battery capacity");
return;
}
System.out.println("Enter charging current value:");
double current = sc.nextDouble();
if(!(current>=300 && current<=2100)) {
System.out.println("Invalid output current");
return;
}
double time=0.0f;
time = (capacity/current)*1.2;
System.out.println(String.format("%.2f",time)+" Hours");
}

*********************************************************************************************
*********************************************************************************************
***
4.STUDENTS WHOSE ROLLNO ARE ODD

INPUT: Entr the set of students :5


Enter the roll number :1
3
4
5
6

OUTPUT: 135

import java.util.*;
public class Main
{
public static void main(String[] args) {
System.out.println("Enter the set of students");
Scanner s=new Scanner(System.in);
int setn=s.nextInt();
if(setn<=0)
{
System.out.println(setn+" is an invalid size");
return;
}
System.out.println("Enter the roll number");
int[] rolls=new int[setn];
int oddflag=0;
for(int i=0;i<setn;i++)
{
rolls[i]=s.nextInt();
if(rolls[i]<0)
{
System.out.println(rolls[i]+" is an invalid roll number");
return;
}
if(rolls[i]%2!=0)
{
oddflag=1;
}
}
if(oddflag==0)
{
System.out.println("The "+setn+" numbers are not odd");
return;
}
String str="";
for(int i=0;i<setn;i++)
{
if(rolls[i]%2!=0)
{
str=str+rolls[i];
}
}
for(int n=0;n<str.length();n++)
{
System.out.println(str.charAt(n)+" ");
}
}
}
*********************************************************************************************
*********************************************************************************************
**

5.CALCULATING BILL AMOUNT

INPUT : Enter your name : Sam


Enter the time duration: 13
List of payment options
1)Visa card
2)Rupay card
3)Master card
Choose an option : 2

OUTPUT: Dear Sam your bill amount is 1294.80

import java.util.*;
public class Main
{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter your name");
String s=sc.nextLine();double sal=0;double disc=0;
for(int i=0;i<s.length();++i)
{
if(!Character.isLetter(s.charAt(i)))
{
System.out.println("Invalid Name");
return;
}
}
System.out.println("Enter the time duration");
int n=sc.nextInt();int n1;
if(n<=0 || n>24)
{
System.out.println("Invalid duration");
return;
}
System.out.println("List of payment options");
System.out.println("1)Visa card");
System.out.println("2)Rupay card");
System.out.println("3)Master card");
System.out.println("Chosse an option");
while(true)
{
n1=sc.nextInt();
if(n1<0||n1>3)
{
System.out.println("Try again");
}
else
{
break;
}
}
if( n1==1)
{
if(n>=5)
{
sal=120*n;
disc=(sal*0.25);
sal=sal-disc;
}
else
{
sal=n*120;
}
}
if(n1==2)
{
if(n>=5)
{
sal=120*n;
disc=(sal*0.17);
sal=(120*n)-disc;
}
else
{
sal=n*120;
}
}
if(n1==3)
{
sal=n*120;
}
System.out.print("Dear "+s+" your bill amount is ");
System.out.printf("%.2f", sal);
}
}

*********************************************************************************************
*********************************************************************************************
***
6.ODD POSITION CHAR WILL BE IN UPPERCASE & EVEN WILL BE LOWERCASE-

INPUT : school

OUTPUT : sChOol

import java.util.Scanner;
public class UPLC{
public static void main(String []args){
Scanner sc = new Scanner(System.in);
String str = sc.next();
int strlen = str.length();
for(int i = 0 ; i < str.length(); i++){
char ch = str.charAt(i);
if(!(ch >= 'a' && ch <='z' || ch >= 'A' && ch <='Z' )){
System.out.println(str+ " is an invalid input");
return;
}
}

if(strlen >= 5 && strlen <= 20){


StringBuffer updateString = new StringBuffer();
char[] charArr = str.toCharArray();
for(int i = 0 ; i < charArr.length; i++){
char ch = charArr[i];
if(i % 2 != 0){
ch = Character.toUpperCase(ch);
}
updateString.append(ch);
}
System.out.println(updateString.toString());
}
else {
System.out.println(str+ " is an invalid Length");
}
}
}

*********************************************************************************************
*********************************************************************************************
****
7) RATING SCORE

INPUT: ENTER JESSON SCORE


1
2
3
4
8
ENTER JAMES SCORE
0
2
6
5
6

OUTPUT: JESSON SCORE : 2


JAMES SCORE : 2

import java.util.Scanner;
public class Ratingscore {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter Jesson Score");
int[] a1 = new int[5];
int[] a2 = new int[5];
int f = 0;
int t = 0;
int sum = 0;
int sum1 = 0;
for (int i = 0; i < 5; i++) {
a1[i] = sc.nextInt();
if (a1[i] < 0) {
f = 1;
t = a1[i];
break;
}
}
if (f == 1) {
System.out.println(t + " is invalid");
} else {
System.out.println("Enter James Score");
for (int j = 0; j < 5; j++) {
a2[j] = sc.nextInt();
if (a2[j] < 0) {
f = 1;
t = a2[j];
break;
}
}
if (f == 1) {
System.out.println(t + " is invalid");
} else {
for (int k = 0; k < 5; k++) {
if (a1[k] > a2[k]) {
sum++;
}
if (a1[k] < a2[k]) {
sum1++;
}
}
System.out.println("Jesson Score");
System.out.println(sum);
System.out.println("James Score");
System.out.println(sum1);
}
}
}
}

**ALTERNATE METHOD:

import java.util.Scanner;
public class minmax {
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
int jesson=0,james=0,c=0;
int a[]=new int[5];
int b[]=new int[5];
System.out.println("Enter Jesson Score");
for(int i=0;i<a.length;i++)
{
a[i]=sc.nextInt();
if(a[i]<0)
{
System.out.println("Invalid");
Runtime.getRuntime().halt(0);
}
}
System.out.println("Enter James Score");
for(int i=0;i<b.length;i++)
{
b[i]=sc.nextInt();
if(b[i]<0)
{
System.out.println("Invalid");
Runtime.getRuntime().halt(0);
}
}
if(a.length==b.length)
{
for(int i=0;i<a.length;i++)
{
if(a[i]>b[i])
{
jesson++;
}
else if(a[i]<b[i])
{
james++;
}
else if(a[i]==b[i])
{
c++;
}
}
System.out.println("Jesson Score: "+jesson);
System.out.println("James Score: "+james);
}
else{
System.out.println("Length not same");
}
}
}

*********************************************************************************************
*******************************************************************************

8.COUNT OF UPPERCASE AND COUNT OF LOWERCASE & OUTPUT WILL BE IN THE FORM OF (UP-LC
)

INPUT : HosTEL

OUTPUT: 4-2=2

import java.util.Scanner;

public class ContNext {


public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the string");
String str=sc.nextLine();
int uc=0,lc=0;
if(str.matches("[A-Za-z ]+")&&str.length()<10) {
for(int i=0;i<str.length();i++)
if(Character.isUpperCase(str.charAt(i))) {
uc++;
}
else if(Character.isLowerCase(str.charAt(i))){
lc++;
}
System.out.println(uc-lc);
}
}
}
*********************************************************************************************
*******************************************************************************
9) PRODUCT of COUNT of UPPERcase and LOWERcase letters

INPUT: ABsdEr

OUTPUT: 6 (3*3)

import java.util.Scanner;
public class minmax {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the String");
String s = sc.nextLine();
int upper = 0;
int lower = 0;
int i;
if (s.matches("[a-zA-Z]+")) {
for (i = 0; i < s.length(); i++) {
char c = s.charAt(i);
if (c >= 'A' && c <= 'Z') {
upper++;
}
if (c >= 'a' && c <= 'z') {
lower++;
}
}
System.out.println(upper * lower);
}
else
{
System.out.println("Invalid String");
}

}
}

*********************************************************************************************
******************************************************************************
10.Count of UPPERcase and LOWERcase and their difference

Enter the String: ColLEgE


Count of uppercase is : 4
Count of lowercase is : 3
Hence the ans is : 1

import java.util.Scanner;
public class MyClass {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the String ");
String str = sc.next();
int strlen = str.length();

for(int i =0; i < str.length() ; i++){ char


ch = str.charAt(i);
if(!(ch >='a' && ch <= 'z' || ch >= 'A' && ch <= 'Z')){
System.out.println(str + " is an invalid String");
return;
}
}

if(strlen > 0 && strlen <= 10){


int upper = 0, lower = 0, ans = 0;

for(int i = 0; i < str.length(); i++)


{
char ch = str.charAt(i);
if (ch >= 'A' && ch <= 'Z')
upper++;
else if(ch >= 'a' && ch <= 'z')
lower++;
}
ans = upper - lower;
System.out.println("count of uppercase is :"+ upper);
System.out.println("count of lowercase is :"+ lower);
System.out.println("Hence the ans is :"+ ans);
}
else {
System.out.println(str + " is an invalid String");
}
}
}
*********************************************************************************************
*******************************************************************************
11.PUBLIC DISTRIBUTION

INPUT : OKR

OUTPUT : 90

import java.util.*;
public class Main
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
String str = in.nextLine();
int l=str.length();
if(l>5 || l<2)
{
System.out.println("Invalid Input");
}
else
{
int sum=0,flag=0;
for(int i=0;i<l;i++)
{
char c=str.charAt(i);
if(c=='O')
{
sum=sum+24;
}
else if(c=='K')
{
sum=sum+36;
}
else if(c=='S')
{
sum=sum+42;
}
else if(c=='R')
{
sum=sum+30;
}
else if(c=='W')
{
sum=sum+44;
}
else
{
flag=1;
}
}
if(flag==1)
{
System.out.println("Invalid Input");
}
else
{
System.out.println(sum);
}
}
}
}
*********************************************************************************************
******************************************************************************

12.LOTTERY TICKETS

INPUT: Enter the Starting range


23467
Enter the Ending range
23477

OUTPUT: 23469
23472

import java.util.*;
public class Main {
public static void main(String args[])
{
int i,c,n,sum,count;
sum=0;count=0;n=0;c=0;i=0;
Scanner sc = new Scanner(System.in);
System.out.println("Enter the Starting range");
int a = sc.nextInt();
String str = Integer.toString(a);
if(str.length()!=5)
{
System.out.println(str + " is an invalid input");
System.exit(0);
}

System.out.println("Enter the Ending range");


int b = sc.nextInt();
String str1 = Integer.toString(b);
if(str1.length()!=5)
{
System.out.println(str1 + "is an invalid input");
System.exit(0);
}

if(a>b)
{
System.out.println(a+" and "+b+" are invalid serial numbers");
System.exit(0);

}
for(i=a;i<=b;i++)
{
n=i;
while(n!=0)
{
c=n%10;
sum=sum+c;
n=n/10;
}
if((sum%3==0)&&((sum/3)%2==0))
{
System.out.println(i + " ");
count++;
}
sum=0;
}
if(count==0)
{
System.out.println("Eligible tickets are not available from "+a+" to "+b);
System.exit(0);
}
}
}

*********************************************************************************************
******************************************************************************
13.COFFEE STALL NUMEROLOGY

INPUT : Enter the Staff Name


Coffee Bar

OUTPUT : Coffee Bar satisfies the numerology logic

import java.util.*;
public class Main{
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the Staff Name");
String name = sc.nextLine();
int count=0;
for(int i=0;i<name.length();i++){
if(Character.isAlphabetic(name.charAt(i)) || name.charAt(i)==' '){
count++;
}
}
if(count==name.length()){
String str = name.replace(" ","");
int sum=0;
for(int i=0;i<str.length();i++){
sum += i;
}
if(sum%2==0){
System.out.println(name+" satisfies the numerology logic");
}else{
System.out.println(name+" does not satisfy the numerology logic");
}
}else{
System.out.println("Invalid Input");
}
}
}

*ALTERNATE METHOD USING -matches for same question

import java.util.*;
public class Main{
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the Staff Name");
String name = sc.nextLine();
if(name.matches("[a-zA-Z ]+")){
String str = name.replace(" ","");
int sum=0;
for(int i=0;i<str.length();i++){
sum += i;
}
if(sum%2==0){
System.out.println(name+" satisfies the numerology logic");
}else{
System.out.println(name+" does not satisfy the numerology logic");
}
}else{
System.out.println("Invalid Input");
}
}
}

*ALTERNATE METHOD

import java.util.Scanner;
public class CoffeeHouse {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the Stall Name");
String name = sc.nextLine();
if (name.matches("^[A-Za-z ]*$")) {
int sum = 0;
String fName = name.replaceAll(" ", "");
for (int i = 0; i < fName.length(); i++)
sum = sum + i;
if (sum % 2 == 0) {
System.out.println(name + " satisfies the numerology logic");
} else {
System.out.println(name + " not satisfies the numerology logic");
}
} else
System.out.println("Invalid Input");
}
}

*********************************************************************************************
******************************************************************************

14.ANAGRAM OR TWO WORDS OF SAME LETTER

INPUT : cat
act

OUTPUT: Same

import java.util.Arrays;
import java.util.Scanner;
public class minmax {
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter sentence 1");
String s1=sc.next();
s1=s1.toLowerCase();
System.out.println("Enter sentence 2");
String s2=sc.next();
s2=s2.toLowerCase();
if(s1.length()!=s2.length())
{
System.out.println("Invalid");
}
if(s1.matches("^[a-zA-Z]*")){
char c1[] = s1.toLowerCase().toCharArray();
char c2[] = s2.toLowerCase().toCharArray();
Arrays.sort(c1);
Arrays.sort(c2);
if (Arrays.equals(c1, c2)) {
System.out.println(s1 + " and " + s2 + " contain the same characters");
} else {
System.out.println(s1 + " and " + s2 + " contain the different characters");
}
}
else
{
System.out.println("Invalid");
}
}
}

ALTERNATE METHOD:

import java.util.*;
public class Main{
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
String first=sc.next();
String secound=sc.next();
String word1=Main.checker(first);
String word2=Main.checker(secound);
if(word1.equals(word2)){
System.out.println("Same");
}else{
System.out.println("Different");
}
}
public static String checker(String word){
char arr[]=word.toCharArray();
Arrays.sort(arr);
int index=0;
for(int i=0;i<arr.length;i++){
int j;
for(j=0;j<i;j++){
if(arr[j]==arr[i]){
break;
}
}
if(i==j){
arr[index++]=arr[i];
}
}
char arr1[]=Arrays.copyOf(arr,index);
String newword= new String(arr1);
return newword;
}
}

ALTERNATE METHOD

import java.util.*;
public class arraysquare {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int f1=0,f2=0;
String s1=sc.nextLine();
char c1[]=s1.toCharArray();
String s2=sc.nextLine();
char c2[]=s2.toCharArray();
for(int i=0;i<c1.length;i++)
{
f1=0;
for(int j=0;j<c2.length;j++)
{
if(c1[i]==c2[j])
{
f1=1;
break;
}
}
if(f1==0)
{
break;
}
}
for(int i=0;i<c2.length;i++)
{
f2=0;
for(int j=0;j<c1.length;j++)
{
if(c2[i]==c1[j])
{
f2=1;
break;
}
}
if(f2==0)
{
break;
}
}
if(f1==1 && f2==1)
{
System.out.println("Same Char");
}
else{
System.out.println("Different char");
}
}
}

*********************************************************************************************
*****************************************************************************
15.SUMMATION OF EVEN NUMBERS IN THE ARRAY

INPUT : Enter array size


4
Enter array elements in 1st array
2
4
6
8
Enter array elements in 2nd array
1
2
5
2

OTPUT: 0
6
0
10

import java.util.*;
public class Main
{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter array size");
int n=sc.nextInt();
if(n>=10 || n<1)
{
System.out.println(n+" is an invalid input");
Runtime.getRuntime().halt(0);
}
int arr1[]=new int[n];
int arr2[]=new int[n];
int result[]=new int[n];
System.out.println("Enter array elements in 1st array");
for(int i=0;i<n;i++)
{
arr1[i]=sc.nextInt();
}
System.out.println("Enter array elements in 2nd array");
for(int i=0;i<n;i++)
{
arr2[i]=sc.nextInt();
}
//PROGRAM LOGIC
int count=0;
for(int i=0;i<n;i++)
{
if((arr1[i]%2==0 || arr1[i]==0) && (arr2[i]%2==0 || arr2[i]==0))
{
result[i]=arr1[i]+arr2[i];
count++;
}
else
{
result[i]=0;
}
}
if(count==0)
{
System.out.println("No even number is present in an Array");
}
for(int i=0;i<n;i++)
{
System.out.println(result[i]);
}
}
}

*********************************************************************************************
******************************************************************************
16.RUNNERS COMPETITION

INPUT :Enter the number of runners


5

Enter the runner details


Robert,9.38
Richard,9.35
Christiano,9.35
Williams,9.36
Vinix,9.35

OUTPUT: Richard
Christiano
Vinix

import java.util.*;
public class Main{
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
sc.useDelimiter("\n");
System.out.println("Enter the number of runners");
int n = sc.nextInt();
if(n<=0 || n>10){
System.out.println(n+" is an invalid number of runners");
Runtime.getRuntime().halt(0);
}
String temp = "";
String name[] = new String[n];
float time[] = new float[n];
System.out.println("Enter the runner details");
for(int i=0;i<n;i++){
temp = sc.next();
String temparr[] = temp.split(",");
name[i] = temparr[0];
time[i] = Float.parseFloat(temparr[1]);
if(time[i]>12 || time[i]<8){
System.out.println(time[i]+" is an invalid input");
Runtime.getRuntime().halt(0);
}
}
int maxcount = 0;
float maxrep = 0;
for(int i=0;i<n;i++){
int count = 0;
for(int j=i+1;j<n;j++){
if(time[i]==time[j]){
count++;
}
}
if(count>=maxcount){
maxcount = count;
maxrep = time[i];
}
}
if(maxcount==n){
System.out.println(n+" runners have same timing");
}
else if(maxcount==0){
System.out.println("No runners with same time.");
}
else{
for(int i=0;i<n;i++){
if(maxrep == time[i]){
System.out.println(name[i]);
}
}
}
}
}
*********************************************************************************************
******************************************************************************

17.REEDME

INPUT : Enter the customer name


Abi
Enter the category
History
Enter the quantity of books ordered
2900

OUTPUT : Total cost is 334080.0


import java.util.*;
public class Main{
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the customer name");
String name = sc.nextLine();
System.out.println("Enter the category");
String category = sc.nextLine();
category = category.toLowerCase();

if(!category.equals("adventure") && !category.equals("comics") && !category.equals("history") && !categ


ory.equals("thriller")){
System.out.println(category+" is invalid category");
Runtime.getRuntime().halt(0);
}
System.out.println("Enter the quantity of books ordered");
int quantity = sc.nextInt();
if(quantity <= 0){
System.out.println(quantity+" is an invalid quantity");
Runtime.getRuntime().halt(0);
}
int discount = 0;
int price = 0;
if(category.equals("adventure")){
price = 150;
if(quantity>=1700)
discount = 5;
}
else if(category.equals("comics")){
price = 230;
if(quantity>=1950)
discount = 5;
}
else if(category.equals("history")){
price = 120;
if(quantity>=2600)
discount = 4;
}
else if(category.equals("thriller") && quantity>=1700){
price = 190;
if(quantity>=6300)
discount = 3;
}
float totalcost = (price*quantity) - (price*quantity*discount/100);
System.out.println("Total cost is "+totalcost);
}
}

*********************************************************************************************
******************************************************************************
18. HARSHAD NUMBER (Sum of digit completely divide that number)

For example: 18= 1+8=9 and in 18/9 remainder is 0


INPUT: Enter array size: 5
Enter array elements : 18 14 12 24 13

OUTPUT: 18 12 24

import java.util.Scanner;
public class Harshad {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the number of values");
int n = sc.nextInt();
int i;
System.out.println("Enter the numbers");
int[] a = new int[n];
if (n > 0)
{
int flag = 0;
int k = 0;
for (i = 0; i < n; i++)
{
k = sc.nextInt();
if (k > 9)
a[i] = k;
else
{
flag = 1;
break;
}
}
if (flag != 1)
{
int c = 0;
for (i = 0; i < n; i++)
{
int x = a[i];
int sum = 0;
do {
int r = x % 10;
sum = sum + r;
x = x / 10;
}
while (x != 0);
if (a[i] % sum == 0)
{
c++;
System.out.println(a[i]);
}
}
if (c == 0)
System.out.println("The " + n + " values are not harshad number");
}
else
System.out.println("Provided " + k + " is not valid");
} else
System.out.println(n + " is an invalid input");
}
}

ALTERNATE METHOD:

import java.util.Scanner;
class Main
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number of values");
int n=sc.nextInt();
System.out.println("Enter the numbers");
int a[]=new int[n];
if(n>0)
{
int flag=0;
int k=0;
for(int i=0;i<n;i++)
{
k=sc.nextInt();
if(k>9) a[i]=k; else
{
flag=1;
break;
}
}
if(flag!=1)
{
int c=0;
for(int i=0;i<n;i++)
{
int x=a[i];
int sum=0;
do
{
int r=x%10; sum=sum+r; x=x/10;
}while(x!=0);
if(a[i]%sum==0)
{ c++;
System.out.println(a[i]);
}
}
if(c==0)
System.out.println("The "+n+" values are not harshad number");
}else
System.out.println("Provided "+k+" is not valid");
}else
System.out.println(n+" is an invalid input");
}
}
*********************************************************************************************
*********************************************************************************************
*******
19. IDEO GAME (PS1)

INPUT : Enter the amount


18000
Enter the Video Game Player Type
PS4

OUTPUT: You can buy PS4

public class PS {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the amount");
int amount = sc.nextInt();
if (amount >= 3000) {
System.out.println("Enter the Video Game Player Type");
String type = sc.next();
if (type.matches("[P][S][1-5]")) {
if (type.equals("PS1")) {
if (amount >= 5000) {
System.out.println("You can buy PS1");
} else {
System.out.println("You need more money to buy a PS1");
}
} else if (type.equals("PS2")) {
if (amount >= 7800) {
System.out.println("You can buy PS2");
} else {
System.out.println("You need more money to buy a PS2");
}
} else if (type.equals("PS3")) {
if (amount >= 9500) {
System.out.println("You can buy PS3");
} else {
System.out.println("You need more money to buy a PS3");
}
} else if (type.equals("PS4")) {
if (amount >= 12000) {
System.out.println("You can buy PS4");
} else {
System.out.println("You need more money to buy a PS4");
}
} else if (type.equals("PS5")) {
if (amount >= 15000) {
System.out.println("You can buy PS5");
} else {
System.out.println("You need more money to buy a PS5");
}
}
} else {
System.out.println(type + " is Invalid Type");
}
} else {
System.out.println(amount + " is too less");
}
}
}

*********************************************************************************************
*********************************************************************************************
****
20.ALTERNATE SUM DIFFERENCE

INPUT :Enter number


6
Enter values
12
13
6
8
9
7
(((( logic: (12-7=a
13-9=b
6-8=c
a+b+c=ans)))))

OUTPUT 2
3
4
5
5-2=3
4-3=1
So 3+1= 4
*/

import java.util.*;
public class AltDiff {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int sum=0;
int n=sc.nextInt();
int a[]=new int[n];
for(int i=0;i<n;i++)
{
a[i]=sc.nextInt();
}
for(int i=0;i<n/2;i++)
{
sum+=Math.abs(a[i]-a[n-i-1]);
}
System.out.println(sum);
}
}
*********************************************************************************************
*********************************************************************************************
*****
21.CHARACTER ADD

INPUT : Enter : 3
Enter the sentences:
ks436
Agh73
7222

OUTPUT: 222
240
0

import java.util.*;
public class arraysquare{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int sum=0;
System.out.println("Enter:");
int n=sc.nextInt();
if(n<=0)
{
System.out.println("The number of sentences "+n+" is invalid");
return;
}
System.out.println("Enter the sentences:");
String str[]=new String[n];
for(int i=0;i<n;i++)
{
str[i]=sc.next();
}
for(int i=0;i<str.length;i++)
{
String s=str[i].replaceAll("[0-9]","");
for(int j=0;j<s.length();j++)
{
char c=s.charAt(j);
int ascii=c;
sum+=ascii;
}
System.out.println(sum);
sum=0;
}

}
}

*********************************************************************************************
*********************************************************************************************
******
22.MIDDLE LETTER/Reverse first half of the string if string length is ODD

Input:
if length of string is even, the reverse the string:
Ex: Food
Output:
dooF

Input:
If length of the string is odd,then find the middle char and then ,reverse the string till mid char and print remain char
acters as it is.
Ex: Samsung
Output:
maSsung

package FinalAss;
import java.util.*;
public class MidLett {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
String str=sc.nextLine();//rahul
int len=str.length();
if(len%2==0)
{
StringBuilder sb=new StringBuilder(str);
sb.reverse();
System.out.println(sb.toString());
}
else if(len%2!=0)
{
System.out.println("Length of string is " +len);
int mid=len/2;
mid++;
System.out.println("Substring of string is "+mid);
String substr=str.substring(0,mid-1);
String remainSub=str.substring(mid-1,len);
StringBuilder sb=new StringBuilder(substr);
sb.reverse();
System.out.println(sb.toString()+remainSub);

}
}
}

ALTERNATE METHOD:::

import java.util.Scanner;
import java.util.regex.Pattern;
public class minmax {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
String str=sc.nextLine();//rahul
if(!Pattern.matches("[A-Za-z]+",str))
{
System.out.println(str+" is not a valid string");
return;
}
else if(str.length()<2)
{
System.out.println("Size of string "+str.length()+" is too small");
return;
}
int len=str.length();
if(len%2==0)
{
StringBuilder sb=new StringBuilder(str);
sb.reverse();
System.out.println(sb.toString());
}
else if(len%2!=0)
{
int mid=len/2;
String substr=str.substring(0,mid);
String remainSub=str.substring(mid,len);
StringBuilder sb=new StringBuilder(substr);
sb.reverse();
System.out.println(sb.toString()+remainSub);

}
}
}

*********************************************************************************************
*********************************************************************************************
*****

23 .ONLINE SHOPPING

input:
enter the product
laptop
Actual price
45000
exchange?
yes
bill amount:
27000.00

import java.util.*;
public class arraysquare {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the Product:");
String prod=sc.nextLine();
int ed=0,pd=0;
if(prod.equals("Mobile"))
{
ed=15;
pd=15;
}
else if(prod.equals("Laptop"))
{
ed=20;
pd=20;
}
else if(prod.equals("Headset"))
{
ed=0;
pd=10;
}
else if(prod.equals("Charger"))
{
ed=0;
pd=5;
}
else{
System.out.println("Not available");
return;
}
System.out.println("Enter the actual Price: ");
int price=sc.nextInt();
if(price<100)
{
System.out.println("Invalid Price");
return;
}
System.out.println("Do u want to Exchange?");
String exc=sc.next();
if(exc.equals("Yes") || exc.equals("yes"))
{
double ap=price-(price*pd)/100;
double ev=(price*ed)/100;
double total=ap-ev;
System.out.printf("Total=%.2f",total);
}
else if(exc.equals("No") || exc.equals("no"))
{
double total=price-(price*pd)/100;
System.out.printf("Total=%.2f",total);
}
else
{
System.out.println("Invalid Option");
}
}
}

*********************************************************************************************
*********************************************************************************************
*****
24 .OPERATOR FOUND

input:
45
23

22
output
45-23=22

import java.util.*;
public class arraysquare {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter n1 and n2:");
int n1=sc.nextInt();
if(n1>0)
{
int n2=sc.nextInt();
if(n2>0)
{
System.out.println("Enter n3:");
int n3=sc.nextInt();
if(n3>0)
{
if(n1+n2==n3)
{
System.out.println(n1+"+"+n2+"="+n3);
}
else if(n1-n2==n3)
{
System.out.println(n1+"-"+n2+"="+n3);
}
else if(n1*n2==n3)
{
System.out.println(n1+"*"+n2+"="+n3);
}
else if(n1/n2==n3)
{
System.out.println(n1+"/"+n2+"="+n3);
}
else
{
System.out.println(n3+" is an invalid answer");
}
}
else{
System.out.println("Invalid");
}
}
else{
System.out.println("Invalid");
}
}
else{
System.out.println("Invalid");
}

}
}

*********************************************************************************************
*********************************************************************************************
****

25 .PRODUCT EQUAL SUM

INPUT : Enter the array size


4
Enter the elements of the first array
12
35
56
34
Enter the elements of the second array
261
195
112
813
OUTPUT: 35,195
34,813

import java.util.*;
public class arraysquare
{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the array size");
int n=sc.nextInt();
if(n<=0)
{
System.out.println("Invalid array size");
return;
}
int a[]=new int[n];
System.out.println("Enter the elements of the first array");
for(int i=0;i<n;i++)
{
a[i]=sc.nextInt();
}
System.out.println("Enter the elements of the second array");
int b[]=new int[n];
for(int i=0;i<n;i++)
{
b[i]=sc.nextInt();
}
int x[]=new int[n];
int y[]=new int[n];
for(int i=0;i<n;i++)
{
int c=a[i];
int prod=1;
while(c!=0)
{
prod*=(c%10);
c/=10;
}
x[i]=prod;
prod=0;
}
for(int i=0;i<n;i++)
{
int s=b[i];
int sum=0;
while(s!=0)
{
sum+=(s%10);
s/=10;
}
y[i]=sum;
sum=0;
}
for(int i=0;i<n;i++)
{
if(x[i]==y[i])
{
System.out.println(a[i]+","+b[i]);
}
}
}
}

*********************************************************************************************
*********************************************************************************************
*

26. UNIQUE CHAR

input:
LIfe is inherently risky

output:
life is ihrtly risky

package FinalAss;
import java.util.*;
public class nonuniquetwo {
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
String sentence = sc.nextLine();
String[] words = sentence.split(" ");
for(String word : words)
{
System.out.print(getUnique(word) + " ");
}
sc.close();
}
public static String getUnique(String str)
{
StringBuffer sb = new StringBuffer();
for(int i = 0; i<str.length(); i++)
{
if(countFrequency(str.charAt(i), str) == 1)
{
sb.append(str.charAt(i));
}
}
String result = sb.toString();
return result;
}
public static int countFrequency(char c, String str)
{
int count = 0 ;
for(int i = 0; i<str.length(); i++)
{
if(str.charAt(i) == c)
{
count++;
}
}
return count;
}
}

*********************************************************************************************
*********************************************************************************************
*
27. BOX SIZE

INPUT : Enter the box size


6
Enter the numbers
5
55
3
59
42
8
OUTPUT: 32 is even its a valid box

import java.util.Scanner;
public class minmax {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the box size");
int a=sc.nextInt();
if(a<=0)
{
System.out.println(a+" is an invalid box size");
return;
}
int b[]=new int[a];
int c=0,sum=0,temp=0;
System.out.println("Enter the numbers");
for(int i=0;i<a;i++)
{
b[i]=sc.nextInt();
if(b[i]<=0)
{
System.out.println(b[i]+" is an invalid input");
return;
}
}
for(int i=0;i<a;i++)
{
c=b[i]%10;
sum+=c;
c=0;
}
if(sum%2==0)
{
System.out.println(sum+" is even its a valid box");
return;
}
else
{
System.out.println(sum+" is odd its an invalid box");
return;
}

}
}
*********************************************************************************************
*********************************************************************************************
***

28. ORDER IDENTIFICATION:(check where elements are in ascending order)

INPUT : Enter the array size : 5


Enter the elements: 32
44
55
66
77

OUTPUT : 32 44 55 66 77 are in ascending order

import java.util.Arrays;
import java.util.Scanner;

public class orderidentification {


public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the array size");
int a=sc.nextInt();
if(a<2 || a>10)
{
System.out.println(a+" is not a valid array size");
return;
}
int b[]=new int[a];
int count=0;
System.out.println("Enter the elements");
for(int i=0;i<a;i++)
{
b[i]=sc.nextInt();
}
int d[]= Arrays.copyOf(b,b.length);
Arrays.sort(d);

if(Arrays.equals(b,d))
{
count++;
}
if(count>0)
{
for(int i=0;i<b.length;i++)
{
System.out.print(b[i]+" ");

}
System.out.print("are in ascending order");
return;
}
else
{
for(int i=0;i<a;i++)
{
System.out.print(b[i]+" ");
}
System.out.print("are not in ascending order");
return;
}
}
}
*********************************************************************************************
**************************************************************
29) DATE ,MONTH AND YEAR

INPUT:13081995

OUTPUT: date: 13
month: 08
year: 1998

import java.util.Scanner;
public class minmax {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
String str=sc.nextLine();
int n=str.length();
for(int i=0;i<str.length() ;i++)
{
if(!(str.charAt(i)>='0' && str.charAt(i)<='9'))
{
System.out.println("Invalid input");
return;
}
if(n!=8)
{
System.out.println("Enter valid date");
return;
}
}
String date=str.substring(0,2);
String mon=str.substring(2,4);
String year=str.substring(4,8);

System.out.println("date:"+date);
System.out.println("Month:"+mon);
System.out.print("Year:"+year);

}
}

*********************************************************************************************
*********************************************************************************************
*
30) MEGA MART CUSTOMER IDENTIFICATION(String and SUBSTRING)

import java.util.*;
public class arraysquare{
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the customer id");
String cid = sc.next();
String shop = cid.substring(0,4);
//System.out.println("shop");
if(!shop.equals("Mega")){
System.out.println("Invalid Shop Name");
Runtime.getRuntime().halt(0);
}
String type = cid.substring(4,cid.length()-3);
//System.out.println(type);
if(!type.equals("Silver") && !type.equals("Gold") && !type.equals("Platinum")){
System.out.println("Invalid Customer Type");
Runtime.getRuntime().halt(0);
}
int mid = Integer.parseInt(cid.substring(cid.length()-3,cid.length()));
//System.out.println(mid);
if(mid<=99 || mid>=1000){
System.out.println("Invalid Member id");
Runtime.getRuntime().halt(0);
}
System.out.println("Welcome Mega Mart "+type+" Customer");

}
}

*********************************************************************************************
***********************************
31) .MALE AND FEMALE COUNT

INPUT: MmFMff

OUTPUT: 3 MALE
3 FEMALE

import java.util.Scanner;
import java.util.regex.*;
public class minmax {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
String s=sc.nextLine();
int count1=0;
int count2=0;
if(Pattern.matches("[MmFf ]+",s)){
for (int i = 0; i < s.length(); i++) {
if (s.charAt(i) == 'M' || s.charAt(i) == 'm') {
count1++;
} else if (s.charAt(i) == 'F' || s.charAt(i) == 'f') {
count2++;
}
}
System.out.println(count1 + " Male");
System.out.println(count2 + " Female");
}
else
{
System.out.println("Invalid Input");
}
}
}
*********************************************************************************************
*********************************************************************************************
***
32. RAINFALL

INPUT: Enter the length of the roof in meters: 4


Enter the breadth of the roof in meters: 3
Enter the rainfall level: 3

OUTPUT: 360.00 Litres

import java.util.Scanner;
public class minmax {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
System.out.println("Enter the length of the roof in meters");
double l=sc.nextDouble();
if(l<=0)
{
System.out.println("Invalid Length");
return;
}
System.out.println("Enter the breadth of the roof in meters");
double b=sc.nextDouble();
if(b<=0)
{
System.out.println("Invalid breadth");
return;
}
System.out.println("Enter the rainfall level");
double r=sc.nextDouble();
if(r<=0)
{
System.out.println("Invalid rainfall");
return;
}
double h;
h=(l*b) *(r*10);
System.out.println(String.format("%.2f",h)+"Litres");
}
}

*********************************************************************************************
*********
33) NUMEROLOGY NAME CHECKING

import java.util.*;
import java.util.regex.Pattern;

public class arraysquare{


public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the name");
String a=sc.next();
if(!Pattern.matches("[A-Za-z]+",a))
{
System.out.println(a+" is an Invalid name");
return;
}
int sum=0;
char b[]=a.toCharArray();
for(int i=0;i<b.length;i++)
{
if(b[i]=='A'||b[i]=='a')
{
sum+=1;
}
else if(b[i]=='B'||b[i]=='b')
{
sum+=2;
}
else if(b[i]=='C'||b[i]=='c')
{
sum+=3;
}
else if(b[i]=='D'||b[i]=='d')
{
sum+=4;
}
else if(b[i]=='E'||b[i]=='e')
{
sum+=5;
}
else if(b[i]=='F'||b[i]=='f')
{
sum+=6;
}
else if(b[i]=='G'||b[i]=='g')
{
sum+=7;
}
else if(b[i]=='H'||b[i]=='h')
{
sum+=8;
}
else if(b[i]=='I'||b[i]=='i')
{
sum+=9;
}
else if(b[i]=='J'||b[i]=='j')
{
sum+=10;
}
else if(b[i]=='K'||b[i]=='k')
{
sum+=11;
}
else if(b[i]=='L'||b[i]=='l')
{
sum+=12;
}
else if(b[i]=='M'||b[i]=='m')
{
sum+=13;
}
if(b[i]=='N'||b[i]=='n')
{
sum+=14;
}
if(b[i]=='O'||b[i]=='o')
{
sum+=15;
}
if(b[i]=='P'||b[i]=='p')
{
sum+=16;
}
if(b[i]=='Q'||b[i]=='q')
{
sum+=17;
}
if(b[i]=='R'||b[i]=='r')
{
sum+=18;
}
if(b[i]=='S'||b[i]=='s')
{
sum+=19;
}
if(b[i]=='T'||b[i]=='t')
{
sum+=20;
}
if(b[i]=='U'||b[i]=='u')
{
sum+=21;
}
if(b[i]=='V'||b[i]=='v')
{
sum+=22;
}
if(b[i]=='W'||b[i]=='w')
{
sum+=23;
}
if(b[i]=='X'||b[i]=='x')
{
sum+=24;
}
if(b[i]=='Y'||b[i]=='y')
{
sum+=25;
}
if(b[i]=='Z'||b[i]=='z')
{
sum+=26;
}
}
System.out.println(sum);
if(sum%3==0 && sum%2==0)
{
System.out.println(a+" is a numerology name");
}
else
{
System.out.println(a+" is not a numerology name");
}
}
}

*******************************************************************************

34)OMR

import java.util.Scanner;
public class arraysquare{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int i;
System.out.println("Enter the No of questions");
int a=sc.nextInt();
if(a<0)
{
System.out.println("Invalid Number");
return;
}
int count=0;
int mark=0;
char b[]=new char[a];
System.out.println("Enter the answer key");
for (i=0;i<a;i++) {
b[i] = sc.next().charAt(0);

if ((b[i] >= 'a' && b[i] <= 'e')||(b[i] > 'E')) {


System.out.println("Invalid Answers");
return;
}
}
char c[]=new char[a];
System.out.println("Enter the student answers");
for (i=0;i<a;i++)
{
c[i]=sc.next().charAt(0);
if ((c[i] >= 'a' && c[i] <= 'e')||(b[i]>'E')) {
System.out.println("Invalid Answers");
return;
}
}

for(i=0;i<a;i++)
{
if(b[i]==c[i])
{
count++;
}
}
if(count>0)
System.out.println("Correct answers are "+count);
mark=(count*100)/a;
if(count<1)
System.out.println("All answers are wrong");
System.out.println("Mark is "+mark);

}
}
JAVA END
*********************************************************************************************
*********************************************************************************************
********

RDBMS IMPORTANT CODES(NOT TESTED)

1.)Select concat(concat(customer_name,'has taken a


policy on'),date_of_policy) as Enrollment_details
from customer JOIN Policy using (customer_id)
order by customer_name,date_of_policy;

2.)select plolicy_id,policy_name,rate_of_interest, bonus_percentage


from policy
where minimum_primeium_amount = 1200
order by policy_d;

3.)select fine_range,fine_amount
CASE
When fine_range=L1
then 5+fine_amount
when fine_range=L2
then 10+fine_amount
When fine_range=M1
then 15+fine_amount
when fine_range=M2
then 20+fine_amount
When fine_range=H1
then 25+fine_amount
when fine_range=H2
then 30+fine_amount
END as NEW_FINE_AMOUNT

4.)select leave_type,allocated_days
CASE
when leave_type='CASUAL'
then allocated_days+2
when leave_type='SICK'
then allocated_days+5
when leave_type='MATERNITY'
then allocated_days+90
when leave_type='MARRIAGE'
then allocated_days+3
when leave_type='STUDY'
then allocated_days-2
END as NEW_ALLOCATED_TYPES
from table_name
order by leave_type;

5.) select emp_id,emp_name,department_id,department_name


from Department JOIN Employee using (department_id)
JOIN Leave+Avail_details using (Emp_id)
JOIN Leave using (Leave_type)
where Allocated_days = 0
order by emp_id;
*********************************************************************************************
**

1.) Account Info - "HDVL002"


select account_type, count(account_id) as TOTAL_ACCOUNTS
from Acount_Info where IFC_Code = 'HDVL002'
group by account_type order by account_type;

2.)select customer_id,customer_name,phone_no,order_date
from Customer_info JOIN Orders using (customer_id)
where order_amount > 500
order by customer_id,order_date;

3.) select distinct customer_id,customer_name,phone_no,loan_amount as


total_loan_amount from customers JOIN loans_taken using
(customer_id)
order by customer_id;

4.) select distinct boat_id,seat_capacity,count(ride_id) as ride_count


From Boat_details JOIN Ride_details using (boat_id)
order by boat_id;

5.) select customer_id,customer_name,contact_no,mail_id


from Coustomer_details where Gender = 'M'
order by customer_id;
6.) select customer_name,total_amount_paid
from Customer_master JOIN Booking_details using (customer_id)
where total_amount_paid < (select max(total_amount_paid) from booking_details
where total_amount_paid < (select max(total_amount_paid) from booking_details))
order by customer_name;

7.) select book_code,book_title, author,rack_num


from book_details where category = 'JAVA'
order by book_code;

8.) select customer_name,policy_enrollment as Enrollment_details


from customer JOIN policy_enrolmment using (customer_id)
order by customer_name,date_of_enrollment;

9.)DECODE QUESTION
select fine_range, fine_amount,
decode(fine_range, 'L1',fine_amount+5,
'L2',fine_amount+10,
'M1',fine_amount+10,
'M2',fine_amount+10,
'H1',fine_amount+10,
'H2',fine_amount+10)new_fine_amount
from fine_details;

10.)select customer_name||" has taken policy on"|| date_of_enrollment as


enrollment_details form customer
join policyenrollent using (customer_id)
order by customr_name,date_of_enrollment;

11.)select policy_id,policy_name,rate_of_interest,bonus_percentage
from policy where mimum_premium_amount = 1200
order by policy_id;

12.) select customer_id,customer_name, street,phone_no,email


from Customers JOIN loan_taken using (customer_id)
where loan_amount > = 500000 and loan_amonunt <1500000
order by customer_id;

13.)select distinct boat_id, boat_name,boat_type


from boat_details JOIN ride_details using (boat_id)
where DOT LIKE '%-AUG-%' and Shift = 'evening'
order by boat_id;

14.) select policy_id,policy_name,rate_of_interest


from policy where miniimum_ppremium_amount < 3000 AND bonus_percent > 85
order by policy_id;

RDBMS ANSWERS

1.1) Write a query to display boat_type and number of boats running under each type. Give an alias name as 'NO_OF
_BOATS'.
Note: Boat_type can be 'DELUXE' or 'SUPER DELUXE'.

select boat_type,count(Boat_id) as NO_OF_BOATS


from boat_details
group by Boat_type;

1.2) select boat_name,boat_type from boat_details


where seat_capacity between 100 and 200
order by boat_name desc;

2.1) select vehicle_type,count(vehicle_id)


from vehicle_details
group by vehicle_type
order by vehicle_type;

2.2) select driver_id,driver_name,phone_no,Driver_rating


from driver_details where driver_rating between 3 and 5
order by driver_rating desc;

3.1) select coursename from course


c join registration r on
c.courseid=r.courseid
having count(studid)>=2
group by coursename
order by coursename;

3.2) select s.studid,sum(fees) as TOTALFEES


from student s join registration r
on s.studid=r.studid join course c
on r.courseid=c.courseid
group by s.studid
order by s.studid;

3.3) select studid,count(CourseID) as NOOFCOURSES


from registration
group by Studid
order by NOOFCOURSES desc,Studid;

3.4) select student.stuid,firstname from student


join registration on registration.stuid=student.stuid
where lower(to_char(doj,'MON'))='jan';

3.5) select courseid,coursename from


course where duration between 10 and 15;

3.6) select courseid,registration.stuid from registration


join student on registration.stuid=student.stuid
where lower(to_char(doj,'MON'))=lower(to_char(dob,'MON'));
Longest substring

Input : abczgdpqrstubg
Output: pqrstu
*/
import java.util.*;
public class Main
{
public static void main (String[] args)
{
Scanner sc=new Scanner(System.in);
String s=sc.next();
int firstindex=0,lastindex=0,length=0;
for(int i=0;i<s.length();i++)
{
int asci=s.charAt(i);
int count=1;
for(int j=i+1;j<s.length();j++)
{
if(s.charAt(j)==++asci)
{
count++;
continue;
}
else
{
if(count>length)
{
firstindex=i;
lastindex=j;
length=count;
break;
}
}
}
}
System.out.println(s.substring(firstindex,lastindex));
}
}
Non Unique char Elimination from string

public class NonUniqueElimination {


public static void main(String[] args){
Scanner sc=new Scanner(System.in);
String name=sc.nextLine(),abc="";
int count=0;
for(int i=0;i<name.length();i++)
{
for(int j=1;j<name.length()-1;j++)
{
if(name.charAt(i)==name.charAt(j))
{
name=name.replace(String.valueOf(name.charAt(j)),"");
count+=1;
}
}
}
if(count==0) {
System.out.println("All are unique character");
return;
}
else {
System.out.println(name);
}
}
Sum of integers at even or odd places

need to specify size (say 5) and then take 5 integer numbers as Input. If the
number of digits in the number is odd then we need to add all odd places digits
and if number of digits is even then we need to add all even place digits. In the
end sum of all these individual sum needs to be displayed as result.

Eg enter size :5
Enter numbers
123(1+3=4)
2536(5+6=11)
2(2)
57(7)
76542(7+5+2=14)
Output: 38 (4+11+2+7+14)

No of substring from a given string

Given a string and a substring, find the number of occurances of the substring in
the given string.
Check that the string can contain only alphabets.
Consider both string and substring in lower case.
Eg:
Enter the string
Entertainment
Enter substring
en
Output : 2
Unknown

input: psvy & 4


(find the difference between p&s i.e 2 and print next 4 letters)
Output: behk

calculate Price*Duration after the deduction of discounts in a Bike renting


Company

*Name should be only in alphabets.. If not Print Invalid


*discount eligible only when the Duration is 5 or more
*Discount table will be given for each card (like Visa,Rupay,Mastercard)
*You have to apply discount for based on the option they used.. (This data is as
1,2,3 where option 1 is visa card option 2 is Rupay)
*If Card option is given as 4,5,6,,... OR 0,-1,-2,,,.. Print "Try again" and go back to
get card option until it's a valid one..

best runner from the given inputs

Input will be given as(Name,seconds)


Jorge, 9.78
Alex, 9.65

Order identification
U need to find weather the array elements are in ascending order r not
Note:array size between 2 and 10(inclusive)
Input1:
Enter the array size:3
Enter the elements
53
52
51
Output:
53 52 51 are not in ascending order

Input2:
Enter the array size:5
Enter the elements
32
65
71
78
82
Output:
32 65 71 78 82 are in ascending order

Product of case count


you need to count uppercase letters and lower case letters in a given string
Multiply the counts and display
Note: string shouldn't contain any digits, special characters
Length shouldn't be greater than 10
Input:
YouRName
Output:
Product value is 15
Explanation
Uppercase letters=3
Lowercase letters=5
Display 3*5=15

import java.util.*;
public class Program{

public static void main(String[] args){


Scanner sc = new Scanner(System.in);
int countj=0,countk=0,i;
System.out.println("Enter string:");
String str=sc.next();
char str1[]=new char[str.length()];
for( i=0;i<str.length();i++) {
if(str.charAt(i)<=122&&str.charAt(i)>=97) {
countj++;
}
else if(str.charAt(i)<=90&&str.charAt(i)>=65) {
countk++;
}
}
System.out.println(countj+" "+countk);
int product=countj*countk;

System.out.println(product);

}}

Unknown
Here, size of the array should be taken as input, and it should be between 1 and
10 (inclusive)
If it is not in 1 and 10, print it as "invalid"
Now, by the comparing the values at the same indices of both the arrays, if both
values are even, then print the sum of the two values, otherwise print "0".
Before performing operation, make sure if no even element is present in both the
arrays, then print it as "There are no even elements in both the arrays",
otherwise perform the above operation.
For example, see the following inputs and outputs:
1. Sample input:
Enter the size of array: 3
Enter the elements in first array:
2
3
4
Enter the elements in second array:
1
5
8
Sample output:
0
0
12

2. Enter the size of array: 3


Enter the elements in first array:
5
3
1
Enter the elements in second array:
1
5
9
Sample output:
There are no even elements in both the arrays

3.Sample input:
Enter the size of array: 1
Enter the elements in first array:
5
Enter the elements in second array:
1
Sample output:There are no even elements in both the arrays
Unkown

Here, a list of grocery items are present as follows:

Rice - 3kg, 5 Rs/kg


Wheat - 2kg, 10Rs/kg
Oil - 4litres, 20Rs/litre
Kerosene - 5litres, 15Rs/litre

Now each of the items is abbreviated by R,W,O and K respectively

Sample input:
ORW
Sample output: the
115
Offer to customers
Toll fee for region code
Take input string of numbers. Extract last four numbers from the string. Calculate
the discount price of the product based on those four numbers.

We need to input the product code as a string


The length of that string shd be of 6-8
If not print invalid
And we need to extract last 4 characters from that string, that will be the MRP of
the product
If the MRP is between 0 to 10, then offer is 0₹
If MRP between 11 to 50, offer is 5₹
If MRP between 51 to 500, offer is 15
If MRP between 501 to 5000, offer is 105
If MRP is above 500, offer is 1005

We need to print the MRP as well as the price after the offer is applied

Sample input 1
20220050
Output 1
MRP : ₹50
Offer price : ₹45

Sample input 2
350004
Output 2
MRP: ₹4
Offer price :₹4

Sample input 3:
202200050
Output 3:
Invalid input
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String n = sc.nextLine();
if (5 < n.length() && n.length() < 9) {
String s = n.substring(n.length() - 4);
int price = Integer.parseInt(s);
if (0 < price && price < 10) {
System.out.println("MRP: Rs " + price);
System.out.println("Offer Price: Rs " + price);
} else if (10 < price && price < 51) {
System.out.println("MRP: Rs " + price);
System.out.println("Offer Price: Rs " + (price - 5));
} else if (50 < price && price < 501) {
System.out.println("MRP: Rs " + price);
System.out.println("Offer Price: Rs " + (price - 15));
} else if (500 < price && price < 5001) {
System.out.println("MRP: Rs " + price);
System.out.println("Offer Price: Rs " + (price - 105));
} else if (5000 < price) {
System.out.println("MRP: Rs " + price);
System.out.println("Offer Price: Rs " + (price - 1005));
}
} else {
System.out.println("Invalid Input");
}
}

Reverse and Concatenate

She sells seashells


Same first letter for all words so reverse the last word and concatenate first word
Output: sllehsaesShe

If first letter is not same then reverse first word and concatenate with last word

Male female version code


import java.util.*;
import java.util.regex.Pattern;
public class Main{
public static void main(String args[]){

Scanner sc = new Scanner(System.in);

String str = sc.next();

int count=0;
int count1=0;

if(Pattern.matches("[mfMF]+",str)){

for(int i=0;i<str.length();i++){
if(str.charAt(i)=='M' || str.charAt(i)=='m'){
count++;
}
else if( str.charAt(i)=='F' || str.charAt(i)=='f'){
count1++;
}
}
System.out.println(count+" Male");
System.out.println(count1+" Female");
}
else{
System.out.println("Not a valid input");
return;
}
}
}
LCM

Tony comes to hotel every 4(i) days and potts every 6(j) days when will they
meet? if i or j <0 print invalid, don't use system.exit (To find LCM)

Cake
Input : 4725strawberry181
Extract the weight , flavour , order id and output the cake price according to per kg price given
initially , and print all the cake details.
Output :
4.73 kg
Strawberry
181
Price:

import java.util.*;
public class cake_order {
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
String s=sc.next();
if(!s.matches("^[a-zA-z0-9]*$"))
{
System.out.println("Invalid string");
return;
}
else
{
String str=s.substring(0,4);
for(int i=0;i<str.length();i++)
{
if(!Character.isDigit(str.charAt(i)))
{
System.out.println("Invalid string");
return;
}

}
int num=Integer.parseInt(str);
if(num<1000)
{
System.out.println("Invalid weight");
return;
}
int l=s.length();
int li=l-3;
String s1=s.substring(li,l);
for(int i=li;i<l;i++)
{
if(!Character.isDigit(s.charAt(i)))
{
System.out.println("Invalid orderno");
return;
}
}
int k=Integer.parseInt(s1);
if(k<100)
{
System.out.println("Invalid Order no");
return;
}
double I=Double.parseDouble(str)/1000;
String form=String.format("%.2f", I);
System.out.println("Cake weight is "+form);
String falv="";
for(int i=4;i<li;i++)
{
falv+=s.charAt(i);
}
System.out.println("Cake flavour is "+falv);
System.out.println("Order no is "+s1);
double price=450*I;
String f=String.format("%.2f",price);
System.out.println("Price is "+f);
}
}
}

Products equals sum


Fun count

Input array of string


if there is 5 input
barbie
barbie
doll
doll
bike

output
barbie=2
doll=2
bike=1
Speed Calculation

The normal_speed 30km/h was given


Take two input hours and distance
Find speed= distance/hours
if speed > normalspeed
then
Actual speed=speed-normal_speed
print actual speed
else
print continue on speed
Add with index
Next Mixing Letters
Mega mart customer identification
Theater seat details
Compose Rhythm(Prime numbers btw two no’s)
Rating Score
Unknown
ASCii

Ascii

import java.util.*;
import java.lang.*;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("Enter the String");
String str =in.nextLine();
for(int i=0;i<str.length();i++)
{
if((Character.isLetter(str.charAt(i)) || Character.isWhitespace(str.charAt(i))))
continue;
else{
System.out.println(str+" is not a valid string");
return;
}
}
int sum=0;
for(int i=0;i<str.length();i++){
if((i+1)%3==0){
sum+=(int)str.charAt(i);
}
}
System.out.println("Sum is "+sum);
}
}
Product equal sum

import java.util.*;
public class arraysquare
{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the array size");
int n=sc.nextInt();
if(n<1 || n>10)
{
System.out.println("Invalid array size");
return;
}
int a[]=new int[n];
System.out.println("Enter the elements of the first array");
for(int i=0;i<n;i++)
{
a[i]=sc.nextInt();
if(a[i]<10 || a[i]>999) {
System.out.println("Invalid input);
}
}
System.out.println("Enter the elements of the second array");
int b[]=new int[n];
for(int i=0;i<n;i++)
{
b[i]=sc.nextInt();
if(b[i]<10 || b[i]>999) {
System.out.println("Invalid input);
}
}
int x[]=new int[n];
int y[]=new int[n];
for(int i=0;i<n;i++)
{
int c=a[i];
int prod=1;
while(c!=0)
{
prod*=(c%10);
c/=10;
}
x[i]=prod;
prod=0;
}
for(int i=0;i<n;i++)
{
int s=b[i];
int sum=0;
while(s!=0)
{
sum+=(s%10);
s/=10;
}
y[i]=sum;
sum=0;
}
int count=0;
for(int i=0;i<n;i++)
{
if(x[i]==y[i])
{
System.out.println(a[i]+","+b[i]);
count++;
}
}
if(count==0) {
System.out.println("No pair found");
}
}
}
1.Admas
Input:hththt
Output:-Team May Win
package sda;
import java.util.*;
public class Admas {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
String str=sc.nextLine();
int len=str.length();
//boolean flag=false;
if(len>=2) {
boolean flag=false;
for(int i=0;i<str.length()-1;i=i+2) {
char ch=str.toLowerCase().charAt(i);
if(ch=='h') {
char ch1=str.toLowerCase().charAt(i+1);
if(ch1=='t') {
flag=true;
}else if(ch1=='h') {
//flag=false;
System.out.println("Team may lose");
return;
}
else {
System.out.println("Invalid string");
return;
}
}

else if(ch=='t') {
char ch1=str.toLowerCase().charAt(i+1);
if(ch1=='h') {
flag=true;
}else if(ch1=='t') {
//flag=false;
System.out.println("Team may lose");
return;
}
else {
System.out.println("Invalid string");
return;
}
}
}
if(flag==true) {
System.out.println("win");
}else {
System.out.println("lose");

}
}

}
}

2.Alternate Number diffrences


Input:
Array element:4
Element:
4
5
6
7
4-7+5-6
Output:4

package sda;
import java.util.*;
public class AlterNateSumDiff {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int no=sc.nextInt();
int arr[]=new int[no];
int diff=0,sum=0;
for(int i=0;i<no;i++) {
arr[i]=sc.nextInt();
}
for(int i=0;i<no/2;i++) {
diff=arr[i]-arr[no-i-1];
sum+=diff;
}
System.out.println(sum);
}

}
3.Asscending Array:
package sda;
import java.util.*;
public class AssendingArray {
public static void main(String args[]) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the Array size:");
int no=sc.nextInt();
int count=0,f=0;
if(no>=2 && no<=10) {
int arr[]=new int[no];
int copy_arr[]=new int[no];
System.out.println("Enter the array element:");
for(int i=0;i<no;i++) {
arr[i]=sc.nextInt();
copy_arr[i]=arr[i];
}for(int i=0;i<no-1;i++) {
if(arr[i]==arr[i+1]) {
f++;
}
}if(f==no) {
System.out.println("Same array");
return;
}
Arrays.sort(copy_arr);
System.out.println(copy_arr);

for(int i=0;i<no;i++) {
if(copy_arr[i]==arr[i]) {
count++;
}
}
System.out.println(count);
if(count==no) {
for(int i=0;i<no;i++) {
System.out.print(arr[i]+" ");
}
System.out.print(" are in ascending order");
}else {
for(int i=0;i<no;i++) {
System.out.print(arr[i]+" ");
}
System.out.print(" are not in ascending order");

}
}else {
System.out.print("Invalid array size");
}

}
4.Bike Rent:
package sda;
import java.util.*;
public class BIkeRent {
public static void main(String args[]) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter your name");
String name=sc.nextLine();
if(name.matches("[a-zA-Z]+")) {
System.out.println("Enter the time duration");
int time=sc.nextInt();
if(time>=1 && time<=24) {
System.out.println("List of the Payment
option;");
System.out.println("1) Visa Card");
System.out.println("2) Rupay card");
System.out.println("3) Master card");
System.out.println("Choose an option\n");
//int op=sc.nextInt();
while(true) {
int op=sc.nextInt();
double bill;
double bill1;
if(op==1) {
if(time>=5) {
bill=(time*120);
bill1=(bill-bill*0.25);
System.out.println("Dear
"+name+" your bill is "+String.format("%.2f",bill1));
}else {
bill=time*120;
System.out.println("Dear
"+name+" your bill is "+String.format("%.2f",bill));
}
}else if(op==2) {
if(time>=5) {
bill=(time*120);
bill1=(bill-bill*0.17);
System.out.println("Dear
"+name+" your bill is "+String.format("%.2f",bill1));
}else {
bill=time*120;
System.out.println("Dear
"+name+" your bill is "+String.format("%.2f",bill));
}
}else if(op==3) {
bill=(time*120);
System.out.println("Dear "+name+" your
bill is "+String.format("%.2f",bill));
}

else {
System.out.println("TRy again");
//break;
//continue;
}
}
}

}
}
}

5.Cake Shop Order


package sda;
import java.util.*;
public class CakeShopOrder {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the customer instrution");
String str=sc.nextLine();
String w=str.substring(0,4);
int weight=0,order_no=0;
String order=str.substring(str.length()-3);
String flavor=str.substring(4,str.length()-3);
if(!(str.matches("[a-zA-z0-9]+"))) {
System.out.println("Invalid Instruction");
return;
}
else if(w.contains("[0-9]+" )) {
weight=Integer.parseInt(w);
System.out.println("Invalid weight");
return;
}
else if(!order.contains("[0-9]+")) {
System.out.println("Invalid Oreder number");
return;

else {
if(weight<999) {
System.out.println("Invalid Weight");
return;
}
double kg=(Double.parseDouble(w))/1000;
System.out.println("Cake weight is "+kg+"kg");
System.out.println("Cake Flavor is "+flavor);
System.out.println("Cake No is "+order);
double price=450*kg;
System.out.println("Price is "+String.format("%.2f",price));
}
}
}

6.Character Addition
package sda;
import java.util.*;
public class CharacterAddition {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number of sentences:");
int no=sc.nextInt();
if(no>0) {
String arr[]=new String[no];
for(int i=0;i<no;i++) {
arr[i]=sc.next();
sc.nextLine();
}
int asci[]=new int[no];
for(int i=0;i<no;i++) {
int sum=0;
for(int j=0;j<arr[i].length();j++) {

if(Character.isAlphabetic(arr[i].charAt(j))) {
sum=arr[i].charAt(j)+sum;
}else {

if(Character.isDigit(arr[i].charAt(j)))
{
continue;
}
}
}asci[i]=sum;
}for(int i=0;i<no;i++) {
System.out.println(asci[i]);
}

}else {
System.out.println("Invalid input");
}

}
7.Product Case Count:

package sda;
import java.util.*;
import java.lang.*;
public class CountUpperLowerChar {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the String:");
String str=sc.nextLine();
if(str.matches("[a-zA-Z]+")) {
int ucount=0,lcount=0;

for(int i=0;i<str.length();i++) {
if(str.charAt(i)>='A' && str.charAt(i)<='Z') {

ucount++;
}
else {
lcount++;
}
}
//System.out.print(ucount+" "+ lcount);
System.out.print("Product value is "+ucount*lcount);

}else {
System.out.println("Invalid String");
}
}

}
8.Non unique char:

package sda;
import java.util.*;
public class DescString {
public static void main(String[] arge) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the string");
String str=sc.nextLine();
StringBuilder sb=new StringBuilder(str);
for(int i=0;i<sb.length()-1;i++) {
for(int j=i+1;j<sb.length();j++) {
if(sb.charAt(i)==sb.charAt(j)) {
sb.deleteCharAt(j);
j--;
}
}

}
char[] c=sb.toString().toCharArray();
Arrays.sort(c);
sb=new StringBuilder(new String(c));
sb.reverse();
System.out.println(sb);

}
9.Divide by three:

package sda;
import java.util.*;
public class DivdeByThree {
public static void main(String args[]) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the String");
String str=sc.nextLine();
if(!str.matches("[]a-zA-Z ]+")) {
System.out.println("Invalid String");
return;

}else {
int sum=0,c=0;
for(int i=0;i<str.length();i++) {
if((i+1)%3==0) {
//System.out.println(c);
sum+=str.charAt(i);
c++;
}
}if(c==0) {
System.out.println("sum is "+sum);
}else {
System.out.println("sum is "+sum);
}
}
}

10.Fastest Runner:
Input:
Shraddha,9.45
Aanushree 9.34
Output:
Aanushree,9.34

package sda;
import java.util.*
public class FastRunner {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number of runners:");
int no=sc.nextInt();
if(no>0 && no<=10) {
System.out.println("Enter the runners:");
String run[]=new String[no];
String name[]=new String[no];
String run_time[]=new String[no];

for(int i=0;i<no;i++) {
run[i]=sc.next();
sc.nextLine();
String time[]=run[i].split(",");
name[i]=time[0];
run_time[i]=time[1];
float time1=Float.parseFloat(time[1]);
if(time1<8.00 || time1>12.00) {
System.out.println(time[1]+" is an invalid
input");
return;
}
}
String min=run_time[0];
int count=0;
float min1=Float.parseFloat(min);
for(int j=0;j<no;j++)
{
float val=Float.parseFloat(run_time[j]);
if(val<=min1)
min1=val;
}
for(int i=0;i<no;i++) {
float val=Float.parseFloat(run_time[i]);
if(val==min1) {
System.out.println(name[i]);
count++;
}
}
if(count==no) {
System.out.println("All the runner have same
time");
return;
}

}else {
System.out.println("Invalid");
}
}
}

11.Fun Count

package sda;
import java.util.*;
public class FunCount {
public static void main(String args[]) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number of element in array");
int no=sc.nextInt();
int count=1;
String arr[]=new String[no];
//String count1[]=new String[no];
for(int i=0;i<no;i++) {
arr[i]=sc.next();
sc.nextLine();
}for(int i=0;i<no;i++) {
for(int j=i+1;j<no;j++) {
if(arr[i].equals(arr[j])) {
count++;
arr[j]="";
}
}if(arr[i]!="") {
System.out.println(arr[i]+"="+count);
}
}

12.Gender Count:

package sda;
import java.util.*;
public class GenderCount {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
String str=sc.nextLine();
sc.close();
int mcount=0,fcount=0;
for(int i=0;i<str.length();i++) {
char ch=str.toLowerCase().charAt(i);
if(ch=='m') {
mcount++;

}else if(ch=='f') {
fcount++;
}else {
System.out.println("Invalid input");
return;

}
}
System.out.println(mcount+" Male");
System.out.println(fcount+" Female");
}

13.Harshad Number

package sda;
import java.util.*;
public class HarShadNumber {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the Number:");
int no=sc.nextInt();
if(no<=0) {
System.out.println("Invalid Input");
System.exit(0);
}
int rem=0;
int arr[]=new int[no];
int arr1[]=new int[no];
System.out.println("Enter the Element:");

for(int i=0;i<no;i++) {
arr[i]=sc.nextInt();
arr1[i]=arr[i];
}
int sum1[]=new int[no];
for(int i=0;i<no;i++) {
int sum=0;

while(arr[i]>0) {
rem=arr[i]%10;
sum=sum+rem;
arr[i]/=10;
sum1[i]=sum;
//sum=0;
}}

for(int i=0;i<no;i++) {
if(arr1[i]%sum1[i]==0) {

System.out.println(arr1[i]);
//System.out.println(sum1[i]);
}
}
}
}

14.Longest String:
package sda;
import java.util.*;
public class LongestString {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the string:");
String str=sc.nextLine();
int findex=0,lindex=0,length=0;
for(int i=0;i<str.length();i++) {
int asci=str.charAt(i);
System.out.println(str.charAt(i)+"1"+asci);

int count=1;
for(int j=i+1;j<str.length();j++) {
if(str.charAt(j)==++asci) {
System.out.println(str.charAt(j)+"2"+asci);
count++;
continue;
}else {
if(count>length) {
System.out.println(count+"3");

findex=i;
lindex=j;
length=count;
break;
}
}

}
}System.out.println(str.substring(findex,lindex));
}
}

15.Maximun No ADDition

package sda;
import java.util.*;
public class MaxAdd {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number of element in array:");
int no=sc.nextInt();
int max=0;
System.out.println("Enter the of element of array:");
int arr[]=new int[no];
for(int i=0;i<no;i++) {
arr[i]=sc.nextInt();
if(max<arr[i]) {
max=arr[i];
}
}
System.out.println(max);
}

16.Add with index

package sda;
import java.util.*;
public class MaxIndex {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the no of elements in arrays: ");
int no=sc.nextInt();
if(no<5) {
System.out.println(no+" is too low");
return;
}
if(no>10) {
System.out.println(no+" is too high");
}
int arr[]=new int[no];
int max=arr[0];
int index=0;

for(int i=0;i<no;i++) {
arr[i]=sc.nextInt();
if(arr[i]>max) {
max=arr[i];
System.out.println(max+" "+arr[i]);
index=i;
System.out.println(index);
}
}
for(int i=0;i<no;i++) {

if(i!=index) {
System.out.println(arr[i]+index);
}else {
System.out.println(arr[i]);
}
}
}

17.Product of Maximun and Minimun no


package sda;
import java.util.*;
public class MaxMinNo {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the array size:");
int no=sc.nextInt();
if(no>2) {
if(no<11) {
int arr[]=new int[no];
System.out.println("Enter the array element:");
for(int i=0;i<no;i++) {
arr[i]=sc.nextInt();
}
Arrays.sort(arr);
System.out.println(arr[0]*arr[no-1]);

}else {
System.out.println(no+" exceeds limit");

}
}else {
System.out.println(no+" is too small");

18.Mega Mart

package sda;
import java.util.*;
public class MeghaMart {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the customer id:");
String str=sc.nextLine();
String name=str.substring(0,4);
String mid=str.substring(str.length()-3,str.length());
System.out.println(mid);
String cus_type=str.substring(4,str.length()-3);
System.out.println(cus_type);
//System.out.println(mem_id);
String sname="Mega";
if(!name.equals(sname)) {
System.out.println("Invalid shop name");
return;
}else if(!mid.contains("[0-9]+")){
System.out.println("Invalid member id");
}
else if(mid.contains("[0-9]+")){
int mem_id=Integer.parseInt(str.substring(str.length()-
3,str.length()));

if(mem_id>99 && mem_id<1000) {


System.out.println("Invalid mem_id");
return;
}else {
System.out.println("Invalid member id");
return;
}
}
else if(!(cus_type.equals("Sliver") || cus_type.equals("Gold") ||
cus_type.equals("Paltinum")))
{
System.out.println("Invalid customer type");
}else {

System.out.println("Welcome "+name+" Mart "+cus_type+"


Customet");
}

19.MRP

package sda;
import java.util.*;

public class MrpAssesment {


public static void main(String args[]) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number");
String no=sc.nextLine();
int len=no.length();
int dis=0;
if(len>=6 && len<=8) {
String mrp=no.substring(len-4);
int mrp1=Integer.parseInt(mrp);
System.out.println("MRP: Rs "+mrp1);
if(mrp1>=1 && mrp1<=10) {
dis=mrp1;
}
else if(mrp1>=11 && mrp1<=50)
{
dis=mrp1-5;
//System.out.println("Offer price: Rs "+ mrp1);

}
else if(mrp1>=51 && mrp1<=500) {
dis=mrp1-15;
}
else if(mrp1>=501 && mrp1<=5000)
{
dis=mrp1-105;
}
else {
dis=mrp1-1005;
}

System.out.println("Offer price: Rs "+ dis);


}else {
System.out.println("Invalid Input");
}

}
}

20.Next Mixxing letter


package sda;
import java.util.*;
public class NextMixingLetter {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
String str=sc.nextLine();
int sub=str.charAt(0)-str.charAt(1);
for(int i=0;i<str.length()-1;i++) {
int no1=str.charAt(i);
int no2=str.charAt(i+1);
int diff=no1-no2;
if(sub!=diff) {
System.out.println(str+" is not a squence");
return;
}
}
System.out.println("Enter the sequence times");
int seq=sc.nextInt();
if(seq<=0) {
System.out.println(seq+" is invalid");
return;
}

int temp=str.charAt(str.length()-1);
System.out.print(temp+" "+(char)temp);
for(int j=0;j<seq;j++) {
temp=temp-sub;
System.out.print(temp+" "+(char)temp);
if(temp>122) {
// System.out.print(temp+"
"+(char)temp);
temp=temp-26;
System.out.print((char)temp);
}else if(temp<97) {
//System.out.print(temp+"
"+(char)temp);
temp=temp+26;
System.out.print((char)temp);
}else {
System.out.print((char)temp);
}

}
}

21.Find perticlar Number


Input
123453
No to find
3
Output
2

package sda;
import java.util.*;
public class NoFind {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the numbe");
int n=sc.nextInt();
System.out.println("Enter number to be search");
int sea=sc.nextInt();
int count=0;
while(n!=0) {
int rem=n%10;
//System.out.println(rem);
if(rem==sea) {
count++;
}
n=n/10;
//System.out.println(n);
}
System.out.println(count);
}

22.Numerology
package sda;

import java.util.*;
public class Numerology{
public static void main (String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter your Name");
String str1=sc.next();
String str=str1.toUpperCase();
int value=0,sum=0;
if(str.matches("[A-Z]+")){
for(int i=0;i<str.length();i++){
value=(int)(str.charAt(i));
sum+=value;

}
if(sum%2==0 && sum%3==0) {
System.out.println(sum+"\n"+str1+" is a Numerology
name");

}
else{
System.out.println(sum+" is not a Numerology name");
return;
}

}
else {
System.out.println(str1+" is an invalid name");
}
}
}

23.Find Odd number of Studentpackage sda;


import java.util.*;
public class OddCombine {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the set of students:");
int no=sc.nextInt();
int count=0;
if(no>0) {
int arr[]=new int[no];
for(int i=0;i<no;i++) {
arr[i]=sc.nextInt();
if(arr[i]<0) {

System.out.println(arr[i]+" Invalid roll


number");
return;
}
}
for(int i=0;i<no;i++) {
if(arr[i]%2!=0) {
System.out.print(arr[i]);
}else {
count++;
}
}
if(count==no) {
System.out.println(no+" numbers are not odd");
}
}else {
System.out.println(no+" ia an invalid size");
}
}

24.Customer Offer

package sda;
import java.util.*;
public class OfferCustomer {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Invalid string");
int no=sc.nextInt();
//sc.nextLine();
String str[]=new String[no];
// String str1[]=new
if(no>3) {
System.out.println("Customer count is too low");
return;
} if(no>0) {
System.out.println("Invalid input");
return;
}if(no<50){
System.out.println("Customer count is too high");
return;
}for(int i=0;i<3;i++) {
str[i]=sc.nextLine();
}
System.out.println("Enter plan id to be searched:");
String pid=sc.next();
for(int i=0;i<no;i++) {
String arr[]=str[i].split(":");
if(pid.equals(arr[1])){
System.out.println(arr[3]+" "+arr[2]);

}
}

}
}

25.Prime Number
package sda;
/*import java.util.*;
public class PrimeNo {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int no1=sc.nextInt();
int no2=sc.nextInt();
//int f=0;
if(no1<0 || no2<0) {
System.out.println("Negative integer can not be
prime");
}else if(no1>no2) {
System.out.println("Invalid input");
}else if (no1==0 && no2==1) {
System.out.println("There are no prime number in the
range 0 to 1");
}
else {
for(int i=no1;i<=no2;i++) {
int f=0;
for(int j=1;j<=i;j++) {
if(i%j==0) {
f++;
}
}if(f==2) {
System.out.println(i);
}
}

}
sc.close();
}

}*/
import java.util.*;
public class PrimeNo {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int a=sc.nextInt();
int b=sc.nextInt();
boolean flag=false;
if(a>b)
{
System.out.println("Invalid Input");
return;
}
else if(a<0 || b<0)
{
System.out.println("Negative integers cannot be
prime");
return;
}
else if( a<=b && a>0 && b>0)
{
for(int i=a;i<=b;i++)
{
int count=0;
for(int j=1;j<=i;j++)
{
if(i%j==0)
count++;
}
if(count==2)
{
System.out.print(i+" ");
flag=true;
}
}
}
if(flag==false)
{
System.out.println("There are no prime numbers in the
range "+a+" to "+b);
return;
}
}
}

26.Product od prime number

package sda;

import java.util.*;
public class PrimeProduct {
public static void main(String args[]) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter no of element in array");
int no=sc.nextInt();
if(no>0) {
System.out.println("Array element");
int pd=1,f=0,f1=0;
int arr[]=new int[no];
for(int i=0;i<no;i++) {
arr[i]=sc.nextInt();
if(arr[i]>0) {
for(int j=2;j<arr[i]/2;j++) {
if(arr[i]%j==0)
{
f1=1;
}
}if(f1==0) {
System.out.println(arr[i]);
pd=arr[i]*pd;
f++;
}

}else {
System.out.println(arr[i]+" Invalid array
element");
}
}if(f!=0) {
System.out.println(pd);
}else {
System.out.print("No element found in ");
for(int k=0;k<no;k++)
System.out.print(arr[k]);
}
}else {
System.out.println(no+ " Invalid array size");
}
}

private static void checkPrime(int i) {


// TODO Auto-generated method stub

27.Public Distrubution
package sda;
import java.util.*;
public class PublicDistrubution {
public static void main(String args[]) {
Scanner sc=new Scanner(System.in);
String str=sc.nextLine();
if(str.length()<2 || str.length()>5) {
System.out.println("invalid input");
return;
}
int amount,total=0;

if(str.matches("[ORWKS]+")) {
for(int i=0;i<str.length();i++) {
if(str.charAt(i)=='O') {
amount=12*2;
total=total+amount;
}else if(str.charAt(i)=='K') {
amount=18*2;
total=total+amount;
}else if(str.charAt(i)=='W') {
amount=22*2;
total=total+amount;
}else if(str.charAt(i)=='R') {
amount=15*2;
total=total+amount;
}else if(str.charAt(i)=='S') {
amount=21*2;
total=total+amount;
}

}
System.out.println(total);
}else {
System.out.println("Invalid input");
}
}
}

28.Reverse String
package sda;
import java.util.*;
public class ReserveString {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the string");
String str=sc.nextLine();
String str1[]=str.split(" ");
int len=str1.length;
String rev = "";
//System.out.println(len);
int f=0;
char ch=str1[0].toUpperCase().charAt(0);
if(len>=3 ) {
for(int i=0;i<len;i++)
if(str1[i].matches("[a-zA-Z]+")) {

if(ch==str1[i].toUpperCase().charAt(0)) {
f++;

}
}else {
System.out.println("Invalid word");
return;
}
if(f==len) {
String s1=str1[len-1];
int l1=s1.length();

for(int i=l1-1;i>=0;i--) {
rev=rev+s1.charAt(i);
}
System.out.println(rev+str1[0]);

}else {
String s1=str1[0];
for(int i=s1.length()-1;i>=0;i--) {
rev=rev+s1.charAt(i);
}
System.out.println(rev+str1[len-1]);
}

}else {
System.out.println("Invalid Sentence");

}
}
}
29.Reverse Prime number
package sda;
import java.util.*;
public class ReversePrime {
public static void main(String args[]) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number of values");
int no=sc.nextInt();
if(no>0) {
int c=0;
int arr[]=new int[no];
System.out.println("Enter the numbers");
for(int i=0;i<no;i++) {
arr[i]=sc.nextInt();
}
for(int i=0;i<no;i++) {
int f=0,f2=0;
//System.out.println(arr[i]);
if(arr[i]>9) {
for(int j=2;j<arr[i]/2;j++) {
if(arr[i]%j==0) {
f=1;
}
}if(f==0) {
//f1=1;
// System.out.println(arr[i]);
int sum=0;
int prime=arr[i];
while(prime!=0)
{
int rem=prime%10;
sum=rem+sum*10;
prime/=10;
}
//System.out.println(sum);
for(int k=2;k<sum/2;k++) {
if(sum%k==0) {
f2=1;
}
}if(f2==0) {
System.out.println(arr[i]);

}
}else {
c++;
}

}else {
System.out.println(arr[i]+" is not valid");
return;
}
}if(c==no) {
System.out.println(no+" is not contain any
reverse prime");
return;
}
}else {
System.out.println(no+" is not valid");
}
}
}

30.Reverse Palindrome
package sda;
import java.util.*;
public class RevPalin {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the string");
String str=sc.nextLine();
String str1[]=str.split(" ");
String rev[]=Arrays.copyOf(str1, str1.length);
for(int i=0;i<str1.length;i++) {
StringBuilder sb=new StringBuilder(rev[i]);
sb.reverse();
rev[i]=sb.toString();
System.out.print(rev[i]+" ");
}
for(int i=0;i<str1.length;i++)
if(rev[i].equals(str1[i]) && str1[i].length()>1) {
System.out.println(rev[i]);
}

31.
Same String
Input:Entertaiment
Substring: en
Output:2
package sda;
import java.util.*;

public class SameString {


public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the String");
String str=sc.nextLine();
System.out.println("Enter subString");
String sub_str1=sc.nextLine();
int count=0;
if(str.matches("[a-zA-Z]+")) {

for(int i=0;i<str.length()-1;i++) {
String str1=str.substring(i,i+sub_str1.length());
System.out.println(str1);
if(sub_str1.equals(str1)) {
count++;
}
}
if(count!=0) {
System.out.println(sub_str1+" found in given string is
"+count);

}
else {
System.out.println("No matching found");

}else {
System.out.println("Invalid string");

32.Print Second Last Number in Array

package sda;
import java.util.*;
public class SecondLast {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the no of element in array");
int n=sc.nextInt();
System.out.println("Enter the elements in array");
int a[]=new int[n];
for(int i=0;i<n;i++) {
a[i]=sc.nextInt();
}
Arrays.sort(a);
System.out.println(a[n-2]);

}
}

33.Secreate Code

package sda;
import java.util.*;
public class SecreateCode {
public static void main(String args[]) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the name of the child");
String str=sc.nextLine();
int len=str.length();
if(len>=4) {
if(str.matches("[a-zA-Z]+")) {
System.out.println("Enter the birthdate of the
child");
int no=sc.nextInt();
if(no>=1 && no<=31) {

System.out.println(str.substring(0,4)+"@"+no);
}else {
System.out.println("Secreat code can not be
genrated");
return;
}
}else {
System.out.println("Secreat code can not be
genrated");
return;
}
}else {
System.out.println("Secreat code can not be genrated");
return;
}
}
}

34.
Compare Sum and Product
Output:35,168

package sda;
import java.util.*;
public class SumCompareProduct {
public static void main(String args[]) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter no of size of First Arrya:");
int no1=sc.nextInt();
System.out.println("Enter no of size of second Arrya:");
int no2=sc.nextInt();
int arr[]=new int[no1];
int arr1[]=new int[no2];

int pa[]=new int[no1];


int sa[]=new int[no2];

int sum1=1,rem=0,sum2=0,count=0;
if(no1>0 && no2>0) {
if(no1==no2) {
System.out.println("enter the element in first
array");
for(int i=0;i<no1;i++ ) {
arr[i]=sc.nextInt();
}
for(int i=0;i<no1;i++) {
int a1[]=new int[no1];
a1[i]=arr[i];
while(a1[i]!=0) {
rem=a1[i]%10;
sum1=rem*sum1;
a1[i]=a1[i]/10;
}

pa[i]=sum1;
sum1=1;
System.out.println(pa[i]);
}
System.out.println("enter the element in second
arrays");
for(int j=0;j<no2;j++) {
arr1[j]=sc.nextInt();
}
for(int j=0;j<no2;j++) {
int a2[]=new int[no2];
a2[j]=arr1[j];

while(a2[j]!=0) {
rem=a2[j]%10;
sum2=rem+sum2;
//sa[j]=sum2;
a2[j]=a2[j]/10;
}

sa[j]=sum2;
sum2=0;
System.out.println(sa[j]);
}
for(int k=0;k<no1;k++) {
if(pa[k]==sa[k]) {

System.out.println(arr[k]+","+arr1[k]);
count++;
}

}if(count==0) {
System.out.println("No match Found");

}else {
System.out.println("Array size is
diffrent");
}

}else {
System.out.println("Invalid array size");
}
}

}
36.Toy shop

package sda;
import java.util.*;
public class ToyShop {
public static void main(String args[]) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number of months");
int month=sc.nextInt();
if(month>0) {
System.out.println("Enter the number of toys purchased
monthly");
int toys[]=new int[month];
for(int i=0;i<month;i++) {
toys[i]=sc.nextInt();
if(toys[i]<10) {
System.out.println(toys[i]+" is an invalid
number of toy");
return;
}
}
int max=toys[0];
for(int i=1;i<month;i++) {
if(max<=toys[i]) {
max=toys[i];
}
}
for(int i=0;i<month;i++) {
if(toys[i]==max) {
System.out.println("month "+(i+1));
}

}
}else {
System.out.println("Invalid month");
}

37.Unique Char string


Input:life is inherantely perfect
Output: life is ihrtly prfct
package sda;
import java.util.*;
public class UniqueCharString {
public static void main(String args[]) {
Scanner sc=new Scanner(System.in);
String str=sc.nextLine();
String word[]=str.split(" ");
if(str.matches("[a-zA-Z ]+")) {
for(int i=0;i<word.length;i++) {
String unique=word[i];
StringBuilder sb=new StringBuilder(unique);
for(int j=0;j<sb.length();j++) {
for(int k=j+1;k<sb.length();k++) {
if(sb.charAt(j)==sb.charAt(k)) {
sb.deleteCharAt(k);
sb.deleteCharAt(j);
}
}
}System.out.print(sb+" ");
}
}else {
System.out.println(str+" Invalid Sentence");
}
}
}
JAVA

1. LCM OF DAY INTERVAL/LUNCH TOGETHER/DINNER TOGETHER

INPUT: Enter the day interval of Tony : 4


Enter the day interval of Potts: 6

OUTPUT: Tony and Potts will have dinner together on 12th day.

import java.util.Scanner;
public class lcm {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the day interval of Sam:");
int n1 = sc.nextInt();
System.out.println("Enter the day interval of Riya:");
int n2 = sc.nextInt();
if(n1<=0 || n2<=0)
{
System.out.println("Given interval is not valid");
return;
}
int lcm;
lcm = (n1 > n2) ? n1 : n2;
while(true) {
if( lcm % n1 == 0 && lcm % n2 == 0 ) {
System.out.printf("Sam and Riya will have their dinner on day "+lcm);
break;
}
++lcm;
}
}
}

ALTERNATE METHOD

import java.util.Scanner;
public class Lunchlcm {
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the day interval of Tony");
int n1=sc.nextInt();
System.out.println("Enter the day interval of Potts");
int n2=sc.nextInt();
if(n1<=0 && n2<=0)
{
System.out.println("Given interval is not valid");
return;
}
int a=n1;
int b=n2;
while(n2>0)
{
if (n1 > n2)
{
n1 = n1 - n2;
} else
{
n2 = n2 - n1;
}
}
int gcd = n1;
int lcm = (a * b) / gcd;

System.out.println("Tony and Potts will have lunch together on " + lcm + " day");
}
}

*********************************************************************************************
*********************************************************************************************
**
2.SCORE OF REPEATING WORDS/ WORD REPETITION

INPUT: Enter the String: GOOD


Enter the sentence: GOOD FOOD GOOD LIFE

OUTPUT: Score is 2

import java.util.*;
class PrintMessage
{
public static void main (String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the string");
String s=sc.next();
int count=0;
int sum=2;
for(int i=0;i<s.length();i++)
{
if(Character.isDigit(s.charAt(i)) || Character.isLetter(s.charAt(i)) || s.charAt(i)==' ')
{
continue;
}
else
{
System.out.println(s+" is not valid String");
return;
}
}
System.out.println("Enter the sentence");
sc.nextLine();
String sentence=sc.nextLine();
String[] w=sentence.split(" ");
for(int i=0;i<w.length;i++)
{
if(w[i].equalsIgnoreCase(s))
{
count++;
if(count>2)
{
sum=sum*2;
}
}
}
if(count>2)
{
System.out.println("Score is "+sum);
}
else
{
System.out.println("Score is"+count);
}
}
}

*ALTERNATE METHOD

import java.util.Scanner;
public class CountWords {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String word, sentence;ed
int count = 0;
System.out.println("Enter a word:");
word = in.nextLine();
System.out.println("Enter a sentence");
sentence = in.nextLine();

if (!(word.matches("[a-z]+"))) {
System.out.println("Invalid Input");
return;
}
String words[] = sentence.toLowerCase().split(" ");
for (int i = 0; i < words.length; i++) {
if (word.equals(words[i])) {
count++;
}
}
System.out.println("Score is:" + ((int) Math.pow(2, count - 1)));
}
}
*********************************************************************************************
*********************************************************************************************
***

3. BATTERY CAPACITY

INPUT: Enter battery capacity :1230


Enter charging current value: 400

OUTPUT: 3.69 Hours

import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter battery capacity:");
double capacity = sc.nextDouble();
if(!(capacity>=1000 && capacity<=10000)) {
System.out.println("Invalid battery capacity");
return;
}
System.out.println("Enter charging current value:");
double current = sc.nextDouble();
if(!(current>=300 && current<=2100)) {
System.out.println("Invalid output current");
return;
}
double time=0.0f;
time = (capacity/current)*1.2;
System.out.println(String.format("%.2f",time)+" Hours");
}

*********************************************************************************************
*********************************************************************************************
***
4.STUDENTS WHOSE ROLLNO ARE ODD

INPUT: Entr the set of students :5


Enter the roll number :1
3
4
5
6

OUTPUT: 135

import java.util.*;
public class Main
{
public static void main(String[] args) {
System.out.println("Enter the set of students");
Scanner s=new Scanner(System.in);
int setn=s.nextInt();
if(setn<=0)
{
System.out.println(setn+" is an invalid size");
return;
}
System.out.println("Enter the roll number");
int[] rolls=new int[setn];
int oddflag=0;
for(int i=0;i<setn;i++)
{
rolls[i]=s.nextInt();
if(rolls[i]<0)
{
System.out.println(rolls[i]+" is an invalid roll number");
return;
}
if(rolls[i]%2!=0)
{
oddflag=1;
}
}
if(oddflag==0)
{
System.out.println("The "+setn+" numbers are not odd");
return;
}
String str="";
for(int i=0;i<setn;i++)
{
if(rolls[i]%2!=0)
{
str=str+rolls[i];
}
}
for(int n=0;n<str.length();n++)
{
System.out.println(str.charAt(n)+" ");
}
}
}
*********************************************************************************************
*********************************************************************************************
**

5.CALCULATING BILL AMOUNT

INPUT : Enter your name : Sam


Enter the time duration: 13
List of payment options
1)Visa card
2)Rupay card
3)Master card
Choose an option : 2

OUTPUT: Dear Sam your bill amount is 1294.80

import java.util.*;
public class Main
{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter your name");
String s=sc.nextLine();double sal=0;double disc=0;
for(int i=0;i<s.length();++i)
{
if(!Character.isLetter(s.charAt(i)))
{
System.out.println("Invalid Name");
return;
}
}
System.out.println("Enter the time duration");
int n=sc.nextInt();int n1;
if(n<=0 || n>24)
{
System.out.println("Invalid duration");
return;
}
System.out.println("List of payment options");
System.out.println("1)Visa card");
System.out.println("2)Rupay card");
System.out.println("3)Master card");
System.out.println("Chosse an option");
while(true)
{
n1=sc.nextInt();
if(n1<0||n1>3)
{
System.out.println("Try again");
}
else
{
break;
}
}
if( n1==1)
{
if(n>=5)
{
sal=120*n;
disc=(sal*0.25);
sal=sal-disc;
}
else
{
sal=n*120;
}
}
if(n1==2)
{
if(n>=5)
{
sal=120*n;
disc=(sal*0.17);
sal=(120*n)-disc;
}
else
{
sal=n*120;
}
}
if(n1==3)
{
sal=n*120;
}
System.out.print("Dear "+s+" your bill amount is ");
System.out.printf("%.2f", sal);
}
}

*********************************************************************************************
*********************************************************************************************
***
6.ODD POSITION CHAR WILL BE IN UPPERCASE & EVEN WILL BE LOWERCASE-

INPUT : school

OUTPUT : sChOol

import java.util.Scanner;
public class UPLC{
public static void main(String []args){
Scanner sc = new Scanner(System.in);
String str = sc.next();
int strlen = str.length();
for(int i = 0 ; i < str.length(); i++){
char ch = str.charAt(i);
if(!(ch >= 'a' && ch <='z' || ch >= 'A' && ch <='Z' )){
System.out.println(str+ " is an invalid input");
return;
}
}

if(strlen >= 5 && strlen <= 20){


StringBuffer updateString = new StringBuffer();
char[] charArr = str.toCharArray();
for(int i = 0 ; i < charArr.length; i++){
char ch = charArr[i];
if(i % 2 != 0){
ch = Character.toUpperCase(ch);
}
updateString.append(ch);
}
System.out.println(updateString.toString());
}
else {
System.out.println(str+ " is an invalid Length");
}
}
}

*********************************************************************************************
*********************************************************************************************
****
7) RATING SCORE

INPUT: ENTER JESSON SCORE


1
2
3
4
8
ENTER JAMES SCORE
0
2
6
5
6

OUTPUT: JESSON SCORE : 2


JAMES SCORE : 2

import java.util.Scanner;
public class Ratingscore {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter Jesson Score");
int[] a1 = new int[5];
int[] a2 = new int[5];
int f = 0;
int t = 0;
int sum = 0;
int sum1 = 0;
for (int i = 0; i < 5; i++) {
a1[i] = sc.nextInt();
if (a1[i] < 0) {
f = 1;
t = a1[i];
break;
}
}
if (f == 1) {
System.out.println(t + " is invalid");
} else {
System.out.println("Enter James Score");
for (int j = 0; j < 5; j++) {
a2[j] = sc.nextInt();
if (a2[j] < 0) {
f = 1;
t = a2[j];
break;
}
}
if (f == 1) {
System.out.println(t + " is invalid");
} else {
for (int k = 0; k < 5; k++) {
if (a1[k] > a2[k]) {
sum++;
}
if (a1[k] < a2[k]) {
sum1++;
}
}
System.out.println("Jesson Score");
System.out.println(sum);
System.out.println("James Score");
System.out.println(sum1);
}
}
}
}

**ALTERNATE METHOD:

import java.util.Scanner;
public class minmax {
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
int jesson=0,james=0,c=0;
int a[]=new int[5];
int b[]=new int[5];
System.out.println("Enter Jesson Score");
for(int i=0;i<a.length;i++)
{
a[i]=sc.nextInt();
if(a[i]<0)
{
System.out.println("Invalid");
Runtime.getRuntime().halt(0);
}
}
System.out.println("Enter James Score");
for(int i=0;i<b.length;i++)
{
b[i]=sc.nextInt();
if(b[i]<0)
{
System.out.println("Invalid");
Runtime.getRuntime().halt(0);
}
}
if(a.length==b.length)
{
for(int i=0;i<a.length;i++)
{
if(a[i]>b[i])
{
jesson++;
}
else if(a[i]<b[i])
{
james++;
}
else if(a[i]==b[i])
{
c++;
}
}
System.out.println("Jesson Score: "+jesson);
System.out.println("James Score: "+james);
}
else{
System.out.println("Length not same");
}
}
}

*********************************************************************************************
*******************************************************************************

8.COUNT OF UPPERCASE AND COUNT OF LOWERCASE & OUTPUT WILL BE IN THE FORM OF (UP-LC
)

INPUT : HosTEL

OUTPUT: 4-2=2

import java.util.Scanner;

public class ContNext {


public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the string");
String str=sc.nextLine();
int uc=0,lc=0;
if(str.matches("[A-Za-z ]+")&&str.length()<10) {
for(int i=0;i<str.length();i++)
if(Character.isUpperCase(str.charAt(i))) {
uc++;
}
else if(Character.isLowerCase(str.charAt(i))){
lc++;
}
System.out.println(uc-lc);
}
}
}
*********************************************************************************************
*******************************************************************************
9) PRODUCT of COUNT of UPPERcase and LOWERcase letters

INPUT: ABsdEr

OUTPUT: 6 (3*3)

import java.util.Scanner;
public class minmax {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the String");
String s = sc.nextLine();
int upper = 0;
int lower = 0;
int i;
if (s.matches("[a-zA-Z]+")) {
for (i = 0; i < s.length(); i++) {
char c = s.charAt(i);
if (c >= 'A' && c <= 'Z') {
upper++;
}
if (c >= 'a' && c <= 'z') {
lower++;
}
}
System.out.println(upper * lower);
}
else
{
System.out.println("Invalid String");
}

}
}

*********************************************************************************************
******************************************************************************
10.Count of UPPERcase and LOWERcase and their difference

Enter the String: ColLEgE


Count of uppercase is : 4
Count of lowercase is : 3
Hence the ans is : 1

import java.util.Scanner;
public class MyClass {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the String ");
String str = sc.next();
int strlen = str.length();
for(int i =0; i < str.length() ; i++){
char ch = str.charAt(i);
if(!(ch >='a' && ch <= 'z' || ch >= 'A' && ch <= 'Z')){
System.out.println(str + " is an invalid String");
return;
}
}

if(strlen > 0 && strlen <= 10){


int upper = 0, lower = 0, ans = 0;

for(int i = 0; i < str.length(); i++)


{
char ch = str.charAt(i);
if (ch >= 'A' && ch <= 'Z')
upper++;
else if(ch >= 'a' && ch <= 'z')
lower++;
}
ans = upper - lower;
System.out.println("count of uppercase is :"+ upper);
System.out.println("count of lowercase is :"+ lower);
System.out.println("Hence the ans is :"+ ans);
}
else {
System.out.println(str + " is an invalid String");
}
}
}
*********************************************************************************************
*******************************************************************************
11.PUBLIC DISTRIBUTION

INPUT : OKR

OUTPUT : 90

import java.util.*;
public class Main
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
String str = in.nextLine();
int l=str.length();
if(l>5 || l<2)
{
System.out.println("Invalid Input");
}
else
{
int sum=0,flag=0;
for(int i=0;i<l;i++)
{
char c=str.charAt(i);
if(c=='O')
{
sum=sum+24;
}
else if(c=='K')
{
sum=sum+36;
}
else if(c=='S')
{
sum=sum+42;
}
else if(c=='R')
{
sum=sum+30;
}
else if(c=='W')
{
sum=sum+44;
}
else
{
flag=1;
}
}
if(flag==1)
{
System.out.println("Invalid Input");
}
else
{
System.out.println(sum);
}
}
}
}
*********************************************************************************************
******************************************************************************

12.LOTTERY TICKETS

INPUT: Enter the Starting range


23467
Enter the Ending range
23477

OUTPUT: 23469
23472

import java.util.*;
public class Main {
public static void main(String args[])
{
int i,c,n,sum,count;
sum=0;count=0;n=0;c=0;i=0;
Scanner sc = new Scanner(System.in);
System.out.println("Enter the Starting range");
int a = sc.nextInt();
String str = Integer.toString(a);
if(str.length()!=5)
{
System.out.println(str + " is an invalid input");
System.exit(0);
}

System.out.println("Enter the Ending range");


int b = sc.nextInt();
String str1 = Integer.toString(b);
if(str1.length()!=5)
{
System.out.println(str1 + "is an invalid input");
System.exit(0);
}

if(a>b)
{
System.out.println(a+" and "+b+" are invalid serial numbers");
System.exit(0);

}
for(i=a;i<=b;i++)
{
n=i;
while(n!=0)
{
c=n%10;
sum=sum+c;
n=n/10;
}
if((sum%3==0)&&((sum/3)%2==0))
{
System.out.println(i + " ");
count++;
}
sum=0;
}
if(count==0)
{
System.out.println("Eligible tickets are not available from "+a+" to "+b);
System.exit(0);
}
}
}

*********************************************************************************************
******************************************************************************
13.COFFEE STALL NUMEROLOGY

INPUT : Enter the Staff Name


Coffee Bar

OUTPUT : Coffee Bar satisfies the numerology logic

import java.util.*;
public class Main{
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the Staff Name");
String name = sc.nextLine();
int count=0;
for(int i=0;i<name.length();i++){
if(Character.isAlphabetic(name.charAt(i)) || name.charAt(i)==' '){
count++;
}
}
if(count==name.length()){
String str = name.replace(" ","");
int sum=0;
for(int i=0;i<str.length();i++){
sum += i;
}
if(sum%2==0){
System.out.println(name+" satisfies the numerology logic");
}else{
System.out.println(name+" does not satisfy the numerology logic");
}
}else{
System.out.println("Invalid Input");
}
}
}

*ALTERNATE METHOD USING -matches for same question

import java.util.*;
public class Main{
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the Staff Name");
String name = sc.nextLine();
if(name.matches("[a-zA-Z ]+")){
String str = name.replace(" ","");
int sum=0;
for(int i=0;i<str.length();i++){
sum += i;
}
if(sum%2==0){
System.out.println(name+" satisfies the numerology logic");
}else{
System.out.println(name+" does not satisfy the numerology logic");
}
}else{
System.out.println("Invalid Input");
}
}
}

*ALTERNATE METHOD

import java.util.Scanner;
public class CoffeeHouse {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the Stall Name");
String name = sc.nextLine();
if (name.matches("^[A-Za-z ]*$")) {
int sum = 0;
String fName = name.replaceAll(" ", "");
for (int i = 0; i < fName.length(); i++)
sum = sum + i;
if (sum % 2 == 0) {
System.out.println(name + " satisfies the numerology logic");
} else {
System.out.println(name + " not satisfies the numerology logic");
}
} else
System.out.println("Invalid Input");
}
}

*********************************************************************************************
******************************************************************************

14.ANAGRAM OR TWO WORDS OF SAME LETTER

INPUT : cat
act

OUTPUT: Same

import java.util.Arrays;
import java.util.Scanner;
public class minmax {
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter sentence 1");
String s1=sc.next();
s1=s1.toLowerCase();
System.out.println("Enter sentence 2");
String s2=sc.next();
s2=s2.toLowerCase();
if(s1.length()!=s2.length())
{
System.out.println("Invalid");
}
if(s1.matches("^[a-zA-Z]*")){
char c1[] = s1.toLowerCase().toCharArray();
char c2[] = s2.toLowerCase().toCharArray();
Arrays.sort(c1);
Arrays.sort(c2);
if (Arrays.equals(c1, c2)) {
System.out.println(s1 + " and " + s2 + " contain the same characters");
} else {
System.out.println(s1 + " and " + s2 + " contain the different characters");
}
}
else
{
System.out.println("Invalid");
}
}
}

ALTERNATE METHOD:

import java.util.*;
public class Main{
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
String first=sc.next();
String secound=sc.next();
String word1=Main.checker(first);
String word2=Main.checker(secound);
if(word1.equals(word2)){
System.out.println("Same");
}else{
System.out.println("Different");
}
}
public static String checker(String word){
char arr[]=word.toCharArray();
Arrays.sort(arr);
int index=0;
for(int i=0;i<arr.length;i++){
int j;
for(j=0;j<i;j++){
if(arr[j]==arr[i]){
break;
}
}
if(i==j){
arr[index++]=arr[i];
}
}
char arr1[]=Arrays.copyOf(arr,index);
String newword= new String(arr1);
return newword;
}
}

ALTERNATE METHOD

import java.util.*;
public class arraysquare {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int f1=0,f2=0;
String s1=sc.nextLine();
char c1[]=s1.toCharArray();
String s2=sc.nextLine();
char c2[]=s2.toCharArray();
for(int i=0;i<c1.length;i++)
{
f1=0;
for(int j=0;j<c2.length;j++)
{
if(c1[i]==c2[j])
{
f1=1;
break;
}
}
if(f1==0)
{
break;
}
}
for(int i=0;i<c2.length;i++)
{
f2=0;
for(int j=0;j<c1.length;j++)
{
if(c2[i]==c1[j])
{
f2=1;
break;
}
}
if(f2==0)
{
break;
}
}
if(f1==1 && f2==1)
{
System.out.println("Same Char");
}
else{
System.out.println("Different char");
}
}
}

*********************************************************************************************
*****************************************************************************
15.SUMMATION OF EVEN NUMBERS IN THE ARRAY

INPUT : Enter array size


4
Enter array elements in 1st array
2
4
6
8
Enter array elements in 2nd array
1
2
5
2

OTPUT: 0
6
0
10

import java.util.*;
public class Main
{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter array size");
int n=sc.nextInt();
if(n>=10 || n<1)
{
System.out.println(n+" is an invalid input");
Runtime.getRuntime().halt(0);
}
int arr1[]=new int[n];
int arr2[]=new int[n];
int result[]=new int[n];
System.out.println("Enter array elements in 1st array");
for(int i=0;i<n;i++)
{
arr1[i]=sc.nextInt();
}
System.out.println("Enter array elements in 2nd array");
for(int i=0;i<n;i++)
{
arr2[i]=sc.nextInt();
}
//PROGRAM LOGIC
int count=0;
for(int i=0;i<n;i++)
{
if((arr1[i]%2==0 || arr1[i]==0) && (arr2[i]%2==0 || arr2[i]==0))
{
result[i]=arr1[i]+arr2[i];
count++;
}
else
{
result[i]=0;
}
}
if(count==0)
{
System.out.println("No even number is present in an Array");
}
for(int i=0;i<n;i++)
{
System.out.println(result[i]);
}
}
}

*********************************************************************************************
******************************************************************************
16.RUNNERS COMPETITION

INPUT :Enter the number of runners


5

Enter the runner details


Robert,9.38
Richard,9.35
Christiano,9.35
Williams,9.36
Vinix,9.35

OUTPUT: Richard
Christiano
Vinix

import java.util.*;
public class Main{
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
sc.useDelimiter("\n");
System.out.println("Enter the number of runners");
int n = sc.nextInt();
if(n<=0 || n>10){
System.out.println(n+" is an invalid number of runners");
Runtime.getRuntime().halt(0);
}
String temp = "";
String name[] = new String[n];
float time[] = new float[n];
System.out.println("Enter the runner details");
for(int i=0;i<n;i++){
temp = sc.next();
String temparr[] = temp.split(",");
name[i] = temparr[0];
time[i] = Float.parseFloat(temparr[1]);
if(time[i]>12 || time[i]<8){
System.out.println(time[i]+" is an invalid input");
Runtime.getRuntime().halt(0);
}
}
int maxcount = 0;
float maxrep = 0;
for(int i=0;i<n;i++){
int count = 0;
for(int j=i+1;j<n;j++){
if(time[i]==time[j]){
count++;
}
}
if(count>=maxcount){
maxcount = count;
maxrep = time[i];
}
}
if(maxcount==n){
System.out.println(n+" runners have same timing");
}
else if(maxcount==0){
System.out.println("No runners with same time.");
}
else{
for(int i=0;i<n;i++){
if(maxrep == time[i]){
System.out.println(name[i]);
}
}
}
}
}
*********************************************************************************************
******************************************************************************

17.REEDME

INPUT : Enter the customer name


Abi
Enter the category
History
Enter the quantity of books ordered
2900

OUTPUT : Total cost is 334080.0


import java.util.*;
public class Main{
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the customer name");
String name = sc.nextLine();
System.out.println("Enter the category");
String category = sc.nextLine();
category = category.toLowerCase();

if(!category.equals("adventure") && !category.equals("comics") && !category.equals("history") && !categ


ory.equals("thriller")){
System.out.println(category+" is invalid category");
Runtime.getRuntime().halt(0);
}
System.out.println("Enter the quantity of books ordered");
int quantity = sc.nextInt();
if(quantity <= 0){
System.out.println(quantity+" is an invalid quantity");
Runtime.getRuntime().halt(0);
}
int discount = 0;
int price = 0;
if(category.equals("adventure")){
price = 150;
if(quantity>=1700)
discount = 5;
}
else if(category.equals("comics")){
price = 230;
if(quantity>=1950)
discount = 5;
}
else if(category.equals("history")){
price = 120;
if(quantity>=2600)
discount = 4;
}
else if(category.equals("thriller") && quantity>=1700){
price = 190;
if(quantity>=6300)
discount = 3;
}
float totalcost = (price*quantity) - (price*quantity*discount/100);
System.out.println("Total cost is "+totalcost);
}
}

*********************************************************************************************
******************************************************************************
18. HARSHAD NUMBER (Sum of digit completely divide that number)

For example: 18= 1+8=9 and in 18/9 remainder is 0


INPUT: Enter array size: 5
Enter array elements : 18 14 12 24 13

OUTPUT: 18 12 24

import java.util.Scanner;
public class Harshad {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the number of values");
int n = sc.nextInt();
int i;
System.out.println("Enter the numbers");
int[] a = new int[n];
if (n > 0)
{
int flag = 0;
int k = 0;
for (i = 0; i < n; i++)
{
k = sc.nextInt();
if (k > 9)
a[i] = k;
else
{
flag = 1;
break;
}
}
if (flag != 1)
{
int c = 0;
for (i = 0; i < n; i++)
{
int x = a[i];
int sum = 0;
do {
int r = x % 10;
sum = sum + r;
x = x / 10;
}
while (x != 0);
if (a[i] % sum == 0)
{
c++;
System.out.println(a[i]);
}
}
if (c == 0)
System.out.println("The " + n + " values are not harshad number");
}
else
System.out.println("Provided " + k + " is not valid");
} else
System.out.println(n + " is an invalid input");
}
}

ALTERNATE METHOD:

import java.util.Scanner;
class Main
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number of values");
int n=sc.nextInt();
System.out.println("Enter the numbers");
int a[]=new int[n];
if(n>0)
{
int flag=0;
int k=0;
for(int i=0;i<n;i++)
{
k=sc.nextInt();
if(k>9) a[i]=k; else
{
flag=1;
break;
}
}
if(flag!=1)
{
int c=0;
for(int i=0;i<n;i++)
{
int x=a[i];
int sum=0;
do
{
int r=x%10; sum=sum+r; x=x/10;
}while(x!=0);
if(a[i]%sum==0)
{ c++;
System.out.println(a[i]);
}
}
if(c==0)
System.out.println("The "+n+" values are not harshad number");
}else
System.out.println("Provided "+k+" is not valid");
}else
System.out.println(n+" is an invalid input");
}
}
*********************************************************************************************
*********************************************************************************************
*******
19.VIDEO GAME (PS1)

INPUT : Enter the amount


18000
Enter the Video Game Player Type
PS4

OUTPUT: You can buy PS4

public class PS {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the amount");
int amount = sc.nextInt();
if (amount >= 3000) {
System.out.println("Enter the Video Game Player Type");
String type = sc.next();
if (type.matches("[P][S][1-5]")) {
if (type.equals("PS1")) {
if (amount >= 5000) {
System.out.println("You can buy PS1");
} else {
System.out.println("You need more money to buy a PS1");
}
} else if (type.equals("PS2")) {
if (amount >= 7800) {
System.out.println("You can buy PS2");
} else {
System.out.println("You need more money to buy a PS2");
}
} else if (type.equals("PS3")) {
if (amount >= 9500) {
System.out.println("You can buy PS3");
} else {
System.out.println("You need more money to buy a PS3");
}
} else if (type.equals("PS4")) {
if (amount >= 12000) {
System.out.println("You can buy PS4");
} else {
System.out.println("You need more money to buy a PS4");
}
} else if (type.equals("PS5")) {
if (amount >= 15000) {
System.out.println("You can buy PS5");
} else {
System.out.println("You need more money to buy a PS5");
}
}
} else {
System.out.println(type + " is Invalid Type");
}
} else {
System.out.println(amount + " is too less");
}
}
}

*********************************************************************************************
*********************************************************************************************
****
20.ALTERNATE SUM DIFFERENCE

INPUT :Enter number


6
Enter values
12
13
6
8
9
7
(((( logic: (12-7=a
13-9=b
6-8=c
a+b+c=ans)))))

OUTPUT 2
3
4
5
5-2=3
4-3=1
So 3+1= 4
*/

import java.util.*;
public class AltDiff {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int sum=0;
int n=sc.nextInt();
int a[]=new int[n];
for(int i=0;i<n;i++)
{
a[i]=sc.nextInt();
}
for(int i=0;i<n/2;i++)
{
sum+=Math.abs(a[i]-a[n-i-1]);
}
System.out.println(sum);
}
}
*********************************************************************************************
*********************************************************************************************
*****
21.CHARACTER ADD

INPUT : Enter : 3
Enter the sentences:
ks436
Agh73
7222

OUTPUT: 222
240
0

import java.util.*;
public class arraysquare{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int sum=0;
System.out.println("Enter:");
int n=sc.nextInt();
if(n<=0)
{
System.out.println("The number of sentences "+n+" is invalid");
return;
}
System.out.println("Enter the sentences:");
String str[]=new String[n];
for(int i=0;i<n;i++)
{
str[i]=sc.next();
}
for(int i=0;i<str.length;i++)
{
String s=str[i].replaceAll("[0-9]","");
for(int j=0;j<s.length();j++)
{
char c=s.charAt(j);
int ascii=c;
sum+=ascii;
}
System.out.println(sum);
sum=0;
}

}
}

*********************************************************************************************
*********************************************************************************************
******
22.MIDDLE LETTER/Reverse first half of the string if string length is ODD

Input:
if length of string is even, the reverse the string:
Ex: Food
Output:
dooF

Input:
If length of the string is odd,then find the middle char and then ,reverse the string till mid char and print remain char
acters as it is.
Ex: Samsung
Output:
maSsung

package FinalAss;
import java.util.*;
public class MidLett {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
String str=sc.nextLine();//rahul
int len=str.length();
if(len%2==0)
{
StringBuilder sb=new StringBuilder(str);
sb.reverse();
System.out.println(sb.toString());
}
else if(len%2!=0)
{
System.out.println("Length of string is " +len);
int mid=len/2;
mid++;
System.out.println("Substring of string is "+mid);
String substr=str.substring(0,mid-1);
String remainSub=str.substring(mid-1,len);
StringBuilder sb=new StringBuilder(substr);
sb.reverse();
System.out.println(sb.toString()+remainSub);

}
}
}

ALTERNATE METHOD:::

import java.util.Scanner;
import java.util.regex.Pattern;
public class minmax {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
String str=sc.nextLine();//rahul
if(!Pattern.matches("[A-Za-z]+",str))
{
System.out.println(str+" is not a valid string");
return;
}
else if(str.length()<2)
{
System.out.println("Size of string "+str.length()+" is too small");
return;
}
int len=str.length();
if(len%2==0)
{
StringBuilder sb=new StringBuilder(str);
sb.reverse();
System.out.println(sb.toString());
}
else if(len%2!=0)
{
int mid=len/2;
String substr=str.substring(0,mid);
String remainSub=str.substring(mid,len);
StringBuilder sb=new StringBuilder(substr);
sb.reverse();
System.out.println(sb.toString()+remainSub);

}
}
}

*********************************************************************************************
*********************************************************************************************
*****

23 .ONLINE SHOPPING

input:
enter the product
laptop
Actual price
45000
exchange?
yes
bill amount:
27000.00

import java.util.*;
public class arraysquare {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the Product:");
String prod=sc.nextLine();
int ed=0,pd=0;
if(prod.equals("Mobile"))
{
ed=15;
pd=15;
}
else if(prod.equals("Laptop"))
{
ed=20;
pd=20;
}
else if(prod.equals("Headset"))
{
ed=0;
pd=10;
}
else if(prod.equals("Charger"))
{
ed=0;
pd=5;
}
else{
System.out.println("Not available");
return;
}
System.out.println("Enter the actual Price: ");
int price=sc.nextInt();
if(price<100)
{
System.out.println("Invalid Price");
return;
}
System.out.println("Do u want to Exchange?");
String exc=sc.next();
if(exc.equals("Yes") || exc.equals("yes"))
{
double ap=price-(price*pd)/100;
double ev=(price*ed)/100;
double total=ap-ev;
System.out.printf("Total=%.2f",total);
}
else if(exc.equals("No") || exc.equals("no"))
{
double total=price-(price*pd)/100;
System.out.printf("Total=%.2f",total);
}
else
{
System.out.println("Invalid Option");
}
}
}

*********************************************************************************************
*********************************************************************************************
*****
24 .OPERATOR FOUND

input:
45
23

22
output
45-23=22

import java.util.*;
public class arraysquare {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter n1 and n2:");
int n1=sc.nextInt();
if(n1>0)
{
int n2=sc.nextInt();
if(n2>0)
{
System.out.println("Enter n3:");
int n3=sc.nextInt();
if(n3>0)
{
if(n1+n2==n3)
{
System.out.println(n1+"+"+n2+"="+n3);
}
else if(n1-n2==n3)
{
System.out.println(n1+"-"+n2+"="+n3);
}
else if(n1*n2==n3)
{
System.out.println(n1+"*"+n2+"="+n3);
}
else if(n1/n2==n3)
{
System.out.println(n1+"/"+n2+"="+n3);
}
else
{
System.out.println(n3+" is an invalid answer");
}
}
else{
System.out.println("Invalid");
}
}
else{
System.out.println("Invalid");
}
}
else{
System.out.println("Invalid");
}

}
}

*********************************************************************************************
*********************************************************************************************
****

25 .PRODUCT EQUAL SUM

INPUT : Enter the array size


4
Enter the elements of the first array
12
35
56
34
Enter the elements of the second array
261
195
112
813
OUTPUT: 35,195
34,813

import java.util.*;
public class arraysquare
{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the array size");
int n=sc.nextInt();
if(n<=0)
{
System.out.println("Invalid array size");
return;
}
int a[]=new int[n];
System.out.println("Enter the elements of the first array");
for(int i=0;i<n;i++)
{
a[i]=sc.nextInt();
}
System.out.println("Enter the elements of the second array");
int b[]=new int[n];
for(int i=0;i<n;i++)
{
b[i]=sc.nextInt();
}
int x[]=new int[n];
int y[]=new int[n];
for(int i=0;i<n;i++)
{
int c=a[i];
int prod=1;
while(c!=0)
{
prod*=(c%10);
c/=10;
}
x[i]=prod;
prod=0;
}
for(int i=0;i<n;i++)
{
int s=b[i];
int sum=0;
while(s!=0)
{
sum+=(s%10);
s/=10;
}
y[i]=sum;
sum=0;
}
for(int i=0;i<n;i++)
{
if(x[i]==y[i])
{
System.out.println(a[i]+","+b[i]);
}
}
}
}

*********************************************************************************************
*********************************************************************************************
*

26.UNIQUE CHAR

input:
LIfe is inherently risky

output:
life is ihrtly risky

package FinalAss;
import java.util.*;
public class nonuniquetwo {
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
String sentence = sc.nextLine();
String[] words = sentence.split(" ");
for(String word : words)
{
System.out.print(getUnique(word) + " ");
}
sc.close();
}
public static String getUnique(String str)
{
StringBuffer sb = new StringBuffer();
for(int i = 0; i<str.length(); i++)
{
if(countFrequency(str.charAt(i), str) == 1)
{
sb.append(str.charAt(i));
}
}
String result = sb.toString();
return result;
}
public static int countFrequency(char c, String str)
{
int count = 0 ;
for(int i = 0; i<str.length(); i++)
{
if(str.charAt(i) == c)
{
count++;
}
}
return count;
}
}

*********************************************************************************************
*********************************************************************************************
*
27. BOX SIZE

INPUT : Enter the box size


6
Enter the numbers
5
55
3
59
42
8
OUTPUT: 32 is even its a valid box

import java.util.Scanner;
public class minmax {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the box size");
int a=sc.nextInt();
if(a<=0)
{
System.out.println(a+" is an invalid box size");
return;
}
int b[]=new int[a];
int c=0,sum=0,temp=0;
System.out.println("Enter the numbers");
for(int i=0;i<a;i++)
{
b[i]=sc.nextInt();
if(b[i]<=0)
{
System.out.println(b[i]+" is an invalid input");
return;
}
}
for(int i=0;i<a;i++)
{
c=b[i]%10;
sum+=c;
c=0;
}
if(sum%2==0)
{
System.out.println(sum+" is even its a valid box");
return;
}
else
{
System.out.println(sum+" is odd its an invalid box");
return;
}

}
}
*********************************************************************************************
*********************************************************************************************
***

28. ORDER IDENTIFICATION:(check where elements are in ascending order)

INPUT : Enter the array size : 5


Enter the elements: 32
44
55
66
77

OUTPUT : 32 44 55 66 77 are in ascending order

import java.util.Arrays;
import java.util.Scanner;

public class orderidentification {


public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the array size");
int a=sc.nextInt();
if(a<2 || a>10)
{
System.out.println(a+" is not a valid array size");
return;
}
int b[]=new int[a];
int count=0;
System.out.println("Enter the elements");
for(int i=0;i<a;i++)
{
b[i]=sc.nextInt();
}
int d[]= Arrays.copyOf(b,b.length);
Arrays.sort(d);

if(Arrays.equals(b,d))
{
count++;
}
if(count>0)
{
for(int i=0;i<b.length;i++)
{
System.out.print(b[i]+" ");

}
System.out.print("are in ascending order");
return;
}
else
{
for(int i=0;i<a;i++)
{
System.out.print(b[i]+" ");
}
System.out.print("are not in ascending order");
return;
}
}
}
*********************************************************************************************
**************************************************************
29) DATE ,MONTH AND YEAR

INPUT:13081995

OUTPUT: date: 13
month: 08
year: 1998

import java.util.Scanner;
public class minmax {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
String str=sc.nextLine();
int n=str.length();
for(int i=0;i<str.length() ;i++)
{
if(!(str.charAt(i)>='0' && str.charAt(i)<='9'))
{
System.out.println("Invalid input");
return;
}
if(n!=8)
{
System.out.println("Enter valid date");
return;
}
}
String date=str.substring(0,2);
String mon=str.substring(2,4);
String year=str.substring(4,8);

System.out.println("date:"+date);
System.out.println("Month:"+mon);
System.out.print("Year:"+year);

}
}

*********************************************************************************************
*********************************************************************************************
*
30) MEGA MART CUSTOMER IDENTIFICATION(String and SUBSTRING)

import java.util.*;
public class arraysquare{
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the customer id");
String cid = sc.next();
String shop = cid.substring(0,4);
//System.out.println("shop");
if(!shop.equals("Mega")){
System.out.println("Invalid Shop Name");
Runtime.getRuntime().halt(0);
}
String type = cid.substring(4,cid.length()-3);
//System.out.println(type);
if(!type.equals("Silver") && !type.equals("Gold") && !type.equals("Platinum")){
System.out.println("Invalid Customer Type");
Runtime.getRuntime().halt(0);
}
int mid = Integer.parseInt(cid.substring(cid.length()-3,cid.length()));
//System.out.println(mid);
if(mid<=99 || mid>=1000){
System.out.println("Invalid Member id");
Runtime.getRuntime().halt(0);
}
System.out.println("Welcome Mega Mart "+type+" Customer");

}
}

*********************************************************************************************
***********************************
31) .MALE AND FEMALE COUNT

INPUT: MmFMff

OUTPUT: 3 MALE
3 FEMALE

import java.util.Scanner;
import java.util.regex.*;
public class minmax {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
String s=sc.nextLine();
int count1=0;
int count2=0;
if(Pattern.matches("[MmFf ]+",s)){
for (int i = 0; i < s.length(); i++) {
if (s.charAt(i) == 'M' || s.charAt(i) == 'm') {
count1++;
} else if (s.charAt(i) == 'F' || s.charAt(i) == 'f') {
count2++;
}
}
System.out.println(count1 + " Male");
System.out.println(count2 + " Female");
}
else
{
System.out.println("Invalid Input");
}
}
}
*********************************************************************************************
*********************************************************************************************
***
32. RAINFALL

INPUT: Enter the length of the roof in meters: 4


Enter the breadth of the roof in meters: 3
Enter the rainfall level: 3

OUTPUT: 360.00 Litres

import java.util.Scanner;
public class minmax {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
System.out.println("Enter the length of the roof in meters");
double l=sc.nextDouble();
if(l<=0)
{
System.out.println("Invalid Length");
return;
}
System.out.println("Enter the breadth of the roof in meters");
double b=sc.nextDouble();
if(b<=0)
{
System.out.println("Invalid breadth");
return;
}
System.out.println("Enter the rainfall level");
double r=sc.nextDouble();
if(r<=0)
{
System.out.println("Invalid rainfall");
return;
}
double h;
h=(l*b) *(r*10);
System.out.println(String.format("%.2f",h)+"Litres");
}
}

*********************************************************************************************
*********
33) NUMEROLOGY NAME CHECKING

import java.util.*;
import java.util.regex.Pattern;

public class arraysquare{


public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the name");
String a=sc.next();
if(!Pattern.matches("[A-Za-z]+",a))
{
System.out.println(a+" is an Invalid name");
return;
}
int sum=0;
char b[]=a.toCharArray();
for(int i=0;i<b.length;i++)
{
if(b[i]=='A'||b[i]=='a')
{
sum+=1;
}
else if(b[i]=='B'||b[i]=='b')
{
sum+=2;
}
else if(b[i]=='C'||b[i]=='c')
{
sum+=3;
}
else if(b[i]=='D'||b[i]=='d')
{
sum+=4;
}
else if(b[i]=='E'||b[i]=='e')
{
sum+=5;
}
else if(b[i]=='F'||b[i]=='f')
{
sum+=6;
}
else if(b[i]=='G'||b[i]=='g')
{
sum+=7;
}
else if(b[i]=='H'||b[i]=='h')
{
sum+=8;
}
else if(b[i]=='I'||b[i]=='i')
{
sum+=9;
}
else if(b[i]=='J'||b[i]=='j')
{
sum+=10;
}
else if(b[i]=='K'||b[i]=='k')
{
sum+=11;
}
else if(b[i]=='L'||b[i]=='l')
{
sum+=12;
}
else if(b[i]=='M'||b[i]=='m')
{
sum+=13;
}
if(b[i]=='N'||b[i]=='n')
{
sum+=14;
}
if(b[i]=='O'||b[i]=='o')
{
sum+=15;
}
if(b[i]=='P'||b[i]=='p')
{
sum+=16;
}
if(b[i]=='Q'||b[i]=='q')
{
sum+=17;
}
if(b[i]=='R'||b[i]=='r')
{
sum+=18;
}
if(b[i]=='S'||b[i]=='s')
{
sum+=19;
}
if(b[i]=='T'||b[i]=='t')
{
sum+=20;
}
if(b[i]=='U'||b[i]=='u')
{
sum+=21;
}
if(b[i]=='V'||b[i]=='v')
{
sum+=22;
}
if(b[i]=='W'||b[i]=='w')
{
sum+=23;
}
if(b[i]=='X'||b[i]=='x')
{
sum+=24;
}
if(b[i]=='Y'||b[i]=='y')
{
sum+=25;
}
if(b[i]=='Z'||b[i]=='z')
{
sum+=26;
}
}
System.out.println(sum);
if(sum%3==0 && sum%2==0)
{
System.out.println(a+" is a numerology name");
}
else
{
System.out.println(a+" is not a numerology name");
}
}
}

*******************************************************************************

34)OMR

import java.util.Scanner;
public class arraysquare{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int i;
System.out.println("Enter the No of questions");
int a=sc.nextInt();
if(a<0)
{
System.out.println("Invalid Number");
return;
}
int count=0;
int mark=0;
char b[]=new char[a];
System.out.println("Enter the answer key");
for (i=0;i<a;i++) {
b[i] = sc.next().charAt(0);

if ((b[i] >= 'a' && b[i] <= 'e')||(b[i] > 'E')) {


System.out.println("Invalid Answers");
return;
}
}
char c[]=new char[a];
System.out.println("Enter the student answers");
for (i=0;i<a;i++)
{
c[i]=sc.next().charAt(0);
if ((c[i] >= 'a' && c[i] <= 'e')||(b[i]>'E')) {
System.out.println("Invalid Answers");
return;
}
}

for(i=0;i<a;i++)
{
if(b[i]==c[i])
{
count++;
}
}
if(count>0)
System.out.println("Correct answers are "+count);
mark=(count*100)/a;
if(count<1)
System.out.println("All answers are wrong");
System.out.println("Mark is "+mark);

}
}
JAVA END
*********************************************************************************************
*********************************************************************************************
********

RDBMS IMPORTANT CODES(NOT TESTED)

1.)Select concat(concat(customer_name,'has taken a


policy on'),date_of_policy) as Enrollment_details
from customer JOIN Policy using (customer_id)
order by customer_name,date_of_policy;

2.)select plolicy_id,policy_name,rate_of_interest, bonus_percentage


from policy
where minimum_primeium_amount = 1200
order by policy_d;

3.)select fine_range,fine_amount
CASE
When fine_range=L1
then 5+fine_amount
when fine_range=L2
then 10+fine_amount
When fine_range=M1
then 15+fine_amount
when fine_range=M2
then 20+fine_amount
When fine_range=H1
then 25+fine_amount
when fine_range=H2
then 30+fine_amount
END as NEW_FINE_AMOUNT

4.)select leave_type,allocated_days
CASE
when leave_type='CASUAL'
then allocated_days+2
when leave_type='SICK'
then allocated_days+5
when leave_type='MATERNITY'
then allocated_days+90
when leave_type='MARRIAGE'
then allocated_days+3
when leave_type='STUDY'
then allocated_days-2
END as NEW_ALLOCATED_TYPES
from table_name
order by leave_type;

5.) select emp_id,emp_name,department_id,department_name


from Department JOIN Employee using (department_id)
JOIN Leave+Avail_details using (Emp_id)
JOIN Leave using (Leave_type)
where Allocated_days = 0
order by emp_id;
*********************************************************************************************
**

1.) Account Info - "HDVL002"


select account_type, count(account_id) as TOTAL_ACCOUNTS
from Acount_Info where IFC_Code = 'HDVL002'
group by account_type order by account_type;

2.)select customer_id,customer_name,phone_no,order_date
from Customer_info JOIN Orders using (customer_id)
where order_amount > 500
order by customer_id,order_date;

3.) select distinct customer_id,customer_name,phone_no,loan_amount as


total_loan_amount from customers JOIN loans_taken using
(customer_id)
order by customer_id;

4.) select distinct boat_id,seat_capacity,count(ride_id) as ride_count


From Boat_details JOIN Ride_details using (boat_id)
order by boat_id;

5.) select customer_id,customer_name,contact_no,mail_id


from Coustomer_details where Gender = 'M'
order by customer_id;
6.) select customer_name,total_amount_paid
from Customer_master JOIN Booking_details using (customer_id)
where total_amount_paid < (select max(total_amount_paid) from booking_details
where total_amount_paid < (select max(total_amount_paid) from booking_details))
order by customer_name;

7.) select book_code,book_title, author,rack_num


from book_details where category = 'JAVA'
order by book_code;

8.) select customer_name,policy_enrollment as Enrollment_details


from customer JOIN policy_enrolmment using (customer_id)
order by customer_name,date_of_enrollment;

9.)DECODE QUESTION
select fine_range, fine_amount,
decode(fine_range, 'L1',fine_amount+5,
'L2',fine_amount+10,
'M1',fine_amount+10,
'M2',fine_amount+10,
'H1',fine_amount+10,
'H2',fine_amount+10)new_fine_amount
from fine_details;

10.)select customer_name||" has taken policy on"|| date_of_enrollment as


enrollment_details form customer
join policyenrollent using (customer_id)
order by customr_name,date_of_enrollment;

11.)select policy_id,policy_name,rate_of_interest,bonus_percentage
from policy where mimum_premium_amount = 1200
order by policy_id;

12.) select customer_id,customer_name, street,phone_no,email


from Customers JOIN loan_taken using (customer_id)
where loan_amount > = 500000 and loan_amonunt <1500000
order by customer_id;

13.)select distinct boat_id, boat_name,boat_type


from boat_details JOIN ride_details using (boat_id)
where DOT LIKE '%-AUG-%' and Shift = 'evening'
order by boat_id;

14.) select policy_id,policy_name,rate_of_interest


from policy where miniimum_ppremium_amount < 3000 AND bonus_percent > 85
order by policy_id;

RDBMS ANSWERS

1.1)Write a query to display boat_type and number of boats running under each type. Give an alias name as 'NO_OF
_BOATS'.
Note: Boat_type can be 'DELUXE' or 'SUPER DELUXE'.

select boat_type,count(Boat_id) as NO_OF_BOATS


from boat_details
group by Boat_type;

1.2) select boat_name,boat_type from boat_details


where seat_capacity between 100 and 200
order by boat_name desc;

2.1)select vehicle_type,count(vehicle_id)
from vehicle_details
group by vehicle_type
order by vehicle_type;

2.2)select driver_id,driver_name,phone_no,Driver_rating
from driver_details where driver_rating between 3 and 5
order by driver_rating desc;

3.1)select coursename from course


c join registration r on
c.courseid=r.courseid
having count(studid)>=2
group by coursename
order by coursename;

3.2)select s.studid,sum(fees) as TOTALFEES


from student s join registration r
on s.studid=r.studid join course c
on r.courseid=c.courseid
group by s.studid
order by s.studid;

3.3)select studid,count(CourseID) as NOOFCOURSES


from registration
group by Studid
order by NOOFCOURSES desc,Studid;

3.4)select student.stuid,firstname from student


join registration on registration.stuid=student.stuid
where lower(to_char(doj,'MON'))='jan';

3.5)select courseid,coursename from


course where duration between 10 and 15;

3.6)select courseid,registration.stuid from registration


join student on registration.stuid=student.stuid
where lower(to_char(doj,'MON'))=lower(to_char(dob,'MON'));
1

1. Gender determination ……………………………………….. 2


2. LCM lunch/dinner together …………………………………2-3
3. Product equals sum ………………………………………………3-5
4. Count of occurences of substring in a given string… ..5-6
5. Fun count……………………………………………………………….. 6
6. Speed Estimation…………………………………………………… 7
7. Prime number………………………………………………………. 7-8
8. Theatre seat ………………………………………………………… 8-9
9. Customer details …………………………………………………. 10-11
10. Team win/loose ………………………………………………… 11
11. Holiday fun ……………………………………………………….. 11-12
12. Reverse-prime …………………………………………………… 12-13
13. Even number addition in arrays…………………………. 14
14. Groceries bill …………………………………………………….. 15
15. Cake order …………………………………………………………. 16-17
2

Gender Determination :

import java.util.*;
public class Main {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
String s=sc.next();
int count=0,count1=0;
if(!(s.matches("[mfMF]+")))
{
System.out.println("Invalid Input");
return;
}
else
for(int i=0;i<s.length();i++)
{
if(s.charAt(i)=='m' ||s.charAt(i)=='M')
count++;
else
count1++;
}
System.out.println(count+" "+"Male");
System.out.println(count1+" "+"Female");
}}
LCM OF DAY INTERVAL/LUNCH/DINNER TOGETHER :

import java.util.*;
public class Main {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
System.out.println("Enter the day interval of person 1:");
int a=sc.nextInt();
System.out.println("Enter the day interval of person 2:");
int b=sc.nextInt();
if(a<=0 || b<=0)
{
System.out.println("Given interval is not valid");
return;
3

}
int lcm;
lcm=(a>b)?a:b;
while(true){
if(lcm%a==0 && lcm%b==0){
System.out.println("person 1 and person 2 will have
their dinner on day "+lcm);
break;
}
lcm++;
}
}}

PRODUCT EQUALS SUM

import java.util.*;

public class Main{

public static void main(String args[]){

Scanner sc=new Scanner(System.in);

System.out.println("Enter the array size:");

int n=sc.nextInt();

int count=0;

if(n<1 || n>10){

System.out.print("Invalid array size");

System.exit(0);

else{

int[] a1=new int[n];

int[] a2=new int[n];

System.out.println("Enter the elements of the first array");


4

for(int i=0;i<n;i++){

int b=sc.nextInt();

if(b>10 && b<999)

a1[i]=b;

else{

System.out.print("Invalid input");

System.exit(0);

}}

System.out.println("Enter the elements of the second


array");

for(int i=0;i<n;i++){

int c=sc.nextInt();

if(c>10 && c<999)

a2[i]=c;

else{

System.out.print("Invalid input");

System.exit(0);

}}

for(int i=0;i<n;i++){

int mul=1,r=0,x=a1[i];

while(x>0){

r=x%10;

mul*=r;
5

x=x/10;

for(int j=0;j<n;j++){

int sum=0,p=0,y=a2[j];

while(y>0){

p=y%10;

sum+=p;

y=y/10;

if(mul==sum){

count++;

System.out.print(a1[i]+","+a2[j]);

System.out.println(" ");

}}}

if(count==0){

System.out.print("No pair found");

System.exit(0);

}}}}

Count of Occurrences of Substring in a String

import java.util.*;
public class Main {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
String s1=sc.next();
String s2=sc.next();
int index=0;
6

int count=0;
while((index=s1.indexOf(s2,index))!=-1){
index=index+1;
count+=1;
}
System.out.println(count);
}
}

Fun Count

import java.util.*;
public class Main {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
if(n<=0){
System.out.println("Invalid Input");
return;
}
if(n>15){
System.out.println("Number exceeds the limit");
return;
}
Map<String,Integer> a=new HashMap<>();
for(int i=0;i<n;i++){
String s=sc.next().toLowerCase();
if(a.containsKey(s))
a.put(s,1+a.get(s));
else
a.put(s,1);
}
Map<String,Integer> tm=new TreeMap<>(a);
for(Map.Entry<String,Integer>data:tm.entrySet()){
System.out.println(data.getKey()+"= "+data.getValue());
}
}
}
7

SPEED ESTIMATION :
import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
System.out.println("Enter the distance in kilometer");
int km=sc.nextInt();
if(km<0) {
System.out.println("Invalid Input");
return;
}
System.out.println("Enter the time to reach in hours");
int hours=sc.nextInt();
if(hours<0){
System.out.println("Invalid Input");
return;
}
int speed=km/hours;
if(speed<30){
System.out.println("You drive a car at normal speed");
return;
}
int inc=speed-30;
System.out.println("You want to increase a speed "+inc+"
km/hr from a normal speed");
}}

Prime Number

import java.util.Scanner;

public class Main{

public static void main(String[] args){

Scanner sc=new Scanner(System.in);

int a = sc.nextInt();

int b = sc.nextInt();

int count=0;
8

if(a<0 || b<0){

System.out.println("Negative integers cannot be prime");

return;

for(int i=a;i<=b;i++){

count = 0;

for(int j=2;j<=i;j++){

if(i % j == 0)

count = count+1;

if(count == 1)

System.out.print(i+" ");

if(count!=1)

System.out.println("There are no prime numbers in the range


"+a+" to "+b);

Theatre

import java.util.*;
public class Main {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
String s=sc.next();
if(s.length()==6)
{
9

String a=s.substring(0,1);
if(a.matches("[NEWS]+"))
{
String b=s.substring(1,2);
if(b.matches("[ABCDE]+"))
{
String c=s.substring(2,3);
if(c.matches("[1-4]+"))
{
String d=s.substring(3,6);
int num=Integer.parseInt(d);
if(num>0 && num<500)
{
System.out.println("Name "+a);
System.out.println("Block "+b);
System.out.println("Floor number "+c);
System.out.println("Seat number
"+num);
}
else
System.out.println("Invalid Seat number");
}
else
System.out.println("Invalid Floor number");
}
else
System.out.println("Invalid Block");
}
else
System.out.println("Invalid Name");
}
else
System.out.println("Invalid size");
}}
10

Customer details

import java.util.Scanner;

public class Main{


public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number of customers:");
int cust=sc.nextInt();
if(cust<0)
{
System.out.println("Invalid Input");
return;
}
if(cust<3)
{
System.out.println("Customer count is too low");
return;
}
if(cust>50)
{
System.out.println("Customer count is too high");
return;
}
System.out.println("Enter the customer details:");
String[] arr=new String[cust];
for (int i=0;i<cust;i++)
{
arr[i]=sc.next();
}
System.out.println("Enter the plan to be searched");
String plan=sc.next();
for (int i=0;i<cust;i++)
{
String[] custdetails=arr[i].split(":");
if(plan.equals(custdetails[1]))
{
System.out.println(custdetails[2]+" "+custdetails[3]);
11

}
}
}
}

Team Win/Loose
import java.util.*;
public class Main {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
String str=sc.next();
int count=0;
if(str.length()<3) {
System.out.println("Invalid input");
return;
}
if(str.matches("[htHT]+")) {
String s=str.toLowerCase();
for(int i=0;i<s.length()-2;i++){
if(s.charAt(i)!=s.charAt(i+1) &&
s.charAt(i)==s.charAt(i+2))
count++;
}
if(count==s.length()-2)
System.out.println("Team will win");
else
System.out.println("Team may loose");
}
else {
System.out.println("Invalid Input");
return;
}
}}

Holiday Fun

import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
12

int sum=0,sum1=0;
int n=sc.nextInt();
if(n>0){
String[] a=new String[n];
for(int i=0;i<n;i++){
a[i]=sc.next();
}
for(int i=0;i<n;i++){
int len=a[i].length();
if(len%2==0)
{
for(int j=1;j<len;j++){

sum=sum+Integer.parseInt(String.valueOf(a[i].charAt(j)));
j++;
}}
else
{
for(int k=0;k<len;k++){

sum1=sum1+Integer.parseInt(String.valueOf(a[i].charAt(k)));
k++;
}}
}
System.out.println(sum+sum1);
}
else
System.out.println("Invalid size");
}}

Reverse Prime

import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
int count=0,c=0,f=0,r=0,prime=0;
int n=sc.nextInt();
if(n>0) {
int[] a=new int[n];
13

for(int i=0;i<n;i++) {
int num=sc.nextInt();
if(num>9)
a[i]=num;
else {
System.out.println("Provided "+num+" is not valid");
return;
}}
for(int i=0;i<n;i++) {
count=0;
for(int j=2;j<a[i];j++)
{
if(a[i]%j==0)
count++;
}
if(count==0) {
prime++;
f=a[i];
r=0;
while(a[i]!=0) {
r=r*10;
r=r+a[i]%10;
a[i] =a[i]/10;
}
for(int k=2;k<r;k++) {
if(r%k==0)
c++;
}
if(c==0)
System.out.println(f);
}}}
else {
System.out.println(n+" is less than a limit");
return;
}
if(prime==0)
System.out.println(n+" values are not prime numbers");
}}
14

Even number addition in arrays

import java.util.*;
public class Main {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
int count=0;
System.out.println("Enter the size of array ");
int n=sc.nextInt();
int[] sum=new int[n];
if(n>=1 && n<=10)
{
int[] a=new int[n];
System.out.println("Enter the elements of the first array ");
for(int i=0;i<n;i++)
a[i]=sc.nextInt();
int[] b=new int[n];
System.out.println("Enter the elements of second array ");
for(int i=0;i<n;i++)
b[i]=sc.nextInt();
for(int i=0;i<n;i++)
{
if(a[i]%2==0 && b[i]%2==0)
{
count++;
sum[i]=a[i]+b[i];
}
else
sum[i]=0;
}
if(count==0)
System.out.println("There are no even elements");
else
for(int result:sum)
System.out.println(result);
}
else
System.out.println("Invalid");
}}
15

Groceries Bill

import java.util.*;
public class Main {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
String s=sc.next();
int a=0,b=0,c=0,d=0,count=0;
if(s.matches("[ORWKorwk]+")) {
for(int i=0;i<s.length();i++) {
for(int j=0;j<s.length();j++) {
if(s.charAt(i)==s.charAt(j))
count++;
}}
if(count==s.length()) {
for(int k=0;k<s.length();k++)
{
if(s.charAt(k)=='O')
a=4*20;
else if(s.charAt(k)=='R')
b=3*5;
else if(s.charAt(k)=='W')
c=2*10;
else
d=5*15;
}
System.out.println(a+b+c+d);
}
else
System.out.println("Duplicates are not allowed");
}
else
System.out.println("Invalid");
}}
16

Cake Order

import java.util.*;

public class CakeProgram {

public static void main(String[] args) {


Scanner sc=new Scanner(System.in);
System.out.println("Enter the Customer instructions: ");
String cd=sc.nextLine();

if (cd.matches("[a-zA-Z0-9]*")) {
String w=cd.substring(0, 4);

if(!w.matches("[0-9]*")){
System.out.println("Invalid weight");
return;
}

float wg=Integer.parseInt(w);
if (wg>999) {
float fwg=wg/1000;
double weight= (Math.round(fwg * 100.0) / 100.0);

String o=cd.substring(cd.length()-3);
if (!o.matches("[0-9]*")) {
System.out.println("Invalid order number");
return;
}
int on=Integer.parseInt(o);
if(on>99) {
String flavour=cd.substring(4,cd.length()-3);

System.out.println("Weight of Cake in Kgs:


"+String.format("%.2f", weight));
System.out.println("Order No: "+on);
System.out.println("Flavour Name: "+flavour);

double cakePrice=450*weight;
17

System.out.printf("Cake Price is: %.2f


Rupees",cakePrice);
}
else {
System.out.println("Invalid order number");
}
}
else {
System.out.println("Invalid weight");
}
}
else {
System.out.println("Invalid Input");
}
}

}
1. Maze Runner

Amy wants to create a game. Her game had 2 players, according to the movement of the players
points will vary. According to the direction, characters will be assigned. Only four characters can
be assigned, L-left, R-right, B-bonus, F-foul, if the direction is left add 50 points, if the direction is
right subtract 50 points, if there is a bonus double the points or if there is foul reduce the total
points to its half.

So according to the string calculate the points and compare it among the players. At the end of
the game, if the player1 have scored more points than player 2, print “Player 1 Wins” or else print
“Player 2 Wins”. At the end of the game, if both have secured equal points print “Draw Nobody
Wins” .Initial points are awarded to the players and the score calculation is done with that initial
points.

Note: Characters L,R,B,F are valid. If there is any other character present in the string print
“Invalid Input”. Number of characters must be same between the players or else print “Invalid
Input”. Initial points can be between 1000 to 5000 or else print “Invalid Input”.

Sample input 1:

Enter the points of the first player:

1200

Enter the string:

LLRRF

Enter the points of the second player:

1000

Enter the string:

RRLFB

Sample output 1:

Player 2 Wins

Explanation: (1200+50+50-50-50)/2=600, ((1000-50-50+50)/2)*2=950, Thus player 2 Wins the


game.

Sample input 2:

Enter the points of the first player:

7000

Sample output 2:
Invalid Input

Sample input 3:

Enter the points of the first player:

1900

Enter the string:

LLRKF

Sample output 3:

Invalid Input

2. Holiday Trip:

Ana wants to book a ticket to Mumbai. She want to call few of her friends with her. Help her to
calculate the ticket amount by which they can go for their trip within their budget. There are
different flights like Air India, Spice Jet, Go Air, IndiGo.

According to the flight name travel cost varies. Each flight will have divisions like Economy class,
Travel class and Business class. Cost of the ticket will vary for each class. If the passenger pays
the ticket cost using card there is a percentage of reduction in the cost of the ticket. If the number
of passengers are more than 5, 10% discount is given and if it is more than 10, 15% discount is
given for IndiGo and Spice Jet alone from the final amount.

Air India:

Travel class:3200

Economy class:6950

Business class:10,340

Card Payment:10.5%

Spice Jet:

Travel class:3450

Economy class:7945

Business class:9500

Card Payment:7.5%
Go Air:

Travel class:3300

Economy class:7250

Business class:9890

Card Payment:9.5%

IndiGo:

Travel class:3490

Economy class:7560

Business class:9990

Card Payment:8.5%

Sample input 1:

Enter the flight name:

Air India

Enter the class:

Travel class

Enter the number of seats:

Card Payment:

Sample output 1:

22912

Explanation: (3200*8)-(3200*8*(10.5/100))

3. Tell the time


John has planned to automate the process of sending the next notification to his colleagues for
the day. He knows the time, when the first notification has to be sent and the time interval, after
which the next notifications has to be sent.

Write a java program to get two input from the user, the first input will be a string holding time in
24 hours format(HH:MM) and the second input will be an integer that holds the time interval in
minutes (MM). And display the time at which the next notifications has to be sent for that day. If
the time to send the next notification exceeds for the day display “Notification cannot be sent for
the day”.

If the range of hours (HH) in time should be between 00 and 23 (both inclusive) and the range of
minutes (MM) should be between 00 and 59(both inclusive). If not display “Input is not valid” and
terminate the program.

Assumption: Day starts 00:00 (HH:MM) and ends at 23:59(HH:MM)

Adhere to the sample input and output.

Sample Input 1:

22:00

05

Sample Output 1:

22:05

Sample Input 2:

23:45

20

Sample Output 2:

Notification cannot be sent for the day

Sample Input 3:

25:50

Sample Output 3:

Input is not valid


Sample Input 4:

23:50

60

Sample Output 4:

Input is not valid

4.Fuel Quantity Calculation

David fueled his vehicle in a fuel station. He remembered that he asked the filling person to fill
the fuel for certain amount in rupees. But he don’t know the quantity of fuel in liters. Help him to
calculate the fuel in Liters from amount in Rupees by getting the rate per liter as input.

Note that, both the inputs must be a positive number. Otherwise print “Invalid Input”

Output must have only two decimal places.

The result should be in two decimal places. To get two decimal places refer the below-mentioned
print statement :

float cost=1105.00f;

System.out.printf(“%.2f”,cost);

Sample Input 1:

Enter the amount in Rupees:

1000

Fuel rate per liter:

89.35

Sample Output 1:

11.19 Liters

Sample Input 2:

Enter the amount in Rupees:

-1000

Sample Output 2:
Invalid Input

5.Vowel Pair Removal

Nancy was playing with her daughter, they were playing with words. That day her daughter was
taught vowels in her class. So they were playing with vowels. Nancy asked her daughter to
remove the vowels from the word, if they are present in continuous pattern alone.

Note: The word should not have more than 8 letters if so print “Word length exceeds the limit”
and less than 3 letters, if so print “Word length is too short”. Word cannot have numbers or
special character, if so print “Invalid Input”.

Sample input 1:

Enter the word:

solution

Sample output 1:

solutn

Sample input 2:

Enter the word:

hi

Sample output 2:

Word length is too short

Sample input 3:

Enter the word:

absurdity

Sample output 3:

Word length exceeds the limit

Sample input 4:
Enter the word:

ba&ery

Sample output 4:

Invalid Input

6. MAC Validation

A MAC (Media Access Control) address is the unique identifier that is assigned by the
manufacturer to a piece of network hardware.

A MAC address consists of six sets of two characters, each separated by a colon.
00:1B:44:11:3A:B7 is an example of a MAC address. Each character should hold only
hexadecimal values ( 0 to 9 and A to F).

Write a java program to check the given string is a valid MAC address or not, if the given string is
valid then display “Valid MAC address” else display “Invalid MAC address”.

Note: If the given string contains less than six sets of two characters, each separated by a colon
display “String is too short”. If the given string contains more than six sets of two characters,
each separated by a colon display “String is too long”. If the given string contains any other
symbols other than colon (:) display “Invalid Input”.

Assumption: Each set in the given string will have only two characters and alphabets in the
Upper case.

Sample Input 1:

56:41:AB:5A:A5:60

Sample Output 1:

Valid MAC address

Sample Input 2:

62:55:VB:ZZ:A5:S6

Sample Output 2:

Invalid MAC address

Sample Input 3:
62:55:CB

Sample Output 3:

String is too short

Sample Input 4:

62:55:CB:62:55:CB:23

Sample Output 4:

String is too long

Sample Input 5:

62&55*CB%62:55@CB

Sample Output 5:

Invalid Input

7. Unique products

John runs a department store and has multiple items in it. Each items will have a 3 digit bar code
ID to identify the items. He wants to segregate items which has Unique number in the 3 digit bar
code ID. A Unique number is a positive integer with no duplicate digits. For example 135, 214 are
all unique numbers whereas 311, 300 are not.Help him by your java skills.

Note: The number of items should be between the range 5 and 20 (both inclusive) else display
“Invalid item count” and terminate the program. The bar code ID of each item should be only a 3
digit number, if not display “Invalid bar code ID” and terminate the program. If there is no bar
code ID with Unique number then display “There are no item with Unique number in the bar code
ID”.

Adhere to the Sample Input and Output

Sample Input 1:

Enter the number of items:

10

Enter the bar code ID for 10 items:

111

222

123
125

654

354

844

141

200

201

Sample Output 1:

123

125

654

354

201

There are 5 items with Unique number in the bar code ID

Sample Input 2:

Enter the number of items:

Enter the bar code ID for 5 items:

111

222

110

333

100

Sample Output 2:

There are no item with Unique number in the bar code ID


Sample Input 3:

Enter the number of items:

25

Sample Output 3:

Invalid item count

Sample Input 4:

Enter the number of items:

Enter the bar code ID for 5 items:

111

1000

Sample Output 4:

Invalid bar code ID

8.Toggle word

Reema is an English teacher, she teaches upper case and lower case letters to her students.
She wanted to test her students, whether her students have understood the concept. She wanted
to conduct it as a game. If the students perform well, she would like to present gifts. Help her to
conduct the game using Java program.

If a word is given, each alternate character in the word should be converted in to upper case ie,
In the given word, the first character should start with upper case followed by each alternate
character as upper case.

For example:

If the input is string, then the output should be StRiNg

Note: Word should not have more than 8 letters if so print “Word length exceeds the limit” and
less than 3 letters, if so print “Word length is too short”. Word cannot have numbers or special
character, if so print “Invalid Input”.

Sample input 1:

Enter the word:

aviation
Sample output 1:

AvIaTiOn

Sample input 2:

Enter the word:

it

Sample output 2:

Word length is too short

Sample input 3:

Enter the word:

abundance

Sample output 3:

Word length exceeds the limit

Sample input 4:

Enter the word:

m@ngo

Sample output 4:

Invalid Input

9.Prime Number Multiples

Write a program to find the product of the prime digits in the given input number.

If the input number is negative or greater than 32767 Print it as "Invalid Input".

If the input number does not have any prime digits,print it as “No Prime Digit Found”

If the input number has single prime digit,then print that prime digit.

Please note that '1' and '0' are neither prime nor composite.
Input and Output Format:

Input consists of an integer.

Output consists of an integer.

Refer sample output for formatting specifications.

Sample Input 1:

2017

Sample Output 1:

14

Explanation:

Number '2' and '7' are the prime digits in the given input and number '1' and '0' are neither prime
nor composite hence the product of prime digits will results in 14(2*7).

Sample Input 2:

483

Sample Output 2:

Sample Input 3:

-67

Sample Output 3:

Invalid Input

10.Estimated Parcel Delivery Time

James needs to find the estimated delivery time of his parcel. Get the distance(in Km) between
the seller and buyer as input. Consider that the delivery vehicle can travel with 10 meter per
second as average speed. Calculate the delivery time and display the output in Minutes (rounded
value) as given in sample data.

Formula: T = D / S

where, S = speed (in meters/second)


D = distance (in meters)

T = time (in seconds)

(1Km=1000m, 1min=60sec).

Note that, the input should be in Kilometers and output should be in minutes.

Write a Java program to calculate the above. Input must be a positive number, otherwise print
“Invalid Input”.

The result should be in two decimal places. To get two decimal places refer the below-mentioned
print statement :

float cost=1105.00f;

System.out.printf(“%.2f”,cost);

Sample Input 1:

Enter the distance in Km:

100

Sample Output 1:

Estimated Time:

166.67 Minutes

Sample Input 2:

Enter the distance in Km:

-50

Sample Output 2:

Invalid Input
1. Maze Runner

Solution:

import java.util.*;

class Main

public static void main(String args[])

Scanner sc=new Scanner(System.in);

System.out.println("Enter the points of the first player:");

int points1=sc.nextInt();

if(points1<1000 || points1>5000)

System.out.println("Invalid Input");

else

System.out.println("Enter the string:");

String s1=sc.next();

int flag=0;

char ch1[]=s1.toCharArray();

for(char c:ch1)

if(c=='L' || c=='R' || c=='F' ||c=='B')

//System.out.println(c);

flag++;

}
}

if(flag!=s1.length())

System.out.println("Invalid Input");

else

System.out.println("Enter the points of the second player:");

int points2=sc.nextInt();

if(points2<1000 || points2>5000)

System.out.println("Invalid Input");

else

System.out.println("Enter the string:");

String s2=sc.next();

if(s1.length()!=s2.length())

System.out.println("Invalid Input");

else

int flag1=0;

char ch2[]=s2.toCharArray();

for(char c:ch2)

{
if(c=='L' ||c=='R' || c=='F' ||c=='B')

flag1++;

if(flag1!=s2.length())

System.out.println("Invalid Input");

else

for(char c:ch1)

if(c=='L')

points1+=50;

if(c=='R')

points1-=50;

if(c=='B')

points1*=2;

if(c=='F')

{
points1/=2;

for(char c:ch2)

if(c=='L')

points2+=50;

if(c=='R')

points2-=50;

if(c=='B')

points2*=2;

if(c=='F')

points2/=2;

if(points1>points2)

System.out.println("Player 1 Wins");

else if(points1<points2)
{

System.out.println("Player 2 Wins");

else

System.out.println("Draw Nobody Wins");

2. Holiday Trip:

Solution:

import java.util.*;

public class Main{

public static void main(String[] args){

Scanner sc=new Scanner(System.in);

Scanner sc1=new Scanner(System.in);

System.out.println("Enter the flight name:");

String fname=sc.nextLine();
System.out.println("Enter the class:");

String fclass=sc.nextLine();

System.out.println("Enter the number of seats:");

int no=sc.nextInt();

System.out.println("Card Payment:");

char pay=sc.next().charAt(0);

int cost=0;

switch(fname){

case "Air India":

// System.out.println("Hai1111");

switch(fclass){

case "Travel class":{

//System.out.println("Hai");

cost=3200;

break;

case "Economy class":{

cost=6950;

break;

case "Business class":{

cost=10340;

break;

}
}

break;

case "Spice Jet":

switch(fclass){

case "Travel class":{

if(no<=5){

cost=3450;

else if(no>5&&no<=10){

cost=(int)(3450*0.9);

else{

cost=(int)(3450*0.85);

break;

case "Economy class":{

if(no<=5){

cost=7945;

else if(no>5&&no<=10){

cost=(int)(7945*0.9);

else{

cost=(int)(7945*0.85);
}

break;

case "Business class":{

if(no<=5){

cost=9500;

else if(no>5&&no<=10){

cost=(int)(9500*0.9);

else{

cost=(int)(9500*0.85);

break;

break;

case "Go Air":

switch(fclass){

case "Travel class":{

cost=3300;

break;

case "Economy class":{


cost=7250;

break;

case "Business class":{

cost=9890;

break;

break;

case "IndiGo":{

switch(fclass){

case "Travel class":{

if(no<=5){

cost=3490;

else if(no>5&&no<=10){

cost=(int)(3490*0.9);

else{

cost=(int)(3490*0.85);

break;

case "Economy class":{

if(no<=5){
cost=7560;

else if(no>5&&no<=10){

cost=(int)(7560*0.9);

else{

cost=(int)(7560*0.85);

break;

case "Business class":{

if(no<=5){

cost=9990;

else if(no>5&&no<=10){

cost=(int)(9990*0.9);

else{

cost=(int)(9990*0.85);

break;

break;

int res=cost*no;
if(pay=='Y')

switch(fname){

case "Air India":

res=(int)(res*0.895);

break;

case "Spice Jet":

res=(int)(res*0.925);

break;

case "Go Air":

res=(int)(res*0.905);

break;

case "IndiGo":

res=(int)(res*0.915);

break;

System.out.println(res);
}

3. Tell the time

Solution:

import java.util.Scanner;

public class Main

public static void main(String args[])

Scanner sc=new Scanner(System.in);

//System.out.println("Enter the word:");

String s=sc.next();

String ch[]=s.split(":");

int m[]=new int[2];int count=0;

for(int i=0;i<2;i++)

int m1=Integer.valueOf(ch[i]);

m[i]=m1;

if(m[0]>=00 && m[0]<=23 && m[1]>=00 && m[1]<=59)

{ int n=sc.nextInt();

if(n<=59 && n>=0)


{

int k=m[1]+n;

if(k>59)

{ int l=m[0]+1; m[1]=k-60;

if(l>23)

System.out.println("Notification cannot be sent for the day");

else

{m[0]=l;

count++;}

else

{ m[1]=k;

count++; }

if(count!=0 && m[1]<=9)

System.out.println(m[0]+":0"+m[1]);

if(count!=0 && m[1]>9)

System.out.println(m[0]+":"+m[1]);

else

System.out.println("Input is not valid");

else

System.out.println("Input is not valid");

}
4.Fuel Quantity Calculation

Solution:

import java.util.*;

public class Main

public static void main(String[] args)

Scanner read=new Scanner(System.in);

System.out.println("Enter the amount in Rupees:");

int rs=read.nextInt();

if(rs<1)

System.out.println("Invalid Input");

else

System.out.println("Fuel rate per liter:");

float liter=read.nextFloat();

if(liter<0)

System.out.println("Invalid Input");

else

float petrol=rs/liter;

System.out.printf("%.2f Liters",petrol);

}
}

}}

5.Vowel Pair Removal

Solution:

import java.util.Scanner;

public class Main

public static void main(String args[])

Scanner sc=new Scanner(System.in);

System.out.println("Enter the word:");

String s=sc.next();int count=0;

if(s.length()>=3 && s.length()<=8)

for(int i=0;i<s.length();i++)

if(Character.isLetter(s.charAt(i)))

count++;

if(count==s.length())

for(int i=0;i<s.length();i++)

{ if(i<s.length())

if(((s.charAt(i)=='a')||(s.charAt(i)=='e')||(s.charAt(i)=='i')||(s.charAt(i)=='o')||(s.charAt(i)=='u')
)&&

((s.charAt(i+1)=='a')||(s.charAt(i+1)=='e')||(s.charAt(i+1)=='i')||(s.charAt(i+1)=='o')||(s.char
At(i+1)=='u')))
{i++;

continue;

else

System.out.print(s.charAt(i));

else

System.out.print(s.charAt(i));

//System.out.println(s);

else

System.out.println("Invalid Input");

if(s.length()>8)

System.out.println("Word length exceeds the limit");

if(s.length()<3)

System.out.println("Word length is too short");

6. MAC Validation

Solution:

import java.lang.*;

import java.util.*;

public class Main{


public static void main(String[] args){

Scanner sc=new Scanner(System.in);

String s=sc.nextLine();

int len=s.length();

int dc=0,cc=0,colonc=0,flag=0;

if(len==17){

char[] a=s.toCharArray();

for(char b:a){

if(Character.isLetter(b)){

if(b>=65&&b<=70)

cc++;

if(Character.isDigit(b)){

dc++;

if(b==':'){

colonc++;

if(!(Character.isLetter(b)||Character.isDigit(b)||b==':')){

flag++;

break;

}
}

if(flag==1){

System.out.println("Invalid Input");

// System.exit(0);

if(flag==0){

int res=cc+dc+colonc;

if(res==17){

System.out.println("Valid MAC address");

else{

System.out.println("Invalid MAC address");

else if(len<17){

System.out.println("String is too short");

else{

System.out.println("String is too long");

}
}

7. Unique products

Solution:

import java.util.Scanner;

public class Main {

public static void main(String[] args)

Scanner sc=new Scanner(System.in);

System.out.println("Enter the number of items:");

int item_count=sc.nextInt();

if(item_count<5 || item_count>20)

System.out.println("Invalid item count");

else

int item[]=new int[item_count];

int flag=1;

System.out.println("Enter the bar code ID for "+item_count+" items:");

int count=0;
for(int i=0;i<item_count;i++)

int it=sc.nextInt();

if(it<100 || it>999)

System.out.println("Invalid bar code ID");

flag=0;

break;

else

item[i]=it;

if(flag!=0)

for(int j:item)

String s="";

s=s.valueOf(j);

if(s.charAt(0)!=s.charAt(1)&&s.charAt(0)!=s.charAt(2)&&s.charAt(2)!=
s.charAt(1))

System.out.println(j);

count++;
}

if(count==0)

System.out.println("There are no item with Unique number in


the bar code ID");

else

System.out.println("There are "+count+" items with Unique


number in the bar code ID");

8.Toggle word

Solution:

import java.util.*;
class Main

public static void main(String args[])

Scanner sc=new Scanner(System.in);

System.out.println("Enter the word:");

String s=sc.next();

int length=s.length();

if(length<3)

System.out.println("Word length is too short");

else if(length>8)

System.out.println("Word length exceeds the limit");

else

char c[]=s.toCharArray();

int flag=0;

for(char c1:c)

if(Character.isLetter(c1))

flag++;

}
if(flag!=length)

System.out.println("Invalid Input");

else

int i=0;

for(char c1:c)

if(i%2==0)

System.out.print(Character.toUpperCase(c1));

i++;

else

System.out.print(c1);

i++;

9.Prime Number Multiples

Solution:
import java.util.*;

class Main

public static void main(String args[])

Scanner sc=new Scanner(System.in);

int num=sc.nextInt();

int product=1;

if(num<0 || num>32767)

System.out.println("Invalid Input");

else

while(num>0)

int a=num%10;

if(a==2 || a==3 ||a==5 || a==7)

product*=a;

num=num/10;

if(product==1)

System.out.println("No Prime Digit Found");

}
else

System.out.println(product);

10.Estimated Parcel Delivery Time

Solution:

import java.util.*;

public class Main

public static void main(String[] args)

Scanner read=new Scanner(System.in);

System.out.println("Enter the distance in Km:");

int distance=read.nextInt();

if(distance<1)

System.out.println("Invalid Input");

else

float dism=distance*1000;

float div=dism/10;

float time=div/60;

System.out.println("Estimated Time:");

System.out.printf("%.2f Minutes",time);

}}}
Longest substring

Input : abczgdpqrstubg
Output: pqrstu
*/
import java.util.*;
public class Main
{
public static void main (String[] args)
{
Scanner sc=new Scanner(System.in);
String s=sc.next();
int firstindex=0,lastindex=0,length=0;
for(int i=0;i<s.length();i++)
{
int asci=s.charAt(i);
int count=1;
for(int j=i+1;j<s.length();j++)
{
if(s.charAt(j)==++asci)
{
count++;
continue;
}
else
{
if(count>length)
{
firstindex=i;
lastindex=j;
length=count;
break;
}
}
}
}
System.out.println(s.substring(firstindex,lastindex));
}
}
Non Unique char Elimination from string

public class NonUniqueElimination {


public static void main(String[] args){
Scanner sc=new Scanner(System.in);
String name=sc.nextLine(),abc="";
int count=0;
for(int i=0;i<name.length();i++)
{
for(int j=1;j<name.length()-1;j++)
{
if(name.charAt(i)==name.charAt(j))
{
name=name.replace(String.valueOf(name.charAt(j)),"");
count+=1;
}
}
}
if(count==0) {
System.out.println("All are unique character");
return;
}
else {
System.out.println(name);
}
}
Sum of integers at even or odd places

need to specify size (say 5) and then take 5 integer numbers as Input. If the
number of digits in the number is odd then we need to add all odd places digits
and if number of digits is even then we need to add all even place digits. In the
end sum of all these individual sum needs to be displayed as result.

Eg enter size :5
Enter numbers
123(1+3=4)
2536(5+6=11)
2(2)
57(7)
76542(7+5+2=14)
Output: 38 (4+11+2+7+14)

No of substring from a given string

Given a string and a substring, find the number of occurances of the substring in
the given string.
Check that the string can contain only alphabets.
Consider both string and substring in lower case.
Eg:
Enter the string
Entertainment
Enter substring
en
Output : 2
Unknown

input: psvy & 4


(find the difference between p&s i.e 2 and print next 4 letters)
Output: behk

calculate Price*Duration after the deduction of discounts in a Bike renting


Company

*Name should be only in alphabets.. If not Print Invalid


*discount eligible only when the Duration is 5 or more
*Discount table will be given for each card (like Visa,Rupay,Mastercard)
*You have to apply discount for based on the option they used.. (This data is as
1,2,3 where option 1 is visa card option 2 is Rupay)
*If Card option is given as 4,5,6,,... OR 0,-1,-2,,,.. Print "Try again" and go back to
get card option until it's a valid one..

best runner from the given inputs

Input will be given as(Name,seconds)


Jorge, 9.78
Alex, 9.65
Order identification

U need to find weather the array elements are in ascending order r not
Note:array size between 2 and 10(inclusive)
Input1:
Enter the array size:3
Enter the elements
53
52
51
Output:
53 52 51 are not in ascending order

Input2:
Enter the array size:5
Enter the elements
32
65
71
78
82
Output:
32 65 71 78 82 are in ascending order
Product of case count

you need to count uppercase letters and lower case letters in a given string
Multiply the counts and display
Note: string shouldn't contain any digits, special characters
Length shouldn't be greater than 10
Input:
YouRName
Output:
Product value is 15
Explanation
Uppercase letters=3
Lowercase letters=5
Display 3*5=15

import java.util.*;
public class Program{

public static void main(String[] args){


Scanner sc = new Scanner(System.in);
int countj=0,countk=0,i;
System.out.println("Enter string:");
String str=sc.next();
char str1[]=new char[str.length()];
for( i=0;i<str.length();i++) {
if(str.charAt(i)<=122&&str.charAt(i)>=97) {
countj++;
}
else if(str.charAt(i)<=90&&str.charAt(i)>=65) {
countk++;
}
}
System.out.println(countj+" "+countk);
int product=countj*countk;

System.out.println(product);

}}
Unknown

Here, size of the array should be taken as input, and it should be between 1 and
10 (inclusive)
If it is not in 1 and 10, print it as "invalid"
Now, by the comparing the values at the same indices of both the arrays, if both
values are even, then print the sum of the two values, otherwise print "0".
Before performing operation, make sure if no even element is present in both the
arrays, then print it as "There are no even elements in both the arrays",
otherwise perform the above operation.
For example, see the following inputs and outputs:
1. Sample input:
Enter the size of array: 3
Enter the elements in first array:
2
3
4
Enter the elements in second array:
1
5
8
Sample output:
0
0
12

2. Enter the size of array: 3


Enter the elements in first array:
5
3
1
Enter the elements in second array:
1
5
9
Sample output:
There are no even elements in both the arrays

3.Sample input:
Enter the size of array: 1
Enter the elements in first array:
5
Enter the elements in second array:
1
Sample output:There are no even elements in both the arrays

Unkown

Here, a list of grocery items are present as follows:

Rice - 3kg, 5 Rs/kg


Wheat - 2kg, 10Rs/kg
Oil - 4litres, 20Rs/litre
Kerosene - 5litres, 15Rs/litre

Now each of the items is abbreviated by R,W,O and K respectively

Sample input:
ORW
Sample output: the
115
Offer to customers
Toll fee for region code
Take input string of numbers. Extract last four numbers from the string. Calculate
the discount price of the product based on those four numbers.

We need to input the product code as a string


The length of that string shd be of 6-8
If not print invalid
And we need to extract last 4 characters from that string, that will be the MRP of
the product
If the MRP is between 0 to 10, then offer is 0₹
If MRP between 11 to 50, offer is 5₹
If MRP between 51 to 500, offer is 15
If MRP between 501 to 5000, offer is 105
If MRP is above 500, offer is 1005

We need to print the MRP as well as the price after the offer is applied

Sample input 1
20220050
Output 1
MRP : ₹50
Offer price : ₹45

Sample input 2
350004
Output 2
MRP: ₹4
Offer price :₹4

Sample input 3:
202200050
Output 3:
Invalid input
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String n = sc.nextLine();
if (5 < n.length() && n.length() < 9) {
String s = n.substring(n.length() - 4);
int price = Integer.parseInt(s);
if (0 < price && price < 10) {
System.out.println("MRP: Rs " + price);
System.out.println("Offer Price: Rs " + price);
} else if (10 < price && price < 51) {
System.out.println("MRP: Rs " + price);
System.out.println("Offer Price: Rs " + (price - 5));
} else if (50 < price && price < 501) {
System.out.println("MRP: Rs " + price);
System.out.println("Offer Price: Rs " + (price - 15));
} else if (500 < price && price < 5001) {
System.out.println("MRP: Rs " + price);
System.out.println("Offer Price: Rs " + (price - 105));
} else if (5000 < price) {
System.out.println("MRP: Rs " + price);
System.out.println("Offer Price: Rs " + (price - 1005));
}
} else {
System.out.println("Invalid Input");
}
}

Reverse and Concatenate

She sells seashells


Same first letter for all words so reverse the last word and concatenate first word
Output: sllehsaesShe

If first letter is not same then reverse first word and concatenate with last word
Male female version code
import java.util.*;
import java.util.regex.Pattern;
public class Main{
public static void main(String args[]){

Scanner sc = new Scanner(System.in);

String str = sc.next();

int count=0;
int count1=0;

if(Pattern.matches("[mfMF]+",str)){

for(int i=0;i<str.length();i++){
if(str.charAt(i)=='M' || str.charAt(i)=='m'){
count++;
}
else if( str.charAt(i)=='F' || str.charAt(i)=='f'){
count1++;
}
}
System.out.println(count+" Male");
System.out.println(count1+" Female");
}
else{
System.out.println("Not a valid input");
return;
}
}
}
LCM

Tony comes to hotel every 4(i) days and potts every 6(j) days when will they
meet? if i or j <0 print invalid, don't use system.exit (To find LCM)
Cake

Input : 4725strawberry181
Extract the weight , flavour , order id and output the cake price according to per kg price given
initially , and print all the cake details.
Output :
4.73 kg
Strawberry
181
Price:

import java.util.*;
public class cake_order {
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
String s=sc.next();
if(!s.matches("^[a-zA-z0-9]*$"))
{
System.out.println("Invalid string");
return;
}
else
{
String str=s.substring(0,4);
for(int i=0;i<str.length();i++)
{
if(!Character.isDigit(str.charAt(i)))
{
System.out.println("Invalid string");
return;
}

}
int num=Integer.parseInt(str);
if(num<1000)
{
System.out.println("Invalid weight");
return;
}
int l=s.length();
int li=l-3;
String s1=s.substring(li,l);
for(int i=li;i<l;i++)
{
if(!Character.isDigit(s.charAt(i)))
{
System.out.println("Invalid orderno");
return;
}
}
int k=Integer.parseInt(s1);
if(k<100)
{
System.out.println("Invalid Order no");
return;
}
double I=Double.parseDouble(str)/1000;
String form=String.format("%.2f", I);
System.out.println("Cake weight is "+form);
String falv="";
for(int i=4;i<li;i++)
{
falv+=s.charAt(i);
}
System.out.println("Cake flavour is "+falv);
System.out.println("Order no is "+s1);
double price=450*I;
String f=String.format("%.2f",price);
System.out.println("Price is "+f);
}
}
}
Products equals sum
Fun count

Input array of string


if there is 5 input
barbie
barbie
doll
doll
bike

output
barbie=2
doll=2
bike=1
Speed Calculation

The normal_speed 30km/h was given


Take two input hours and distance
Find speed= distance/hours
if speed > normalspeed
then
Actual speed=speed-normal_speed
print actual speed
else
print continue on speed
Add with index
Next Mixing Letters
Mega mart customer identification
Theater seat details
Compose Rhythm(Prime numbers btw two no’s)
Rating Score
Unknown
1

1. Gender determination ……………………………………….. 2


2. LCM lunch/dinner together …………………………………2-3
3. Product equals sum ………………………………………………3-5
4. Count of occurences of substring in a given string… ..5-6
5. Fun count……………………………………………………………….. 6
6. Speed Estimation…………………………………………………… 7
7. Prime number………………………………………………………. 7-8
8. Theatre seat ………………………………………………………… 8-9
9. Customer details …………………………………………………. 10-11
10. Team win/loose ………………………………………………… 11
11. Holiday fun ……………………………………………………….. 11-12
12. Reverse-prime …………………………………………………… 12-13
13. Even number addition in arrays…………………………. 14
14. Groceries bill …………………………………………………….. 15
15. Cake order …………………………………………………………. 16-17
2

Gender Determination :

import java.util.*;
public class Main {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
String s=sc.next();
int count=0,count1=0;
if(!(s.matches("[mfMF]+")))
{
System.out.println("Invalid Input");
return;
}
else
for(int i=0;i<s.length();i++)
{
if(s.charAt(i)=='m' ||s.charAt(i)=='M')
count++;
else
count1++;
}
System.out.println(count+" "+"Male");
System.out.println(count1+" "+"Female");
}}
LCM OF DAY INTERVAL/LUNCH/DINNER TOGETHER :

import java.util.*;
public class Main {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
System.out.println("Enter the day interval of person 1:");
int a=sc.nextInt();
System.out.println("Enter the day interval of person 2:");
int b=sc.nextInt();
if(a<=0 || b<=0)
{
System.out.println("Given interval is not valid");
return;
3

}
int lcm;
lcm=(a>b)?a:b;
while(true){
if(lcm%a==0 && lcm%b==0){
System.out.println("person 1 and person 2 will have
their dinner on day "+lcm);
break;
}
lcm++;
}
}}

PRODUCT EQUALS SUM

import java.util.*;

public class Main{

public static void main(String args[]){

Scanner sc=new Scanner(System.in);

System.out.println("Enter the array size:");

int n=sc.nextInt();

int count=0;

if(n<1 || n>10){

System.out.print("Invalid array size");

System.exit(0);

else{

int[] a1=new int[n];

int[] a2=new int[n];

System.out.println("Enter the elements of the first array");


4

for(int i=0;i<n;i++){

int b=sc.nextInt();

if(b>10 && b<999)

a1[i]=b;

else{

System.out.print("Invalid input");

System.exit(0);

}}

System.out.println("Enter the elements of the second


array");

for(int i=0;i<n;i++){

int c=sc.nextInt();

if(c>10 && c<999)

a2[i]=c;

else{

System.out.print("Invalid input");

System.exit(0);

}}

for(int i=0;i<n;i++){

int mul=1,r=0,x=a1[i];

while(x>0){

r=x%10;

mul*=r;
5

x=x/10;

for(int j=0;j<n;j++){

int sum=0,p=0,y=a2[j];

while(y>0){

p=y%10;

sum+=p;

y=y/10;

if(mul==sum){

count++;

System.out.print(a1[i]+","+a2[j]);

System.out.println(" ");

}}}

if(count==0){

System.out.print("No pair found");

System.exit(0);

}}}}

Count of Occurrences of Substring in a String

import java.util.*;
public class Main {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
String s1=sc.next();
String s2=sc.next();
int index=0;
6

int count=0;
while((index=s1.indexOf(s2,index))!=-1){
index=index+1;
count+=1;
}
System.out.println(count);
}
}

Fun Count

import java.util.*;
public class Main {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
if(n<=0){
System.out.println("Invalid Input");
return;
}
if(n>15){
System.out.println("Number exceeds the limit");
return;
}
Map<String,Integer> a=new HashMap<>();
for(int i=0;i<n;i++){
String s=sc.next().toLowerCase();
if(a.containsKey(s))
a.put(s,1+a.get(s));
else
a.put(s,1);
}
Map<String,Integer> tm=new TreeMap<>(a);
for(Map.Entry<String,Integer>data:tm.entrySet()){
System.out.println(data.getKey()+"= "+data.getValue());
}
}
}
7

SPEED ESTIMATION :
import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
System.out.println("Enter the distance in kilometer");
int km=sc.nextInt();
if(km<0) {
System.out.println("Invalid Input");
return;
}
System.out.println("Enter the time to reach in hours");
int hours=sc.nextInt();
if(hours<0){
System.out.println("Invalid Input");
return;
}
int speed=km/hours;
if(speed<30){
System.out.println("You drive a car at normal speed");
return;
}
int inc=speed-30;
System.out.println("You want to increase a speed "+inc+"
km/hr from a normal speed");
}}

Prime Number

import java.util.Scanner;

public class Main{

public static void main(String[] args){

Scanner sc=new Scanner(System.in);

int a = sc.nextInt();

int b = sc.nextInt();

int count=0;
8

if(a<0 || b<0){

System.out.println("Negative integers cannot be prime");

return;

for(int i=a;i<=b;i++){

count = 0;

for(int j=2;j<=i;j++){

if(i % j == 0)

count = count+1;

if(count == 1)

System.out.print(i+" ");

if(count!=1)

System.out.println("There are no prime numbers in the range


"+a+" to "+b);

Theatre

import java.util.*;
public class Main {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
String s=sc.next();
if(s.length()==6)
{
9

String a=s.substring(0,1);
if(a.matches("[NEWS]+"))
{
String b=s.substring(1,2);
if(b.matches("[ABCDE]+"))
{
String c=s.substring(2,3);
if(c.matches("[1-4]+"))
{
String d=s.substring(3,6);
int num=Integer.parseInt(d);
if(num>0 && num<500)
{
System.out.println("Name "+a);
System.out.println("Block "+b);
System.out.println("Floor number "+c);
System.out.println("Seat number
"+num);
}
else
System.out.println("Invalid Seat number");
}
else
System.out.println("Invalid Floor number");
}
else
System.out.println("Invalid Block");
}
else
System.out.println("Invalid Name");
}
else
System.out.println("Invalid size");
}}
10

Customer details

import java.util.Scanner;

public class Main{


public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number of customers:");
int cust=sc.nextInt();
if(cust<0)
{
System.out.println("Invalid Input");
return;
}
if(cust<3)
{
System.out.println("Customer count is too low");
return;
}
if(cust>50)
{
System.out.println("Customer count is too high");
return;
}
System.out.println("Enter the customer details:");
String[] arr=new String[cust];
for (int i=0;i<cust;i++)
{
arr[i]=sc.next();
}
System.out.println("Enter the plan to be searched");
String plan=sc.next();
for (int i=0;i<cust;i++)
{
String[] custdetails=arr[i].split(":");
if(plan.equals(custdetails[1]))
{
System.out.println(custdetails[2]+" "+custdetails[3]);
11

}
}
}
}

Team Win/Loose
import java.util.*;
public class Main {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
String str=sc.next();
int count=0;
if(str.length()<3) {
System.out.println("Invalid input");
return;
}
if(str.matches("[htHT]+")) {
String s=str.toLowerCase();
for(int i=0;i<s.length()-2;i++){
if(s.charAt(i)!=s.charAt(i+1) &&
s.charAt(i)==s.charAt(i+2))
count++;
}
if(count==s.length()-2)
System.out.println("Team will win");
else
System.out.println("Team may loose");
}
else {
System.out.println("Invalid Input");
return;
}
}}

Holiday Fun

import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
12

int sum=0,sum1=0;
int n=sc.nextInt();
if(n>0){
String[] a=new String[n];
for(int i=0;i<n;i++){
a[i]=sc.next();
}
for(int i=0;i<n;i++){
int len=a[i].length();
if(len%2==0)
{
for(int j=1;j<len;j++){

sum=sum+Integer.parseInt(String.valueOf(a[i].charAt(j)));
j++;
}}
else
{
for(int k=0;k<len;k++){

sum1=sum1+Integer.parseInt(String.valueOf(a[i].charAt(k)));
k++;
}}
}
System.out.println(sum+sum1);
}
else
System.out.println("Invalid size");
}}

Reverse Prime

import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
int count=0,c=0,f=0,r=0,prime=0;
int n=sc.nextInt();
if(n>0) {
int[] a=new int[n];
13

for(int i=0;i<n;i++) {
int num=sc.nextInt();
if(num>9)
a[i]=num;
else {
System.out.println("Provided "+num+" is not valid");
return;
}}
for(int i=0;i<n;i++) {
count=0;
for(int j=2;j<a[i];j++)
{
if(a[i]%j==0)
count++;
}
if(count==0) {
prime++;
f=a[i];
r=0;
while(a[i]!=0) {
r=r*10;
r=r+a[i]%10;
a[i] =a[i]/10;
}
for(int k=2;k<r;k++) {
if(r%k==0)
c++;
}
if(c==0)
System.out.println(f);
}}}
else {
System.out.println(n+" is less than a limit");
return;
}
if(prime==0)
System.out.println(n+" values are not prime numbers");
}}
14

Even number addition in arrays

import java.util.*;
public class Main {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
int count=0;
System.out.println("Enter the size of array ");
int n=sc.nextInt();
int[] sum=new int[n];
if(n>=1 && n<=10)
{
int[] a=new int[n];
System.out.println("Enter the elements of the first array ");
for(int i=0;i<n;i++)
a[i]=sc.nextInt();
int[] b=new int[n];
System.out.println("Enter the elements of second array ");
for(int i=0;i<n;i++)
b[i]=sc.nextInt();
for(int i=0;i<n;i++)
{
if(a[i]%2==0 && b[i]%2==0)
{
count++;
sum[i]=a[i]+b[i];
}
else
sum[i]=0;
}
if(count==0)
System.out.println("There are no even elements");
else
for(int result:sum)
System.out.println(result);
}
else
System.out.println("Invalid");
}}
15

Groceries Bill

import java.util.*;
public class Main {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
String s=sc.next();
int a=0,b=0,c=0,d=0,count=0;
if(s.matches("[ORWKorwk]+")) {
for(int i=0;i<s.length();i++) {
for(int j=0;j<s.length();j++) {
if(s.charAt(i)==s.charAt(j))
count++;
}}
if(count==s.length()) {
for(int k=0;k<s.length();k++)
{
if(s.charAt(k)=='O')
a=4*20;
else if(s.charAt(k)=='R')
b=3*5;
else if(s.charAt(k)=='W')
c=2*10;
else
d=5*15;
}
System.out.println(a+b+c+d);
}
else
System.out.println("Duplicates are not allowed");
}
else
System.out.println("Invalid");
}}
16

Cake Order

import java.util.*;

public class CakeProgram {

public static void main(String[] args) {


Scanner sc=new Scanner(System.in);
System.out.println("Enter the Customer instructions: ");
String cd=sc.nextLine();

if (cd.matches("[a-zA-Z0-9]*")) {
String w=cd.substring(0, 4);

if(!w.matches("[0-9]*")){
System.out.println("Invalid weight");
return;
}

float wg=Integer.parseInt(w);
if (wg>999) {
float fwg=wg/1000;
double weight= (Math.round(fwg * 100.0) / 100.0);

String o=cd.substring(cd.length()-3);
if (!o.matches("[0-9]*")) {
System.out.println("Invalid order number");
return;
}
int on=Integer.parseInt(o);
if(on>99) {
String flavour=cd.substring(4,cd.length()-3);

System.out.println("Weight of Cake in Kgs:


"+String.format("%.2f", weight));
System.out.println("Order No: "+on);
System.out.println("Flavour Name: "+flavour);

double cakePrice=450*weight;
17

System.out.printf("Cake Price is: %.2f


Rupees",cakePrice);
}
else {
System.out.println("Invalid order number");
}
}
else {
System.out.println("Invalid weight");
}
}
else {
System.out.println("Invalid Input");
}
}

}
Java Codes
1.Absolute Difference
public class AbsoluteDifference {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number of values");
int n=sc.nextInt();
int sum=0;
if((n<=0) && (n%2!=0))
{
System.out.println(n+" is an invalid size");
return;
}
System.out.println("Enter the numbers");
int[] a=new int[n];
for(int i=0;i<n;i++)
{
a[i]=sc.nextInt();
if(a[i]<=0)
{
System.out.println(a[i]+" is an invalid number");
return;
}
}
for(int i=0;i<n/2;i++)
{
sum+=Math.abs(a[i]-a[n-i-1]);
}
System.out.println(sum);
}
}

2.Add With Index


public class AddWithIndex {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the array size");
int n=sc.nextInt();
if(n<5)
{
System.out.println("Array size "+n+" is too low");
return;
}
if(n>10)
{
System.out.println("Array size "+n+" is too high");
return;
}
int a[]=new int[n];
int b[]=new int[n];
System.out.println("Enter the array elements");
for(int i=0;i<n;i++)
{
a[i]=sc.nextInt();
b[i]=a[i];
}
Arrays.sort(b);
if(b[0]==b[n-1])
{
System.out.println("These "+n+" values are same");
return;
}
int max=b[b.length-1];
int max_index=0;
for(int i=0;i<n;i++)
{
if(a[i]==max)
{
max_index=i;
break;
}
}
for(int i=0;i<n;i++)
{
a[i]=a[i]+max_index;
}
System.out.println("output");
for(int i:a)
{
System.out.println(i);
}

}
}

3.Phone Charging Duration

public class BatteryCapacity {


public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter battery capacity");
double cap=sc.nextDouble();
if(!(cap>=1000 && cap<=10000))
{
System.out.println("Invalid battery capacity");
return;
}
System.out.println("Enter the charging current value");
double current=sc.nextDouble();
if(!(current>=300 && current<=2100))
{
System.out.println("Invalid output current");
return;
}
double time=0.0f;
time=(cap/current)*1.2;
System.out.printf("%.2f Hours",time);
}
}

4.Car Parking
public class CarParking {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the car number");
String car=sc.nextLine();
String str[]=car.split(" ");
int len=car.length();
if(len!=10)
{
System.out.println("Invalid State Code");
return;
}
String floor;
String code=car.substring(0,2);
if(code.equals("TN"))
{
floor="ground";
}
else if(code.equals("KA"))
{
floor="1st";
}
else if(code.equals("KL"))
{
floor="2nd";
}
else if(code.equals("AP"))
{
floor="3rd";
}
else{
System.out.println("Invalid State Code");
return;
}
System.out.println("Park the car in "+floor+" floor");
}
}

5.Product of Case Count


public class CaseCountProduct {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the string : ");
String str = sc.nextLine();
int upper = 0, lower = 0;
int len=str.length();
if(str.matches("[a-zA-Z]+")) {
if(str.length()<=10) {
for(int i=0;i<str.length();i++) {
if(Character.isUpperCase(str.charAt(i)))
upper++;
else
lower++;
}
} else {
System.out.println(str+" exceeds the limit");
return;
}
} else {
System.out.println(str+" is not a valid string");
return;
}
int result=upper*lower;
System.out.println("Product value is "+result);
}
}

6.Count Occurrence in Substring


public class CountOccurencesInsubstring {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the sentence:");
String str1=sc.nextLine();
if(!str1.matches("[a-zA-Z]*"))
{
System.out.println("Invalid Input");
}
else{
System.out.println("Enter the substring");
String sub=sc.nextLine();
str1=str1.toLowerCase();
if(sub.length()<2)
{
System.out.println("Substring length is too short");
}
else{
str1=str1.replaceAll(sub,"0");
int count=0;
for(int i=0;i<str1.length();i++)
{
if(str1.charAt(i)=='0')
{
count++;
}
}
if(count==0)
{
System.out.println("Not matching pattern");
}
else{
System.out.println(count);
}
}
}
}
}

7.Digit Count
public class DigitCount {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the number");
int n = sc.nextInt();
String num = Integer.toString(n);
if (n<=0) {
System.out.println(num + " is an invalid number");
return;
} else {
System.out.println("Enter the digit");
int d = sc.nextInt();
String dig = Integer.toString(d);
if (!dig.matches("[0-9]")) {
System.out.println(dig + " is not in range");
return;
} else {
int count = 0;
for (int i = 0; i < num.length(); i++) {
int ch = Integer.parseInt(String.valueOf(num.charAt(i)));
if (ch == d) {
count++;
}
}
System.out.println(d+" appears in "+num+" is "+count);
}
}

8.Land Area discount calculation


public class DiscountCalculation {
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the customer name");
String name=sc.nextLine();
System.out.println("Enter the land area");
double land=sc.nextDouble();
long total=0;
double discount=0;
double pay=0;
if((land<400) || (land>2200))
{
System.out.printf("%.1f is out of range.",land);
return;
}
else if((land>=400) && (land<600))
{
total=(long)(land*1700);
discount=(double)(total*0.05);
pay=(double)(total-discount);
}
else if((land>=600) && (land<1000))
{
total=(long)(land*1950);
discount=(double)(total*0.05);
pay=(double)(total-discount);
}
else if((land>=1000) && (land<1500))
{
total=(long)(land*2100);
discount=(double)(total*0.04);
pay=(double)(total-discount);
}
else if((land>=1500) && (land<2201))
{
total=(long)(land*2300);
discount=(double)(total*0.03);
pay=(double)(total-discount);
}
System.out.printf("Total payable amount after discount is %.1f",pay);
}
}

9.Fun Count
public class FC2 {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number of toys");
int n=sc.nextInt();
if(n<=0)
{
System.out.println("Invalid Input");
}
else if(n>15)
{
System.out.println("Number exceeds the limit");
}
else{
String[] ar1=new String[n];
System.out.println("Enter the toy list");
for(int i=0;i<n;i++)
{
ar1[i]=sc.next().toLowerCase();
}
Arrays.sort(ar1);
int count=0;
for(int i=0;i<n;i++)
{
count=1;
for(int j=i+1;j<n;j++)
{
if(ar1[i].equalsIgnoreCase(ar1[j]))
{
count++;
ar1[j]="0";
}
}
if(ar1[i]!="0")
{
System.out.println(ar1[i]+"="+count);
}
}
}
}
}

10.Gender Determination
public class GenderDetermination {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
String str=sc.nextLine();
int mc=0;
int fc=0;
if(!str.matches("[mMfF]*"))
{
System.out.println("Invalid Input");
}
else{
for(int i=0;i<str.length();i++)
{
char temp=str.charAt(i);
if((str.charAt(i)=='M') || (str.charAt(i)=='m'))
{
mc++;
}
else if((str.charAt(i)=='F') || (str.charAt(i)=='f'))
{
fc++;
}
}
System.out.println(mc+" Male");
System.out.println(fc+" Female");
}
}
}

11.Gross Numbers or Ugly Numbers


public class GrossNumber2 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the number of integers");
int n = sc.nextInt();
if (n <= 0) {
System.out.println("The number of integers " + n + " is invalid");
return;
}
int[] a = new int[n];
System.out.println("Enter the integers");
for (int i = 0; i < n; i++) {
a[i] = sc.nextInt();
if ((a[i] <= 0) && (a[i] > 100)) {
System.out.println(a[i] + " is not in range");
return;
}
}
int[] b = new int[100];
int num = 2,k = 0;
while (num < 100) {
if ((num % 2 == 0) || (num % 3 == 0) || (num % 5 == 0)) {
b[k++] = num;
}
num++;
}
int flag = 0;
for (int i = 0; i < n; i++) {
flag = 0;
for(int j=0;j<k;j++)
{
if(a[i]==b[j])
{
System.out.println(j+1);
flag=0;
break;
}
else{
flag=1;
}
}
if(flag==1)
{
System.out.println(0);
}
}
}
}

12.LCM Tony Potts


public class LCMTonyPotts {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the day interval of Tony");
int d1=sc.nextInt();
if(d1<0)
{
System.out.println(d1+" is not a valid day");
}
else{
System.out.println("Enter the day interval of Potts");
int d2=sc.nextInt();
if(d2<0)
{
System.out.println(d2+" is not a valid day");
}
else{
int lcm=(d1>d2)?d1:d2;
while(true)
{
if(lcm%d1==0 && lcm%d2==0)
{
System.out.printf("Tony and Potts will have their lunch on day %d",lcm);
break;
}
++lcm;
}
}
}
}
}
13.Longest Substring
public class LongSubstring {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
String str=sc.next().toLowerCase();
String res="";
for(int i=0;i<str.length();i++)
{
String s=str.substring(i,i+1);
for(int j=i;j<str.length()-1;j++)
{
if(str.charAt(j+1)==str.charAt(j)+1)
{
s+=str.charAt(j+1);
}
else{
i=j;
break;
}
}
if(res.length()<s.length())
{
res=s;
}
}
System.out.println(res);
}
}

14.Lottery Ticket
public class LotteryTicket {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int i=0,c=0,n=0,sum=0,count=0;
System.out.println("Enter the starting range");
int a=sc.nextInt();
String str1=Integer.toString(a);
if(str1.length()!=5)
{
System.out.println(str1+" is an invalid length");
return;
}
System.out.println("Enter the ending range");
int b=sc.nextInt();
String str2=Integer.toString(b);
if(str2.length()!=5)
{
System.out.println(str2+" is an invalid length");
return;
}
if(a>b)
{
System.out.println(a+" and "+b+" are invalid serial numbers");
return;
}
for(i=a;i<=b;i++)
{
n=i;
while(n!=0)
{
c=n%10;
sum=sum+c;
n/=10;
}
if((sum%3==0) && ((sum/3)%2==0))
{
System.out.println(i+" ");
count++;
}
sum=0;
}
if(count==0)
{
System.out.println("Eligible tickets are not available from "+a+" to "+b);
return;
}
}
}

15.Multiply with position


public class MultiplyWithPosition {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the array size");
int n=sc.nextInt();
if((n<1) || (n>10))
{
System.out.println("Invalid Array Size");
return;
}
int[] a=new int[n];
int res=0;
System.out.println("Enter the elements");
for(int i=0;i<n;i++)
{
a[i]=sc.nextInt();
}
for(int i=0;i<n;i++)
{
res=a[i]*(i+1);
System.out.println(res);
}

}
}

16. Offer Price


public class OfferPrice {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String n=sc.nextLine();
int offer=0;
int len=n.length();
if(5<len && len<9)
{
String str=n.substring(len-4);
int price=Integer.parseInt(str);
if(price>=1 && price<11)
{
offer=0;
}
else if(price>=11 && price<51)
{
offer=price-5;
}
else if(price>=51 && price<501)
{
offer=price-15;
}
else if(price>=501 && price<5001)
{
offer=price-105;
}
else if(price>=5001)
{
offer=price-1005;
}
System.out.println("MRP:Rs "+price);
System.out.println("Offer Price: Rs "+offer);
}
else{
System.out.println("Invalid Input");
return;
}
}
}
17. Online Shopping
public class OnlineShopping{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the Product:");
String prod=sc.nextLine();
int ed=0,pd=0;
if(prod.equalsIgnoreCase("Mobile"))
{
ed=5;
pd=5;
}
else if(prod.equalsIgnoreCase("Laptop"))
{
ed=10;
pd=15;
}
else if(prod.equalsIgnoreCase("Telephone"))
{
ed=0;
pd=10;
}
else if(prod.equalsIgnoreCase("Headset"))
{
ed=0;
pd=20;
}
else{
System.out.println("Not Available");
return;
}
System.out.println("Enter the price");
int price=sc.nextInt();
sc.nextLine();
if(price<100)
{
System.out.println("Invalid price");
return;
}
System.out.println("Do you want to exchange(yes/No)?");
String exc=sc.nextLine();
if(exc.equalsIgnoreCase("Yes"))
{
double ap=price-(price*pd)/100;
double exp=(price*ed)/100;
double total=ap-exp;
System.out.printf("Total= %.2f",total);
}
else if(exc.equalsIgnoreCase("No"))
{
double total=price-(price*pd)/100;
System.out.printf("Total= %.2f",total);
}
else{
System.out.println("Invalid Option");
}
}
}

18. Product Equals Sum


public class ProductEqualsSum
{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the size of array");
int n=sc.nextInt();
if(n<0)
{
System.out.println("Invalid size");
return;
}
int a[]=new int[n];
int b[]=new int[n];
System.out.println("Enter the array 1 elements");
for(int i=0;i<n;i++)
{
a[i]=sc.nextInt();
}
System.out.println("Enter the array 2 elements");
for(int i=0;i<n;i++)
{
b[i]=sc.nextInt();
}
int x[]=new int[n];
int y[]=new int[n];
for(int i=0;i<n;i++)
{
int c=a[i];
int prod=1;
while(c!=0)
{
prod*=(c%10);
c/=10;
}
x[i]=prod;
prod=0;
}
for(int i=0;i<n;i++)
{
int d=b[i];
int sum=0;
while(d!=0)
{
sum+=(d%10);
d/=10;
}
y[i]=sum;
sum=0;
}
for(int i=0;i<n;i++)
{
if(x[i]==y[i])
{
System.out.println(a[i]+" , "+b[i]);
}
}
}
}

19. Order Identification


public class Order {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the array size:");
int n = sc.nextInt();
if (n < 2 || n > 10) {
System.out.println("Invalid input");
return;
} else {
int a[] = new int[n];
int b[] = new int[n];
System.out.println("Enter the elements:");
for (int i = 0; i < n; i++) {
a[i] = sc.nextInt();
b[i] = a[i];
}
int temp = b[0];
int flag = 0;
for (int i = 1; i < n; i++) {
if (temp != b[i]) {
flag = 1;
break;
}
}
if (flag == 1) {
Arrays.sort(a);
for (int i = 0; i < n; i++) {
System.out.print(b[i] + " ");
}
if (Arrays.equals(a, b)) {
System.out.print(" in ascending order");
} else {
System.out.print(" not in ascending order.");
}
} else {
for (int i = 0; i < n; i++) {
System.out.print(b[i] + " ");
}
System.out.print(" not in ascending order.");
}
}
}
}

20. Reverse a Word


public class ReverseAWord
{
public static void main(String []args)
{
Scanner sc=new Scanner(System.in);
String s=sc.nextLine();
String sa[]=s.split(" ");
if((s==null) && (s.equals("")) && (!s.matches("[a-zA-Z]*$")))
{
System.out.println("Invalid Word");
return;
}
if(sa.length!=3)
{
System.out.println("Invalid Sentence");
return;
}
StringBuilder ss=new StringBuilder();
char aa[]=new char[sa.length];
for(int i=0;i<sa.length;i++)
{
char a[]=sa[i].toCharArray();
aa[i]=a[0];
}
if(aa[0]==aa[1] && aa[1]==aa[2])
{
ss.append(sa[2]);
ss=ss.reverse();
ss.append(sa[0]);
System.out.println(ss);
}
else
{
ss.append(sa[0]);
ss=ss.reverse();
ss.append(sa[2]);
System.out.println(ss);
}
}
}

21. Reverse first half


public class ReverseFirstHalf {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the string");
String str=sc.nextLine();
int len=str.length();
if(len<2)
{
System.out.println("Size of string "+str+" is too small");
return;
}
for(int i=0;i<len;i++)
{
if(Character.isLetter(str.charAt(i)))
{
continue;
}
else{
System.out.println(str+" is not a valid string");
return;
}
}
if(len%2==0)
{
StringBuilder sb=new StringBuilder(str);
sb.reverse();
System.out.println(sb.toString());
}
else if(len%2!=0)
{
int mid=len/2;
mid++;
String sub=str.substring(0,mid-1);
String remain=str.substring(mid-1,len);
StringBuilder sb=new StringBuilder(sub);
sb.reverse();
System.out.println(sb.toString()+remain);
}
}
}
22 Sign Conversion
public class ReverseFirstHalf {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the string");
String str=sc.nextLine();
int len=str.length();
if(len<2)
{
System.out.println("Size of string "+str+" is too small");
return;
}
for(int i=0;i<len;i++)
{
if(Character.isLetter(str.charAt(i)))
{
continue;
}
else{
System.out.println(str+" is not a valid string");
return;
}
}
if(len%2==0)
{
StringBuilder sb=new StringBuilder(str);
sb.reverse();
System.out.println(sb.toString());
}
else if(len%2!=0)
{
int mid=len/2;
mid++;
String sub=str.substring(0,mid-1);
String remain=str.substring(mid-1,len);
StringBuilder sb=new StringBuilder(sub);
sb.reverse();
System.out.println(sb.toString()+remain);
}
}
}

23 Sum of odd digit squares


public class SumOfOddDigitSquares {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number of values");
int n=sc.nextInt();
if(n<=0)
{
System.out.println(n+" is an invalid size");
return;
}
int[] a=new int[n];
int count=0;
int sum=0;
System.out.println("Enter the values");
for(int i=0;i<n;i++)
{
a[i]=sc.nextInt();
if(a[i]%2!=0)
count++;
}
if(count<=0)
{
System.out.println("These "+n+" values are not an odd digit");
return;
}
else{
for(int i=0;i<n;i++)
{
if(a[i]%2!=0)
{
sum=sum+a[i]*a[i];
}
}
System.out.println(sum);
}
}
}

24.Threes
public class ThreesASCII {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("Enter the String");
String str =in.nextLine();
int len=str.length();
for(int i=0;i<len;i++)
{
if(Character.isLetter(str.charAt(i)) || (Character.isWhitespace(str.charAt(i))))
{
continue;
}
else{
System.out.println(str+" is not a valid string");
return;
}
}
int sum=0;
for(int i=0;i<len;i++)
{
if((i+1)%3==0)
{
sum+=(int)(str.charAt(i));
}
}
System.out.println("Sum is "+sum);
}
}

25.Toy Shop
public class ToyShop {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number of months");
int m=sc.nextInt();
if(m<=0)
{
System.out.println(m+" is an invalid number of month");
return;
}
int[] a=new int[m];
System.out.println("Enter the number of toys to be purchased monthly");
for(int i=0;i<m;i++)
{
a[i]=sc.nextInt();
if(a[i]<=10)
{
System.out.println(a[i]+" is an invalid number of toys");
return;
}
}
int max=0,index=1;
for(int i=0;i<m;i++)
{
if(a[i]>=max)
{
max=a[i];
index=i;
}
}
for(int k=0;k<m;k++)
{
if(a[k]==max)
System.out.println("Month "+(k+1));
}
}}
26.Unique Characters
public class Unique {

public static void main(String[] args)


{
System.out.println("Enter the String");
Scanner sc=new Scanner(System. in);
String str=sc.nextLine();
String output="";
String[] word=str.split(" ");
for(int i=0;i<word.length;i++)
{
for(int j=0;j<word[i].length();j++)
{
int count=0;
char c=word[i].charAt(j);
for(int k=0;k<word[i].length();k++)
{
if(c==word[i].charAt(k))
count++;
}
if(count==1)
{
output+=Character.toLowerCase(c);
}
}
output+=" ";
}
System.out.println(output);
}
}

27. Video Game


public class VideoGame {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the amount");
int amount=sc.nextInt();
if(amount<=3000)
{
System.out.println(amount+" is too less");
return;
}
sc.nextLine();
System.out.println("Enter the Video Game Player Type");
String v=sc.nextLine();
if(v.matches("[P][S][1-5]"))
{
if(v.equals("PS1"))
{
if(amount>=5000)
{
System.out.println("You can buy a PS1");
}
else{
System.out.println("You need more amount to buy a PS1");
}
}
else if(v.equals("PS2"))
{
if(amount>=7800)
{
System.out.println("You can buy a PS2");
}
else{
System.out.println("You need more amount to buy a PS2");
}
}
else if(v.equals("PS3"))
{
if(amount>=9500)
{
System.out.println("You can buy a PS3");
}
else{
System.out.println("You need more amount to buy a PS3");
}
}
else if(v.equals("PS4"))
{
if(amount>=12000)
{
System.out.println("You can buy a PS4");
}
else{
System.out.println("You need more amount to buy a PS4");
}
}
else if(v.equals("PS5"))
{
if(amount>=15000)
{
System.out.println("You can buy a PS5");
}
else {
System.out.println("You need more amount to buy a PS5");
}
}
}
else{
System.out.println(v+" is an invalid type");
}
}
}

28.Word Find
public class WordFind {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the number of words");
int n=sc.nextInt();
if(n<=0)
{
System.out.println(n+" is less than the desired limit");
return;
}
sc.nextLine();
String set1[]=new String[n];
String set2[]=new String[n];
System.out.println("Enter the words in set1");
for(int i=0;i<n;i++)
{
set1[i]=sc.nextLine();
}
System.out.println("Enter the words in set2");
for(int i=0;i<n;i++)
{
set2[i]=sc.nextLine();
}
int count=0;
int flag=1;
for(int i=0;i<set1.length;i++)
{
String first=set1[i];
for(int j=0;j<set2.length;j++)
{
String second=set2[j];
if(first.equalsIgnoreCase(second))
{
count++;
flag=0;
}
}
if(flag==1)
{
System.out.println(set1[i]);
}
flag=1;
}
if(n==count)
{
System.out.println(n+" words in a set are repeated");
}
}

29.MegaMart
public class MegaMart {
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
System.out.println("Enter the Customer Id");
String str = sc.next();
String name = str.substring(0,4);
if(name.equals("Mega")){
String ctype ="";
if(str.contains("Gold") || str.contains("Silver") || str.contains("Platinum")){
if(str.contains("Gold"))
ctype = "Gold";
else if(str.contains("Platinum"))
ctype="Platinum";
else if(str.contains("Silver"))
ctype="Silver";
String n =str.substring(str.length()-3,str.length());
if(n.matches("[a-z]{1}[0-9]{2}"))
{
System.out.println("Invalid Member Id");
return;
}
int n1 =Integer.parseInt(n);
if(n1>99 && n1 <1000)
System.out.println("Welcome Mega Mart "+ctype+" Customer");
else{
System.out.println("Invalid Member Id");
}
}
else{
System.out.println("Invalid Customer Type");
}
}
else{
System.out.println("Invalid Shop Name");
}
}
}

30.Theater Seat Details


package practice;
import java.util.*;
public class TheaterSeatDetails {

public static void main(String[] args) {


// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
String s = sc.next().toUpperCase();
if(s.length() != 10){
System.out.println("Invalid input");
return;
}
if(s.charAt(6)<49 || s.charAt(6)>57){
System.out.println("Invalid count");
return;
}
if(s.charAt(7) < 'A' || s.charAt(7) > 'Z'){
System.out.println("Invalid Alpha");
return;
}
if((s.charAt(8)<48 || s.charAt(8)>57) || (s.charAt(9)<48 && s.charAt(9)>57)){
System.out.println("Invalid Size Number");
return;
}
String ch ="";
ch += s.charAt(6);
int c = Integer.parseInt(ch);
int num = Integer.parseInt(s.substring(8,10));
System.out.println("Seat Numbers");
for(int i =0;i<c;i++){
System.out.print(s.charAt(7));
System.out.println(num++);
}
}
}

31.Bike Rent
public class BillAmount {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter your name");
String name=sc.nextLine();
int len=name.length();
double fare=0;
double disc=0;
for(int i=0;i<len;i++)
{
if(!Character.isLetter(name.charAt(i)))
{
System.out.println(name+" is an invalid name");
return;
}
}
System.out.println("Enter the time of duration");
int n=sc.nextInt();
if((n<=0) || (n>=24))
{
System.out.println("Invalid Duration");
return;
}
System.out.println("List of payment options");
System.out.println("1) Visa card");
System.out.println("2) Rupay card");
System.out.println("3) Master card");
System.out.println("Choose an option");
int op=sc.nextInt();
if((op<0) || (op>=3))
{
System.out.println("Try Again");
return;
}
if(op==1)
{
if(n>=5)
{
fare=120*n;
disc=(fare*0.25);
fare=fare-disc;
}
else{
fare=120*n;
}
}
if(op==2)
{
if(n>=5)
{
fare=120*n;
disc=(fare*0.17);
fare=(120*n)-disc;
}
else{
fare=n*120;
}
}
if(op==3)
{
if(n>=5)
{
fare=120*n;
}
}
System.out.print("Dear "+name+" your bill amount is ");
System.out.printf("%.2f",fare);
}
}

32.Speed Calculation
public class SpeedCalculation {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the distance in kilometres");
int dis=sc.nextInt();
if(dis<0)
{
System.out.println("Invalid input");
return;
}
System.out.println("Enter the time to reach in hours");
int hour=sc.nextInt();
if(hour<0)
{
System.out.println("Invalid input");
return;
}
int speed=dis/hour;
if(speed>30)
{
int ini_sp=speed-30;
System.out.println("You want to increase a speed "+ini_sp+" km/hr from a normal
speed");
}
else{
System.out.println("You drive a car at a normal speed");
}
}
}

33.Odd Position Char will be in uppercase and even position will be


in lowercase.
import java.util.Scanner;
public class UPLC{
public static void main(String []args){
Scanner sc = new Scanner(System.in);
String str = sc.next();
int strlen = str.length();
for(int i = 0 ; i < str.length(); i++){
char ch = str.charAt(i);
if(!(ch >= 'a' && ch <='z' || ch >= 'A' && ch <='Z' )){
System.out.println(str+ " is an invalid input");
return;
}
}
if(strlen >= 5 && strlen <= 20){
StringBuffer updateString = new StringBuffer();
char[] charArr = str.toCharArray();
for(int i = 0 ; i < charArr.length; i++){
char ch = charArr[i];
if(i % 2 != 0){
ch = Character.toUpperCase(ch);
}
updateString.append(ch);
}
System.out.println(updateString.toString());
}
else {
System.out.println(str+ " is an invalid Length");
}
}
}
34. Adam’s Conviction
public class AdamGame {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
String str=sc.nextLine();
int len=str.length();
int count=0;
if(len<=2)
{
System.out.println("Invalid Input");
return;
}
if(str.matches("[hHtT]*"))
{
String s=str.toLowerCase();
for(int i=0;i<len-2;i++) {
if ((s.charAt(i) != s.charAt(i + 1)) && (s.charAt(i) == s.charAt(i + 2))) {
count++;
}
}
if(count==len-2)
{
System.out.println("Team will win");
}
else{
System.out.println("Team will loose");
}
}
else{
System.out.println("Invalid input");
return;
}
}
}

35.Next Missing Letter


import java.util.*;
public class Main {
static boolean flag = true;
public static void main(String[] arg) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the String");
String input = sc.next().toLowerCase();
String str = "abcdefghijklmnopqrstuvwxyz";
str = str + str ;
char[] arr = input.toCharArray();
Arrays.sort(arr);
String msg = "";
for(int i = 0;i<arr.length ; i++)
msg = msg + arr[i];
if ( ! msg.equalsIgnoreCase(input) )
flag = false;
System.out.println("Enter the Sequence time");
int seq = sc.nextInt();
if( seq>0)
{
int diff=0, min=0;
for(int i=1 ; i<input.length() ; i++)
{
if(i==1)
diff = Math.abs((int)input.charAt(i-1) - (int)input.charAt(i));
else
{
min = Math.abs((int)input.charAt(i-1) - (int)input.charAt(i));
if( min != diff)
{
System.out.println(input+" not in correct sequence");
return;
}
}
}
if(flag) // input is in ascending order
{
int index = str.indexOf(input.charAt(input.length() - 1));
for(int i=0 ; i<seq ; i++)
{
System.out.print(str.charAt(index+diff));
index = index+diff;
}
}
else // input is in descending order
{
int index = str.lastIndexOf(input.charAt(input.length() - 1));
for(int i=0 ; i<seq ; i++)
{
System.out.print(str.charAt(index-diff));
index = index-diff;
}
}
}
else
System.out.println(seq+" is invalid");
}
}
JAVA

1. LCM OF DAY INTERVAL/LUNCH TOGETHER/DINNER TOGETHER

INPUT: Enter the day interval of Tony : 4


Enter the day interval of Potts: 6

OUTPUT: Tony and Potts will have dinner together on 12th day.

import java.util.Scanner;
public class lcm {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the day interval of Sam:");
int n1 = sc.nextInt();
System.out.println("Enter the day interval of Riya:");
int n2 = sc.nextInt();
if(n1<=0 || n2<=0)
{
System.out.println("Given interval is not valid");
return;
}
int lcm;
lcm = (n1 > n2) ? n1 : n2;
while(true) {
if( lcm % n1 == 0 && lcm % n2 == 0 ) {
System.out.printf("Sam and Riya will have their dinner on day "+lcm);
break;
}
++lcm;
}
}
}

ALTERNATE METHOD

import java.util.Scanner;
public class Lunchlcm {
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the day interval of Tony");
int n1=sc.nextInt();
System.out.println("Enter the day interval of Potts");
int n2=sc.nextInt();
if(n1<=0 && n2<=0)
{
System.out.println("Given interval is not valid");
return;
}
int a=n1;
int b=n2;
while(n2>0)
{
if (n1 > n2)
{
n1 = n1 - n2;
} else
{
n2 = n2 - n1;
}
}
int gcd = n1;
int lcm = (a * b) / gcd;

System.out.println("Tony and Potts will have lunch together on " + lcm + " day");
}
}

*********************************************************************************************
*********************************************************************************************
**
2.SCORE OF REPEATING WORDS/ WORD REPETITION

INPUT: Enter the String: GOOD


Enter the sentence: GOOD FOOD GOOD LIFE

OUTPUT: Score is 2

import java.util.*;
class PrintMessage
{
public static void main (String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the string");
String s=sc.next();
int count=0;
int sum=2;
for(int i=0;i<s.length();i++)
{
if(Character.isDigit(s.charAt(i)) || Character.isLetter(s.charAt(i)) || s.charAt(i)==' ')
{
continue;
}
else
{
System.out.println(s+" is not valid String");
return;
}
}
System.out.println("Enter the sentence");
sc.nextLine();
String sentence=sc.nextLine();
String[] w=sentence.split(" ");
for(int i=0;i<w.length;i++)
{
if(w[i].equalsIgnoreCase(s))
{
count++;
if(count>2)
{
sum=sum*2;
}
}
}
if(count>2)
{
System.out.println("Score is "+sum);
}
else
{
System.out.println("Score is"+count);
}
}
}

*ALTERNATE METHOD

import java.util.Scanner;
public class CountWords {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String word, sentence;ed
int count = 0;
System.out.println("Enter a word:");
word = in.nextLine();
System.out.println("Enter a sentence");
sentence = in.nextLine();

if (!(word.matches("[a-z]+"))) {
System.out.println("Invalid Input");
return;
}
String words[] = sentence.toLowerCase().split(" ");
for (int i = 0; i < words.length; i++) {
if (word.equals(words[i])) {
count++;
}
}
System.out.println("Score is:" + ((int) Math.pow(2, count - 1)));
}
}
*********************************************************************************************
*********************************************************************************************
***

3. BATTERY CAPACITY

INPUT: Enter battery capacity :1230


Enter charging current value: 400

OUTPUT: 3.69 Hours

import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter battery capacity:");
double capacity = sc.nextDouble();
if(!(capacity>=1000 && capacity<=10000)) {
System.out.println("Invalid battery capacity");
return;
}
System.out.println("Enter charging current value:");
double current = sc.nextDouble();
if(!(current>=300 && current<=2100)) {
System.out.println("Invalid output current");
return;
}
double time=0.0f;
time = (capacity/current)*1.2;
System.out.println(String.format("%.2f",time)+" Hours");
}

*********************************************************************************************
*********************************************************************************************
***
4.STUDENTS WHOSE ROLLNO ARE ODD

INPUT: Entr the set of students :5


Enter the roll number :1
3
4
5
6

OUTPUT: 135

import java.util.*;
public class Main
{
public static void main(String[] args) {
System.out.println("Enter the set of students");
Scanner s=new Scanner(System.in);
int setn=s.nextInt();
if(setn<=0)
{
System.out.println(setn+" is an invalid size");
return;
}
System.out.println("Enter the roll number");
int[] rolls=new int[setn];
int oddflag=0;
for(int i=0;i<setn;i++)
{
rolls[i]=s.nextInt();
if(rolls[i]<0)
{
System.out.println(rolls[i]+" is an invalid roll number");
return;
}
if(rolls[i]%2!=0)
{
oddflag=1;
}
}
if(oddflag==0)
{
System.out.println("The "+setn+" numbers are not odd");
return;
}
String str="";
for(int i=0;i<setn;i++)
{
if(rolls[i]%2!=0)
{
str=str+rolls[i];
}
}
for(int n=0;n<str.length();n++)
{
System.out.println(str.charAt(n)+" ");
}
}
}
*********************************************************************************************
*********************************************************************************************
**

5.CALCULATING BILL AMOUNT

INPUT : Enter your name : Sam


Enter the time duration: 13
List of payment options
1)Visa card
2)Rupay card
3)Master card
Choose an option : 2

OUTPUT: Dear Sam your bill amount is 1294.80

import java.util.*;
public class Main
{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter your name");
String s=sc.nextLine();double sal=0;double disc=0;
for(int i=0;i<s.length();++i)
{
if(!Character.isLetter(s.charAt(i)))
{
System.out.println("Invalid Name");
return;
}
}
System.out.println("Enter the time duration");
int n=sc.nextInt();int n1;
if(n<=0 || n>24)
{
System.out.println("Invalid duration");
return;
}
System.out.println("List of payment options");
System.out.println("1)Visa card");
System.out.println("2)Rupay card");
System.out.println("3)Master card");
System.out.println("Chosse an option");
while(true)
{
n1=sc.nextInt();
if(n1<0||n1>3)
{
System.out.println("Try again");
}
else
{
break;
}
}
if( n1==1)
{
if(n>=5)
{
sal=120*n;
disc=(sal*0.25);
sal=sal-disc;
}
else
{
sal=n*120;
}
}
if(n1==2)
{
if(n>=5)
{
sal=120*n;
disc=(sal*0.17);
sal=(120*n)-disc;
}
else
{
sal=n*120;
}
}
if(n1==3)
{
sal=n*120;
}
System.out.print("Dear "+s+" your bill amount is ");
System.out.printf("%.2f", sal);
}
}

*********************************************************************************************
*********************************************************************************************
***
6.ODD POSITION CHAR WILL BE IN UPPERCASE & EVEN WILL BE LOWERCASE-

INPUT : school

OUTPUT : sChOol

import java.util.Scanner;
public class UPLC{
public static void main(String []args){
Scanner sc = new Scanner(System.in);
String str = sc.next();
int strlen = str.length();
for(int i = 0 ; i < str.length(); i++){
char ch = str.charAt(i);
if(!(ch >= 'a' && ch <='z' || ch >= 'A' && ch <='Z' )){
System.out.println(str+ " is an invalid input");
return;
}
}

if(strlen >= 5 && strlen <= 20){


StringBuffer updateString = new StringBuffer();
char[] charArr = str.toCharArray();
for(int i = 0 ; i < charArr.length; i++){
char ch = charArr[i];
if(i % 2 != 0){
ch = Character.toUpperCase(ch);
}
updateString.append(ch);
}
System.out.println(updateString.toString());
}
else {
System.out.println(str+ " is an invalid Length");
}
}
}

*********************************************************************************************
*********************************************************************************************
****
7) RATING SCORE

INPUT: ENTER JESSON SCORE


1
2
3
4
8
ENTER JAMES SCORE
0
2
6
5
6

OUTPUT: JESSON SCORE : 2


JAMES SCORE : 2

import java.util.Scanner;
public class Ratingscore {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter Jesson Score");
int[] a1 = new int[5];
int[] a2 = new int[5];
int f = 0;
int t = 0;
int sum = 0;
int sum1 = 0;
for (int i = 0; i < 5; i++) {
a1[i] = sc.nextInt();
if (a1[i] < 0) {
f = 1;
t = a1[i];
break;
}
}
if (f == 1) {
System.out.println(t + " is invalid");
} else {
System.out.println("Enter James Score");
for (int j = 0; j < 5; j++) {
a2[j] = sc.nextInt();
if (a2[j] < 0) {
f = 1;
t = a2[j];
break;
}
}
if (f == 1) {
System.out.println(t + " is invalid");
} else {
for (int k = 0; k < 5; k++) {
if (a1[k] > a2[k]) {
sum++;
}
if (a1[k] < a2[k]) {
sum1++;
}
}
System.out.println("Jesson Score");
System.out.println(sum);
System.out.println("James Score");
System.out.println(sum1);
}
}
}
}

**ALTERNATE METHOD:

import java.util.Scanner;
public class minmax {
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
int jesson=0,james=0,c=0;
int a[]=new int[5];
int b[]=new int[5];
System.out.println("Enter Jesson Score");
for(int i=0;i<a.length;i++)
{
a[i]=sc.nextInt();
if(a[i]<0)
{
System.out.println("Invalid");
Runtime.getRuntime().halt(0);
}
}
System.out.println("Enter James Score");
for(int i=0;i<b.length;i++)
{
b[i]=sc.nextInt();
if(b[i]<0)
{
System.out.println("Invalid");
Runtime.getRuntime().halt(0);
}
}
if(a.length==b.length)
{
for(int i=0;i<a.length;i++)
{
if(a[i]>b[i])
{
jesson++;
}
else if(a[i]<b[i])
{
james++;
}
else if(a[i]==b[i])
{
c++;
}
}
System.out.println("Jesson Score: "+jesson);
System.out.println("James Score: "+james);
}
else{
System.out.println("Length not same");
}
}
}

*********************************************************************************************
*******************************************************************************

8.COUNT OF UPPERCASE AND COUNT OF LOWERCASE & OUTPUT WILL BE IN THE FORM OF (UP-LC
)

INPUT : HosTEL

OUTPUT: 4-2=2

import java.util.Scanner;

public class ContNext {


public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the string");
String str=sc.nextLine();
int uc=0,lc=0;
if(str.matches("[A-Za-z ]+")&&str.length()<10) {
for(int i=0;i<str.length();i++)
if(Character.isUpperCase(str.charAt(i))) {
uc++;
}
else if(Character.isLowerCase(str.charAt(i))){
lc++;
}
System.out.println(uc-lc);
}
}
}
*********************************************************************************************
*******************************************************************************
9) PRODUCT of COUNT of UPPERcase and LOWERcase letters

INPUT: ABsdEr

OUTPUT: 6 (3*3)

import java.util.Scanner;
public class minmax {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the String");
String s = sc.nextLine();
int upper = 0;
int lower = 0;
int i;
if (s.matches("[a-zA-Z]+")) {
for (i = 0; i < s.length(); i++) {
char c = s.charAt(i);
if (c >= 'A' && c <= 'Z') {
upper++;
}
if (c >= 'a' && c <= 'z') {
lower++;
}
}
System.out.println(upper * lower);
}
else
{
System.out.println("Invalid String");
}

}
}

*********************************************************************************************
******************************************************************************
10.Count of UPPERcase and LOWERcase and their difference

Enter the String: ColLEgE


Count of uppercase is : 4
Count of lowercase is : 3
Hence the ans is : 1

import java.util.Scanner;
public class MyClass {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the String ");
String str = sc.next();
int strlen = str.length();

for(int i =0; i < str.length() ; i++){ char


ch = str.charAt(i);
if(!(ch >='a' && ch <= 'z' || ch >= 'A' && ch <= 'Z')){
System.out.println(str + " is an invalid String");
return;
}
}

if(strlen > 0 && strlen <= 10){


int upper = 0, lower = 0, ans = 0;

for(int i = 0; i < str.length(); i++)


{
char ch = str.charAt(i);
if (ch >= 'A' && ch <= 'Z')
upper++;
else if(ch >= 'a' && ch <= 'z')
lower++;
}
ans = upper - lower;
System.out.println("count of uppercase is :"+ upper);
System.out.println("count of lowercase is :"+ lower);
System.out.println("Hence the ans is :"+ ans);
}
else {
System.out.println(str + " is an invalid String");
}
}
}
*********************************************************************************************
*******************************************************************************
11.PUBLIC DISTRIBUTION

INPUT : OKR

OUTPUT : 90

import java.util.*;
public class Main
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
String str = in.nextLine();
int l=str.length();
if(l>5 || l<2)
{
System.out.println("Invalid Input");
}
else
{
int sum=0,flag=0;
for(int i=0;i<l;i++)
{
char c=str.charAt(i);
if(c=='O')
{
sum=sum+24;
}
else if(c=='K')
{
sum=sum+36;
}
else if(c=='S')
{
sum=sum+42;
}
else if(c=='R')
{
sum=sum+30;
}
else if(c=='W')
{
sum=sum+44;
}
else
{
flag=1;
}
}
if(flag==1)
{
System.out.println("Invalid Input");
}
else
{
System.out.println(sum);
}
}
}
}
*********************************************************************************************
******************************************************************************

12.LOTTERY TICKETS

INPUT: Enter the Starting range


23467
Enter the Ending range
23477

OUTPUT: 23469
23472

import java.util.*;
public class Main {
public static void main(String args[])
{
int i,c,n,sum,count;
sum=0;count=0;n=0;c=0;i=0;
Scanner sc = new Scanner(System.in);
System.out.println("Enter the Starting range");
int a = sc.nextInt();
String str = Integer.toString(a);
if(str.length()!=5)
{
System.out.println(str + " is an invalid input");
System.exit(0);
}

System.out.println("Enter the Ending range");


int b = sc.nextInt();
String str1 = Integer.toString(b);
if(str1.length()!=5)
{
System.out.println(str1 + "is an invalid input");
System.exit(0);
}

if(a>b)
{
System.out.println(a+" and "+b+" are invalid serial numbers");
System.exit(0);

}
for(i=a;i<=b;i++)
{
n=i;
while(n!=0)
{
c=n%10;
sum=sum+c;
n=n/10;
}
if((sum%3==0)&&((sum/3)%2==0))
{
System.out.println(i + " ");
count++;
}
sum=0;
}
if(count==0)
{
System.out.println("Eligible tickets are not available from "+a+" to "+b);
System.exit(0);
}
}
}

*********************************************************************************************
******************************************************************************
13.COFFEE STALL NUMEROLOGY

INPUT : Enter the Staff Name


Coffee Bar

OUTPUT : Coffee Bar satisfies the numerology logic

import java.util.*;
public class Main{
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the Staff Name");
String name = sc.nextLine();
int count=0;
for(int i=0;i<name.length();i++){
if(Character.isAlphabetic(name.charAt(i)) || name.charAt(i)==' '){
count++;
}
}
if(count==name.length()){
String str = name.replace(" ","");
int sum=0;
for(int i=0;i<str.length();i++){
sum += i;
}
if(sum%2==0){
System.out.println(name+" satisfies the numerology logic");
}else{
System.out.println(name+" does not satisfy the numerology logic");
}
}else{
System.out.println("Invalid Input");
}
}
}

*ALTERNATE METHOD USING -matches for same question

import java.util.*;
public class Main{
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the Staff Name");
String name = sc.nextLine();
if(name.matches("[a-zA-Z ]+")){
String str = name.replace(" ","");
int sum=0;
for(int i=0;i<str.length();i++){
sum += i;
}
if(sum%2==0){
System.out.println(name+" satisfies the numerology logic");
}else{
System.out.println(name+" does not satisfy the numerology logic");
}
}else{
System.out.println("Invalid Input");
}
}
}

*ALTERNATE METHOD

import java.util.Scanner;
public class CoffeeHouse {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the Stall Name");
String name = sc.nextLine();
if (name.matches("^[A-Za-z ]*$")) {
int sum = 0;
String fName = name.replaceAll(" ", "");
for (int i = 0; i < fName.length(); i++)
sum = sum + i;
if (sum % 2 == 0) {
System.out.println(name + " satisfies the numerology logic");
} else {
System.out.println(name + " not satisfies the numerology logic");
}
} else
System.out.println("Invalid Input");
}
}

*********************************************************************************************
******************************************************************************

14.ANAGRAM OR TWO WORDS OF SAME LETTER

INPUT : cat
act

OUTPUT: Same

import java.util.Arrays;
import java.util.Scanner;
public class minmax {
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter sentence 1");
String s1=sc.next();
s1=s1.toLowerCase();
System.out.println("Enter sentence 2");
String s2=sc.next();
s2=s2.toLowerCase();
if(s1.length()!=s2.length())
{
System.out.println("Invalid");
}
if(s1.matches("^[a-zA-Z]*")){
char c1[] = s1.toLowerCase().toCharArray();
char c2[] = s2.toLowerCase().toCharArray();
Arrays.sort(c1);
Arrays.sort(c2);
if (Arrays.equals(c1, c2)) {
System.out.println(s1 + " and " + s2 + " contain the same characters");
} else {
System.out.println(s1 + " and " + s2 + " contain the different characters");
}
}
else
{
System.out.println("Invalid");
}
}
}

ALTERNATE METHOD:

import java.util.*;
public class Main{
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
String first=sc.next();
String secound=sc.next();
String word1=Main.checker(first);
String word2=Main.checker(secound);
if(word1.equals(word2)){
System.out.println("Same");
}else{
System.out.println("Different");
}
}
public static String checker(String word){
char arr[]=word.toCharArray();
Arrays.sort(arr);
int index=0;
for(int i=0;i<arr.length;i++){
int j;
for(j=0;j<i;j++){
if(arr[j]==arr[i]){
break;
}
}
if(i==j){
arr[index++]=arr[i];
}
}
char arr1[]=Arrays.copyOf(arr,index);
String newword= new String(arr1);
return newword;
}
}

ALTERNATE METHOD

import java.util.*;
public class arraysquare {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int f1=0,f2=0;
String s1=sc.nextLine();
char c1[]=s1.toCharArray();
String s2=sc.nextLine();
char c2[]=s2.toCharArray();
for(int i=0;i<c1.length;i++)
{
f1=0;
for(int j=0;j<c2.length;j++)
{
if(c1[i]==c2[j])
{
f1=1;
break;
}
}
if(f1==0)
{
break;
}
}
for(int i=0;i<c2.length;i++)
{
f2=0;
for(int j=0;j<c1.length;j++)
{
if(c2[i]==c1[j])
{
f2=1;
break;
}
}
if(f2==0)
{
break;
}
}
if(f1==1 && f2==1)
{
System.out.println("Same Char");
}
else{
System.out.println("Different char");
}
}
}

*********************************************************************************************
*****************************************************************************
15.SUMMATION OF EVEN NUMBERS IN THE ARRAY

INPUT : Enter array size


4
Enter array elements in 1st array
2
4
6
8
Enter array elements in 2nd array
1
2
5
2

OTPUT: 0
6
0
10

import java.util.*;
public class Main
{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter array size");
int n=sc.nextInt();
if(n>=10 || n<1)
{
System.out.println(n+" is an invalid input");
Runtime.getRuntime().halt(0);
}
int arr1[]=new int[n];
int arr2[]=new int[n];
int result[]=new int[n];
System.out.println("Enter array elements in 1st array");
for(int i=0;i<n;i++)
{
arr1[i]=sc.nextInt();
}
System.out.println("Enter array elements in 2nd array");
for(int i=0;i<n;i++)
{
arr2[i]=sc.nextInt();
}
//PROGRAM LOGIC
int count=0;
for(int i=0;i<n;i++)
{
if((arr1[i]%2==0 || arr1[i]==0) && (arr2[i]%2==0 || arr2[i]==0))
{
result[i]=arr1[i]+arr2[i];
count++;
}
else
{
result[i]=0;
}
}
if(count==0)
{
System.out.println("No even number is present in an Array");
}
for(int i=0;i<n;i++)
{
System.out.println(result[i]);
}
}
}

*********************************************************************************************
******************************************************************************
16.RUNNERS COMPETITION

INPUT :Enter the number of runners


5

Enter the runner details


Robert,9.38
Richard,9.35
Christiano,9.35
Williams,9.36
Vinix,9.35

OUTPUT: Richard
Christiano
Vinix

import java.util.*;
public class Main{
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
sc.useDelimiter("\n");
System.out.println("Enter the number of runners");
int n = sc.nextInt();
if(n<=0 || n>10){
System.out.println(n+" is an invalid number of runners");
Runtime.getRuntime().halt(0);
}
String temp = "";
String name[] = new String[n];
float time[] = new float[n];
System.out.println("Enter the runner details");
for(int i=0;i<n;i++){
temp = sc.next();
String temparr[] = temp.split(",");
name[i] = temparr[0];
time[i] = Float.parseFloat(temparr[1]);
if(time[i]>12 || time[i]<8){
System.out.println(time[i]+" is an invalid input");
Runtime.getRuntime().halt(0);
}
}
int maxcount = 0;
float maxrep = 0;
for(int i=0;i<n;i++){
int count = 0;
for(int j=i+1;j<n;j++){
if(time[i]==time[j]){
count++;
}
}
if(count>=maxcount){
maxcount = count;
maxrep = time[i];
}
}
if(maxcount==n){
System.out.println(n+" runners have same timing");
}
else if(maxcount==0){
System.out.println("No runners with same time.");
}
else{
for(int i=0;i<n;i++){
if(maxrep == time[i]){
System.out.println(name[i]);
}
}
}
}
}
*********************************************************************************************
******************************************************************************

17.REEDME

INPUT : Enter the customer name


Abi
Enter the category
History
Enter the quantity of books ordered
2900

OUTPUT : Total cost is 334080.0


import java.util.*;
public class Main{
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the customer name");
String name = sc.nextLine();
System.out.println("Enter the category");
String category = sc.nextLine();
category = category.toLowerCase();

if(!category.equals("adventure") && !category.equals("comics") && !category.equals("history") && !categ


ory.equals("thriller")){
System.out.println(category+" is invalid category");
Runtime.getRuntime().halt(0);
}
System.out.println("Enter the quantity of books ordered");
int quantity = sc.nextInt();
if(quantity <= 0){
System.out.println(quantity+" is an invalid quantity");
Runtime.getRuntime().halt(0);
}
int discount = 0;
int price = 0;
if(category.equals("adventure")){
price = 150;
if(quantity>=1700)
discount = 5;
}
else if(category.equals("comics")){
price = 230;
if(quantity>=1950)
discount = 5;
}
else if(category.equals("history")){
price = 120;
if(quantity>=2600)
discount = 4;
}
else if(category.equals("thriller") && quantity>=1700){
price = 190;
if(quantity>=6300)
discount = 3;
}
float totalcost = (price*quantity) - (price*quantity*discount/100);
System.out.println("Total cost is "+totalcost);
}
}

*********************************************************************************************
******************************************************************************
18. HARSHAD NUMBER (Sum of digit completely divide that number)

For example: 18= 1+8=9 and in 18/9 remainder is 0


INPUT: Enter array size: 5
Enter array elements : 18 14 12 24 13

OUTPUT: 18 12 24

import java.util.Scanner;
public class Harshad {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the number of values");
int n = sc.nextInt();
int i;
System.out.println("Enter the numbers");
int[] a = new int[n];
if (n > 0)
{
int flag = 0;
int k = 0;
for (i = 0; i < n; i++)
{
k = sc.nextInt();
if (k > 9)
a[i] = k;
else
{
flag = 1;
break;
}
}
if (flag != 1)
{
int c = 0;
for (i = 0; i < n; i++)
{
int x = a[i];
int sum = 0;
do {
int r = x % 10;
sum = sum + r;
x = x / 10;
}
while (x != 0);
if (a[i] % sum == 0)
{
c++;
System.out.println(a[i]);
}
}
if (c == 0)
System.out.println("The " + n + " values are not harshad number");
}
else
System.out.println("Provided " + k + " is not valid");
} else
System.out.println(n + " is an invalid input");
}
}

ALTERNATE METHOD:

import java.util.Scanner;
class Main
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number of values");
int n=sc.nextInt();
System.out.println("Enter the numbers");
int a[]=new int[n];
if(n>0)
{
int flag=0;
int k=0;
for(int i=0;i<n;i++)
{
k=sc.nextInt();
if(k>9) a[i]=k; else
{
flag=1;
break;
}
}
if(flag!=1)
{
int c=0;
for(int i=0;i<n;i++)
{
int x=a[i];
int sum=0;
do
{
int r=x%10; sum=sum+r; x=x/10;
}while(x!=0);
if(a[i]%sum==0)
{ c++;
System.out.println(a[i]);
}
}
if(c==0)
System.out.println("The "+n+" values are not harshad number");
}else
System.out.println("Provided "+k+" is not valid");
}else
System.out.println(n+" is an invalid input");
}
}
*********************************************************************************************
*********************************************************************************************
*******
19. IDEO GAME (PS1)

INPUT : Enter the amount


18000
Enter the Video Game Player Type
PS4

OUTPUT: You can buy PS4

public class PS {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the amount");
int amount = sc.nextInt();
if (amount >= 3000) {
System.out.println("Enter the Video Game Player Type");
String type = sc.next();
if (type.matches("[P][S][1-5]")) {
if (type.equals("PS1")) {
if (amount >= 5000) {
System.out.println("You can buy PS1");
} else {
System.out.println("You need more money to buy a PS1");
}
} else if (type.equals("PS2")) {
if (amount >= 7800) {
System.out.println("You can buy PS2");
} else {
System.out.println("You need more money to buy a PS2");
}
} else if (type.equals("PS3")) {
if (amount >= 9500) {
System.out.println("You can buy PS3");
} else {
System.out.println("You need more money to buy a PS3");
}
} else if (type.equals("PS4")) {
if (amount >= 12000) {
System.out.println("You can buy PS4");
} else {
System.out.println("You need more money to buy a PS4");
}
} else if (type.equals("PS5")) {
if (amount >= 15000) {
System.out.println("You can buy PS5");
} else {
System.out.println("You need more money to buy a PS5");
}
}
} else {
System.out.println(type + " is Invalid Type");
}
} else {
System.out.println(amount + " is too less");
}
}
}

*********************************************************************************************
*********************************************************************************************
****
20.ALTERNATE SUM DIFFERENCE

INPUT :Enter number


6
Enter values
12
13
6
8
9
7
(((( logic: (12-7=a
13-9=b
6-8=c
a+b+c=ans)))))

OUTPUT 2
3
4
5
5-2=3
4-3=1
So 3+1= 4
*/

import java.util.*;
public class AltDiff {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int sum=0;
int n=sc.nextInt();
int a[]=new int[n];
for(int i=0;i<n;i++)
{
a[i]=sc.nextInt();
}
for(int i=0;i<n/2;i++)
{
sum+=Math.abs(a[i]-a[n-i-1]);
}
System.out.println(sum);
}
}
*********************************************************************************************
*********************************************************************************************
*****
21.CHARACTER ADD

INPUT : Enter : 3
Enter the sentences:
ks436
Agh73
7222

OUTPUT: 222
240
0

import java.util.*;
public class arraysquare{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int sum=0;
System.out.println("Enter:");
int n=sc.nextInt();
if(n<=0)
{
System.out.println("The number of sentences "+n+" is invalid");
return;
}
System.out.println("Enter the sentences:");
String str[]=new String[n];
for(int i=0;i<n;i++)
{
str[i]=sc.next();
}
for(int i=0;i<str.length;i++)
{
String s=str[i].replaceAll("[0-9]","");
for(int j=0;j<s.length();j++)
{
char c=s.charAt(j);
int ascii=c;
sum+=ascii;
}
System.out.println(sum);
sum=0;
}

}
}

*********************************************************************************************
*********************************************************************************************
******
22.MIDDLE LETTER/Reverse first half of the string if string length is ODD

Input:
if length of string is even, the reverse the string:
Ex: Food
Output:
dooF

Input:
If length of the string is odd,then find the middle char and then ,reverse the string till mid char and print remain char
acters as it is.
Ex: Samsung
Output:
maSsung

package FinalAss;
import java.util.*;
public class MidLett {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
String str=sc.nextLine();//rahul
int len=str.length();
if(len%2==0)
{
StringBuilder sb=new StringBuilder(str);
sb.reverse();
System.out.println(sb.toString());
}
else if(len%2!=0)
{
System.out.println("Length of string is " +len);
int mid=len/2;
mid++;
System.out.println("Substring of string is "+mid);
String substr=str.substring(0,mid-1);
String remainSub=str.substring(mid-1,len);
StringBuilder sb=new StringBuilder(substr);
sb.reverse();
System.out.println(sb.toString()+remainSub);

}
}
}

ALTERNATE METHOD:::

import java.util.Scanner;
import java.util.regex.Pattern;
public class minmax {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
String str=sc.nextLine();//rahul
if(!Pattern.matches("[A-Za-z]+",str))
{
System.out.println(str+" is not a valid string");
return;
}
else if(str.length()<2)
{
System.out.println("Size of string "+str.length()+" is too small");
return;
}
int len=str.length();
if(len%2==0)
{
StringBuilder sb=new StringBuilder(str);
sb.reverse();
System.out.println(sb.toString());
}
else if(len%2!=0)
{
int mid=len/2;
String substr=str.substring(0,mid);
String remainSub=str.substring(mid,len);
StringBuilder sb=new StringBuilder(substr);
sb.reverse();
System.out.println(sb.toString()+remainSub);

}
}
}

*********************************************************************************************
*********************************************************************************************
*****

23 .ONLINE SHOPPING

input:
enter the product
laptop
Actual price
45000
exchange?
yes
bill amount:
27000.00

import java.util.*;
public class arraysquare {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the Product:");
String prod=sc.nextLine();
int ed=0,pd=0;
if(prod.equals("Mobile"))
{
ed=15;
pd=15;
}
else if(prod.equals("Laptop"))
{
ed=20;
pd=20;
}
else if(prod.equals("Headset"))
{
ed=0;
pd=10;
}
else if(prod.equals("Charger"))
{
ed=0;
pd=5;
}
else{
System.out.println("Not available");
return;
}
System.out.println("Enter the actual Price: ");
int price=sc.nextInt();
if(price<100)
{
System.out.println("Invalid Price");
return;
}
System.out.println("Do u want to Exchange?");
String exc=sc.next();
if(exc.equals("Yes") || exc.equals("yes"))
{
double ap=price-(price*pd)/100;
double ev=(price*ed)/100;
double total=ap-ev;
System.out.printf("Total=%.2f",total);
}
else if(exc.equals("No") || exc.equals("no"))
{
double total=price-(price*pd)/100;
System.out.printf("Total=%.2f",total);
}
else
{
System.out.println("Invalid Option");
}
}
}

*********************************************************************************************
*********************************************************************************************
*****
24 .OPERATOR FOUND

input:
45
23

22
output
45-23=22

import java.util.*;
public class arraysquare {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter n1 and n2:");
int n1=sc.nextInt();
if(n1>0)
{
int n2=sc.nextInt();
if(n2>0)
{
System.out.println("Enter n3:");
int n3=sc.nextInt();
if(n3>0)
{
if(n1+n2==n3)
{
System.out.println(n1+"+"+n2+"="+n3);
}
else if(n1-n2==n3)
{
System.out.println(n1+"-"+n2+"="+n3);
}
else if(n1*n2==n3)
{
System.out.println(n1+"*"+n2+"="+n3);
}
else if(n1/n2==n3)
{
System.out.println(n1+"/"+n2+"="+n3);
}
else
{
System.out.println(n3+" is an invalid answer");
}
}
else{
System.out.println("Invalid");
}
}
else{
System.out.println("Invalid");
}
}
else{
System.out.println("Invalid");
}

}
}

*********************************************************************************************
*********************************************************************************************
****

25 .PRODUCT EQUAL SUM

INPUT : Enter the array size


4
Enter the elements of the first array
12
35
56
34
Enter the elements of the second array
261
195
112
813
OUTPUT: 35,195
34,813

import java.util.*;
public class arraysquare
{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the array size");
int n=sc.nextInt();
if(n<=0)
{
System.out.println("Invalid array size");
return;
}
int a[]=new int[n];
System.out.println("Enter the elements of the first array");
for(int i=0;i<n;i++)
{
a[i]=sc.nextInt();
}
System.out.println("Enter the elements of the second array");
int b[]=new int[n];
for(int i=0;i<n;i++)
{
b[i]=sc.nextInt();
}
int x[]=new int[n];
int y[]=new int[n];
for(int i=0;i<n;i++)
{
int c=a[i];
int prod=1;
while(c!=0)
{
prod*=(c%10);
c/=10;
}
x[i]=prod;
prod=0;
}
for(int i=0;i<n;i++)
{
int s=b[i];
int sum=0;
while(s!=0)
{
sum+=(s%10);
s/=10;
}
y[i]=sum;
sum=0;
}
for(int i=0;i<n;i++)
{
if(x[i]==y[i])
{
System.out.println(a[i]+","+b[i]);
}
}
}
}

*********************************************************************************************
*********************************************************************************************
*

26. UNIQUE CHAR

input:
LIfe is inherently risky

output:
life is ihrtly risky

package FinalAss;
import java.util.*;
public class nonuniquetwo {
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
String sentence = sc.nextLine();
String[] words = sentence.split(" ");
for(String word : words)
{
System.out.print(getUnique(word) + " ");
}
sc.close();
}
public static String getUnique(String str)
{
StringBuffer sb = new StringBuffer();
for(int i = 0; i<str.length(); i++)
{
if(countFrequency(str.charAt(i), str) == 1)
{
sb.append(str.charAt(i));
}
}
String result = sb.toString();
return result;
}
public static int countFrequency(char c, String str)
{
int count = 0 ;
for(int i = 0; i<str.length(); i++)
{
if(str.charAt(i) == c)
{
count++;
}
}
return count;
}
}

*********************************************************************************************
*********************************************************************************************
*
27. BOX SIZE

INPUT : Enter the box size


6
Enter the numbers
5
55
3
59
42
8
OUTPUT: 32 is even its a valid box

import java.util.Scanner;
public class minmax {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the box size");
int a=sc.nextInt();
if(a<=0)
{
System.out.println(a+" is an invalid box size");
return;
}
int b[]=new int[a];
int c=0,sum=0,temp=0;
System.out.println("Enter the numbers");
for(int i=0;i<a;i++)
{
b[i]=sc.nextInt();
if(b[i]<=0)
{
System.out.println(b[i]+" is an invalid input");
return;
}
}
for(int i=0;i<a;i++)
{
c=b[i]%10;
sum+=c;
c=0;
}
if(sum%2==0)
{
System.out.println(sum+" is even its a valid box");
return;
}
else
{
System.out.println(sum+" is odd its an invalid box");
return;
}

}
}
*********************************************************************************************
*********************************************************************************************
***

28. ORDER IDENTIFICATION:(check where elements are in ascending order)

INPUT : Enter the array size : 5


Enter the elements: 32
44
55
66
77

OUTPUT : 32 44 55 66 77 are in ascending order

import java.util.Arrays;
import java.util.Scanner;

public class orderidentification {


public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the array size");
int a=sc.nextInt();
if(a<2 || a>10)
{
System.out.println(a+" is not a valid array size");
return;
}
int b[]=new int[a];
int count=0;
System.out.println("Enter the elements");
for(int i=0;i<a;i++)
{
b[i]=sc.nextInt();
}
int d[]= Arrays.copyOf(b,b.length);
Arrays.sort(d);

if(Arrays.equals(b,d))
{
count++;
}
if(count>0)
{
for(int i=0;i<b.length;i++)
{
System.out.print(b[i]+" ");

}
System.out.print("are in ascending order");
return;
}
else
{
for(int i=0;i<a;i++)
{
System.out.print(b[i]+" ");
}
System.out.print("are not in ascending order");
return;
}
}
}
*********************************************************************************************
**************************************************************
29) DATE ,MONTH AND YEAR

INPUT:13081995

OUTPUT: date: 13
month: 08
year: 1998

import java.util.Scanner;
public class minmax {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
String str=sc.nextLine();
int n=str.length();
for(int i=0;i<str.length() ;i++)
{
if(!(str.charAt(i)>='0' && str.charAt(i)<='9'))
{
System.out.println("Invalid input");
return;
}
if(n!=8)
{
System.out.println("Enter valid date");
return;
}
}
String date=str.substring(0,2);
String mon=str.substring(2,4);
String year=str.substring(4,8);

System.out.println("date:"+date);
System.out.println("Month:"+mon);
System.out.print("Year:"+year);

}
}

*********************************************************************************************
*********************************************************************************************
*
30) MEGA MART CUSTOMER IDENTIFICATION(String and SUBSTRING)

import java.util.*;
public class arraysquare{
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the customer id");
String cid = sc.next();
String shop = cid.substring(0,4);
//System.out.println("shop");
if(!shop.equals("Mega")){
System.out.println("Invalid Shop Name");
Runtime.getRuntime().halt(0);
}
String type = cid.substring(4,cid.length()-3);
//System.out.println(type);
if(!type.equals("Silver") && !type.equals("Gold") && !type.equals("Platinum")){
System.out.println("Invalid Customer Type");
Runtime.getRuntime().halt(0);
}
int mid = Integer.parseInt(cid.substring(cid.length()-3,cid.length()));
//System.out.println(mid);
if(mid<=99 || mid>=1000){
System.out.println("Invalid Member id");
Runtime.getRuntime().halt(0);
}
System.out.println("Welcome Mega Mart "+type+" Customer");

}
}

*********************************************************************************************
***********************************
31) .MALE AND FEMALE COUNT

INPUT: MmFMff

OUTPUT: 3 MALE
3 FEMALE

import java.util.Scanner;
import java.util.regex.*;
public class minmax {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
String s=sc.nextLine();
int count1=0;
int count2=0;
if(Pattern.matches("[MmFf ]+",s)){
for (int i = 0; i < s.length(); i++) {
if (s.charAt(i) == 'M' || s.charAt(i) == 'm') {
count1++;
} else if (s.charAt(i) == 'F' || s.charAt(i) == 'f') {
count2++;
}
}
System.out.println(count1 + " Male");
System.out.println(count2 + " Female");
}
else
{
System.out.println("Invalid Input");
}
}
}
*********************************************************************************************
*********************************************************************************************
***
32. RAINFALL

INPUT: Enter the length of the roof in meters: 4


Enter the breadth of the roof in meters: 3
Enter the rainfall level: 3

OUTPUT: 360.00 Litres

import java.util.Scanner;
public class minmax {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
System.out.println("Enter the length of the roof in meters");
double l=sc.nextDouble();
if(l<=0)
{
System.out.println("Invalid Length");
return;
}
System.out.println("Enter the breadth of the roof in meters");
double b=sc.nextDouble();
if(b<=0)
{
System.out.println("Invalid breadth");
return;
}
System.out.println("Enter the rainfall level");
double r=sc.nextDouble();
if(r<=0)
{
System.out.println("Invalid rainfall");
return;
}
double h;
h=(l*b) *(r*10);
System.out.println(String.format("%.2f",h)+"Litres");
}
}

*********************************************************************************************
*********
33) NUMEROLOGY NAME CHECKING

import java.util.*;
import java.util.regex.Pattern;

public class arraysquare{


public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the name");
String a=sc.next();
if(!Pattern.matches("[A-Za-z]+",a))
{
System.out.println(a+" is an Invalid name");
return;
}
int sum=0;
char b[]=a.toCharArray();
for(int i=0;i<b.length;i++)
{
if(b[i]=='A'||b[i]=='a')
{
sum+=1;
}
else if(b[i]=='B'||b[i]=='b')
{
sum+=2;
}
else if(b[i]=='C'||b[i]=='c')
{
sum+=3;
}
else if(b[i]=='D'||b[i]=='d')
{
sum+=4;
}
else if(b[i]=='E'||b[i]=='e')
{
sum+=5;
}
else if(b[i]=='F'||b[i]=='f')
{
sum+=6;
}
else if(b[i]=='G'||b[i]=='g')
{
sum+=7;
}
else if(b[i]=='H'||b[i]=='h')
{
sum+=8;
}
else if(b[i]=='I'||b[i]=='i')
{
sum+=9;
}
else if(b[i]=='J'||b[i]=='j')
{
sum+=10;
}
else if(b[i]=='K'||b[i]=='k')
{
sum+=11;
}
else if(b[i]=='L'||b[i]=='l')
{
sum+=12;
}
else if(b[i]=='M'||b[i]=='m')
{
sum+=13;
}
if(b[i]=='N'||b[i]=='n')
{
sum+=14;
}
if(b[i]=='O'||b[i]=='o')
{
sum+=15;
}
if(b[i]=='P'||b[i]=='p')
{
sum+=16;
}
if(b[i]=='Q'||b[i]=='q')
{
sum+=17;
}
if(b[i]=='R'||b[i]=='r')
{
sum+=18;
}
if(b[i]=='S'||b[i]=='s')
{
sum+=19;
}
if(b[i]=='T'||b[i]=='t')
{
sum+=20;
}
if(b[i]=='U'||b[i]=='u')
{
sum+=21;
}
if(b[i]=='V'||b[i]=='v')
{
sum+=22;
}
if(b[i]=='W'||b[i]=='w')
{
sum+=23;
}
if(b[i]=='X'||b[i]=='x')
{
sum+=24;
}
if(b[i]=='Y'||b[i]=='y')
{
sum+=25;
}
if(b[i]=='Z'||b[i]=='z')
{
sum+=26;
}
}
System.out.println(sum);
if(sum%3==0 && sum%2==0)
{
System.out.println(a+" is a numerology name");
}
else
{
System.out.println(a+" is not a numerology name");
}
}
}

*******************************************************************************

34)OMR

import java.util.Scanner;
public class arraysquare{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int i;
System.out.println("Enter the No of questions");
int a=sc.nextInt();
if(a<0)
{
System.out.println("Invalid Number");
return;
}
int count=0;
int mark=0;
char b[]=new char[a];
System.out.println("Enter the answer key");
for (i=0;i<a;i++) {
b[i] = sc.next().charAt(0);

if ((b[i] >= 'a' && b[i] <= 'e')||(b[i] > 'E')) {


System.out.println("Invalid Answers");
return;
}
}
char c[]=new char[a];
System.out.println("Enter the student answers");
for (i=0;i<a;i++)
{
c[i]=sc.next().charAt(0);
if ((c[i] >= 'a' && c[i] <= 'e')||(b[i]>'E')) {
System.out.println("Invalid Answers");
return;
}
}

for(i=0;i<a;i++)
{
if(b[i]==c[i])
{
count++;
}
}
if(count>0)
System.out.println("Correct answers are "+count);
mark=(count*100)/a;
if(count<1)
System.out.println("All answers are wrong");
System.out.println("Mark is "+mark);

}
}
JAVA END
*********************************************************************************************
*********************************************************************************************
********

RDBMS IMPORTANT CODES(NOT TESTED)

1.)Select concat(concat(customer_name,'has taken a


policy on'),date_of_policy) as Enrollment_details
from customer JOIN Policy using (customer_id)
order by customer_name,date_of_policy;

2.)select plolicy_id,policy_name,rate_of_interest, bonus_percentage


from policy
where minimum_primeium_amount = 1200
order by policy_d;

3.)select fine_range,fine_amount
CASE
When fine_range=L1
then 5+fine_amount
when fine_range=L2
then 10+fine_amount
When fine_range=M1
then 15+fine_amount
when fine_range=M2
then 20+fine_amount
When fine_range=H1
then 25+fine_amount
when fine_range=H2
then 30+fine_amount
END as NEW_FINE_AMOUNT

4.)select leave_type,allocated_days
CASE
when leave_type='CASUAL'
then allocated_days+2
when leave_type='SICK'
then allocated_days+5
when leave_type='MATERNITY'
then allocated_days+90
when leave_type='MARRIAGE'
then allocated_days+3
when leave_type='STUDY'
then allocated_days-2
END as NEW_ALLOCATED_TYPES
from table_name
order by leave_type;

5.) select emp_id,emp_name,department_id,department_name


from Department JOIN Employee using (department_id)
JOIN Leave+Avail_details using (Emp_id)
JOIN Leave using (Leave_type)
where Allocated_days = 0
order by emp_id;
*********************************************************************************************
**

1.) Account Info - "HDVL002"


select account_type, count(account_id) as TOTAL_ACCOUNTS
from Acount_Info where IFC_Code = 'HDVL002'
group by account_type order by account_type;

2.)select customer_id,customer_name,phone_no,order_date
from Customer_info JOIN Orders using (customer_id)
where order_amount > 500
order by customer_id,order_date;

3.) select distinct customer_id,customer_name,phone_no,loan_amount as


total_loan_amount from customers JOIN loans_taken using
(customer_id)
order by customer_id;

4.) select distinct boat_id,seat_capacity,count(ride_id) as ride_count


From Boat_details JOIN Ride_details using (boat_id)
order by boat_id;

5.) select customer_id,customer_name,contact_no,mail_id


from Coustomer_details where Gender = 'M'
order by customer_id;
6.) select customer_name,total_amount_paid
from Customer_master JOIN Booking_details using (customer_id)
where total_amount_paid < (select max(total_amount_paid) from booking_details
where total_amount_paid < (select max(total_amount_paid) from booking_details))
order by customer_name;

7.) select book_code,book_title, author,rack_num


from book_details where category = 'JAVA'
order by book_code;

8.) select customer_name,policy_enrollment as Enrollment_details


from customer JOIN policy_enrolmment using (customer_id)
order by customer_name,date_of_enrollment;

9.)DECODE QUESTION
select fine_range, fine_amount,
decode(fine_range, 'L1',fine_amount+5,
'L2',fine_amount+10,
'M1',fine_amount+10,
'M2',fine_amount+10,
'H1',fine_amount+10,
'H2',fine_amount+10)new_fine_amount
from fine_details;

10.)select customer_name||" has taken policy on"|| date_of_enrollment as


enrollment_details form customer
join policyenrollent using (customer_id)
order by customr_name,date_of_enrollment;

11.)select policy_id,policy_name,rate_of_interest,bonus_percentage
from policy where mimum_premium_amount = 1200
order by policy_id;

12.) select customer_id,customer_name, street,phone_no,email


from Customers JOIN loan_taken using (customer_id)
where loan_amount > = 500000 and loan_amonunt <1500000
order by customer_id;

13.)select distinct boat_id, boat_name,boat_type


from boat_details JOIN ride_details using (boat_id)
where DOT LIKE '%-AUG-%' and Shift = 'evening'
order by boat_id;

14.) select policy_id,policy_name,rate_of_interest


from policy where miniimum_ppremium_amount < 3000 AND bonus_percent > 85
order by policy_id;

RDBMS ANSWERS

1.1) Write a query to display boat_type and number of boats running under each type. Give an alias name as 'NO_OF
_BOATS'.
Note: Boat_type can be 'DELUXE' or 'SUPER DELUXE'.

select boat_type,count(Boat_id) as NO_OF_BOATS


from boat_details
group by Boat_type;

1.2) select boat_name,boat_type from boat_details


where seat_capacity between 100 and 200
order by boat_name desc;

2.1) select vehicle_type,count(vehicle_id)


from vehicle_details
group by vehicle_type
order by vehicle_type;

2.2) select driver_id,driver_name,phone_no,Driver_rating


from driver_details where driver_rating between 3 and 5
order by driver_rating desc;

3.1) select coursename from course


c join registration r on
c.courseid=r.courseid
having count(studid)>=2
group by coursename
order by coursename;

3.2) select s.studid,sum(fees) as TOTALFEES


from student s join registration r
on s.studid=r.studid join course c
on r.courseid=c.courseid
group by s.studid
order by s.studid;

3.3) select studid,count(CourseID) as NOOFCOURSES


from registration
group by Studid
order by NOOFCOURSES desc,Studid;

3.4) select student.stuid,firstname from student


join registration on registration.stuid=student.stuid
where lower(to_char(doj,'MON'))='jan';

3.5) select courseid,coursename from


course where duration between 10 and 15;

3.6) select courseid,registration.stuid from registration


join student on registration.stuid=student.stuid
where lower(to_char(doj,'MON'))=lower(to_char(dob,'MON'));
Longest substring

Input : abczgdpqrstubg
Output: pqrstu
*/
import java.util.*;
public class Main
{
public static void main (String[] args)
{
Scanner sc=new Scanner(System.in);
String s=sc.next();
int firstindex=0,lastindex=0,length=0;
for(int i=0;i<s.length();i++)
{
int asci=s.charAt(i);
int count=1;
for(int j=i+1;j<s.length();j++)
{
if(s.charAt(j)==++asci)
{
count++;
continue;
}
else
{
if(count>length)
{
firstindex=i;
lastindex=j;
length=count;
break;
}
}
}
}
System.out.println(s.substring(firstindex,lastindex));
}
}
Non Unique char Elimination from string

public class NonUniqueElimination {


public static void main(String[] args){
Scanner sc=new Scanner(System.in);
String name=sc.nextLine(),abc="";
int count=0;
for(int i=0;i<name.length();i++)
{
for(int j=1;j<name.length()-1;j++)
{
if(name.charAt(i)==name.charAt(j))
{
name=name.replace(String.valueOf(name.charAt(j)),"");
count+=1;
}
}
}
if(count==0) {
System.out.println("All are unique character");
return;
}
else {
System.out.println(name);
}
}
Sum of integers at even or odd places

need to specify size (say 5) and then take 5 integer numbers as Input. If the
number of digits in the number is odd then we need to add all odd places digits
and if number of digits is even then we need to add all even place digits. In the
end sum of all these individual sum needs to be displayed as result.

Eg enter size :5
Enter numbers
123(1+3=4)
2536(5+6=11)
2(2)
57(7)
76542(7+5+2=14)
Output: 38 (4+11+2+7+14)

No of substring from a given string

Given a string and a substring, find the number of occurances of the substring in
the given string.
Check that the string can contain only alphabets.
Consider both string and substring in lower case.
Eg:
Enter the string
Entertainment
Enter substring
en
Output : 2
Unknown

input: psvy & 4


(find the difference between p&s i.e 2 and print next 4 letters)
Output: behk

calculate Price*Duration after the deduction of discounts in a Bike renting


Company

*Name should be only in alphabets.. If not Print Invalid


*discount eligible only when the Duration is 5 or more
*Discount table will be given for each card (like Visa,Rupay,Mastercard)
*You have to apply discount for based on the option they used.. (This data is as
1,2,3 where option 1 is visa card option 2 is Rupay)
*If Card option is given as 4,5,6,,... OR 0,-1,-2,,,.. Print "Try again" and go back to
get card option until it's a valid one..

best runner from the given inputs

Input will be given as(Name,seconds)


Jorge, 9.78
Alex, 9.65

Order identification
U need to find weather the array elements are in ascending order r not
Note:array size between 2 and 10(inclusive)
Input1:
Enter the array size:3
Enter the elements
53
52
51
Output:
53 52 51 are not in ascending order

Input2:
Enter the array size:5
Enter the elements
32
65
71
78
82
Output:
32 65 71 78 82 are in ascending order

Product of case count


you need to count uppercase letters and lower case letters in a given string
Multiply the counts and display
Note: string shouldn't contain any digits, special characters
Length shouldn't be greater than 10
Input:
YouRName
Output:
Product value is 15
Explanation
Uppercase letters=3
Lowercase letters=5
Display 3*5=15

import java.util.*;
public class Program{

public static void main(String[] args){


Scanner sc = new Scanner(System.in);
int countj=0,countk=0,i;
System.out.println("Enter string:");
String str=sc.next();
char str1[]=new char[str.length()];
for( i=0;i<str.length();i++) {
if(str.charAt(i)<=122&&str.charAt(i)>=97) {
countj++;
}
else if(str.charAt(i)<=90&&str.charAt(i)>=65) {
countk++;
}
}
System.out.println(countj+" "+countk);
int product=countj*countk;

System.out.println(product);

}}

Unknown
Here, size of the array should be taken as input, and it should be between 1 and
10 (inclusive)
If it is not in 1 and 10, print it as "invalid"
Now, by the comparing the values at the same indices of both the arrays, if both
values are even, then print the sum of the two values, otherwise print "0".
Before performing operation, make sure if no even element is present in both the
arrays, then print it as "There are no even elements in both the arrays",
otherwise perform the above operation.
For example, see the following inputs and outputs:
1. Sample input:
Enter the size of array: 3
Enter the elements in first array:
2
3
4
Enter the elements in second array:
1
5
8
Sample output:
0
0
12

2. Enter the size of array: 3


Enter the elements in first array:
5
3
1
Enter the elements in second array:
1
5
9
Sample output:
There are no even elements in both the arrays

3.Sample input:
Enter the size of array: 1
Enter the elements in first array:
5
Enter the elements in second array:
1
Sample output:There are no even elements in both the arrays
Unkown

Here, a list of grocery items are present as follows:

Rice - 3kg, 5 Rs/kg


Wheat - 2kg, 10Rs/kg
Oil - 4litres, 20Rs/litre
Kerosene - 5litres, 15Rs/litre

Now each of the items is abbreviated by R,W,O and K respectively

Sample input:
ORW
Sample output: the
115
Offer to customers
Toll fee for region code
Take input string of numbers. Extract last four numbers from the string. Calculate
the discount price of the product based on those four numbers.

We need to input the product code as a string


The length of that string shd be of 6-8
If not print invalid
And we need to extract last 4 characters from that string, that will be the MRP of
the product
If the MRP is between 0 to 10, then offer is 0₹
If MRP between 11 to 50, offer is 5₹
If MRP between 51 to 500, offer is 15
If MRP between 501 to 5000, offer is 105
If MRP is above 500, offer is 1005

We need to print the MRP as well as the price after the offer is applied

Sample input 1
20220050
Output 1
MRP : ₹50
Offer price : ₹45

Sample input 2
350004
Output 2
MRP: ₹4
Offer price :₹4

Sample input 3:
202200050
Output 3:
Invalid input
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String n = sc.nextLine();
if (5 < n.length() && n.length() < 9) {
String s = n.substring(n.length() - 4);
int price = Integer.parseInt(s);
if (0 < price && price < 10) {
System.out.println("MRP: Rs " + price);
System.out.println("Offer Price: Rs " + price);
} else if (10 < price && price < 51) {
System.out.println("MRP: Rs " + price);
System.out.println("Offer Price: Rs " + (price - 5));
} else if (50 < price && price < 501) {
System.out.println("MRP: Rs " + price);
System.out.println("Offer Price: Rs " + (price - 15));
} else if (500 < price && price < 5001) {
System.out.println("MRP: Rs " + price);
System.out.println("Offer Price: Rs " + (price - 105));
} else if (5000 < price) {
System.out.println("MRP: Rs " + price);
System.out.println("Offer Price: Rs " + (price - 1005));
}
} else {
System.out.println("Invalid Input");
}
}

Reverse and Concatenate

She sells seashells


Same first letter for all words so reverse the last word and concatenate first word
Output: sllehsaesShe

If first letter is not same then reverse first word and concatenate with last word

Male female version code


import java.util.*;
import java.util.regex.Pattern;
public class Main{
public static void main(String args[]){

Scanner sc = new Scanner(System.in);

String str = sc.next();

int count=0;
int count1=0;

if(Pattern.matches("[mfMF]+",str)){

for(int i=0;i<str.length();i++){
if(str.charAt(i)=='M' || str.charAt(i)=='m'){
count++;
}
else if( str.charAt(i)=='F' || str.charAt(i)=='f'){
count1++;
}
}
System.out.println(count+" Male");
System.out.println(count1+" Female");
}
else{
System.out.println("Not a valid input");
return;
}
}
}
LCM

Tony comes to hotel every 4(i) days and potts every 6(j) days when will they
meet? if i or j <0 print invalid, don't use system.exit (To find LCM)

Cake
Input : 4725strawberry181
Extract the weight , flavour , order id and output the cake price according to per kg price given
initially , and print all the cake details.
Output :
4.73 kg
Strawberry
181
Price:

import java.util.*;
public class cake_order {
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
String s=sc.next();
if(!s.matches("^[a-zA-z0-9]*$"))
{
System.out.println("Invalid string");
return;
}
else
{
String str=s.substring(0,4);
for(int i=0;i<str.length();i++)
{
if(!Character.isDigit(str.charAt(i)))
{
System.out.println("Invalid string");
return;
}

}
int num=Integer.parseInt(str);
if(num<1000)
{
System.out.println("Invalid weight");
return;
}
int l=s.length();
int li=l-3;
String s1=s.substring(li,l);
for(int i=li;i<l;i++)
{
if(!Character.isDigit(s.charAt(i)))
{
System.out.println("Invalid orderno");
return;
}
}
int k=Integer.parseInt(s1);
if(k<100)
{
System.out.println("Invalid Order no");
return;
}
double I=Double.parseDouble(str)/1000;
String form=String.format("%.2f", I);
System.out.println("Cake weight is "+form);
String falv="";
for(int i=4;i<li;i++)
{
falv+=s.charAt(i);
}
System.out.println("Cake flavour is "+falv);
System.out.println("Order no is "+s1);
double price=450*I;
String f=String.format("%.2f",price);
System.out.println("Price is "+f);
}
}
}

Products equals sum


Fun count

Input array of string


if there is 5 input
barbie
barbie
doll
doll
bike

output
barbie=2
doll=2
bike=1
Speed Calculation

The normal_speed 30km/h was given


Take two input hours and distance
Find speed= distance/hours
if speed > normalspeed
then
Actual speed=speed-normal_speed
print actual speed
else
print continue on speed
Add with index
Next Mixing Letters
Mega mart customer identification
Theater seat details
Compose Rhythm(Prime numbers btw two no’s)
Rating Score
Unknown
ASCii

Ascii

import java.util.*;
import java.lang.*;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("Enter the String");
String str =in.nextLine();
for(int i=0;i<str.length();i++)
{
if((Character.isLetter(str.charAt(i)) || Character.isWhitespace(str.charAt(i))))
continue;
else{
System.out.println(str+" is not a valid string");
return;
}
}
int sum=0;
for(int i=0;i<str.length();i++){
if((i+1)%3==0){
sum+=(int)str.charAt(i);
}
}
System.out.println("Sum is "+sum);
}
}
Product equal sum

import java.util.*;
public class arraysquare
{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the array size");
int n=sc.nextInt();
if(n<1 || n>10)
{
System.out.println("Invalid array size");
return;
}
int a[]=new int[n];
System.out.println("Enter the elements of the first array");
for(int i=0;i<n;i++)
{
a[i]=sc.nextInt();
if(a[i]<10 || a[i]>999) {
System.out.println("Invalid input);
}
}
System.out.println("Enter the elements of the second array");
int b[]=new int[n];
for(int i=0;i<n;i++)
{
b[i]=sc.nextInt();
if(b[i]<10 || b[i]>999) {
System.out.println("Invalid input);
}
}
int x[]=new int[n];
int y[]=new int[n];
for(int i=0;i<n;i++)
{
int c=a[i];
int prod=1;
while(c!=0)
{
prod*=(c%10);
c/=10;
}
x[i]=prod;
prod=0;
}
for(int i=0;i<n;i++)
{
int s=b[i];
int sum=0;
while(s!=0)
{
sum+=(s%10);
s/=10;
}
y[i]=sum;
sum=0;
}
int count=0;
for(int i=0;i<n;i++)
{
if(x[i]==y[i])
{
System.out.println(a[i]+","+b[i]);
count++;
}
}
if(count==0) {
System.out.println("No pair found");
}
}
}
JAVA

1. LCM OF DAY INTERVAL/LUNCH TOGETHER/DINNER TOGETHER

INPUT: Enter the day interval of Tony : 4


Enter the day interval of Potts: 6

OUTPUT: Tony and Potts will have dinner together on 12th day.

import java.util.Scanner;
public class lcm {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the day interval of Sam:");
int n1 = sc.nextInt();
System.out.println("Enter the day interval of Riya:");
int n2 = sc.nextInt();
if(n1<=0 || n2<=0)
{
System.out.println("Given interval is not valid");
return;
}
int lcm;
lcm = (n1 > n2) ? n1 : n2;
while(true) {
if( lcm % n1 == 0 && lcm % n2 == 0 ) {
System.out.printf("Sam and Riya will have their dinner on day "+lcm);
break;
}
++lcm;
}
}
}

ALTERNATE METHOD

import java.util.Scanner;
public class Lunchlcm {
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the day interval of Tony");
int n1=sc.nextInt();
System.out.println("Enter the day interval of Potts");
int n2=sc.nextInt();
if(n1<=0 && n2<=0)
{
System.out.println("Given interval is not valid");
return;
}
int a=n1;
int b=n2;
while(n2>0)
{
if (n1 > n2)
{
n1 = n1 - n2;
} else
{
n2 = n2 - n1;
}
}
int gcd = n1;
int lcm = (a * b) / gcd;

System.out.println("Tony and Potts will have lunch together on " + lcm + " day");
}
}

*********************************************************************************************
*********************************************************************************************
**
2.SCORE OF REPEATING WORDS/ WORD REPETITION

INPUT: Enter the String: GOOD


Enter the sentence: GOOD FOOD GOOD LIFE

OUTPUT: Score is 2

import java.util.*;
class PrintMessage
{
public static void main (String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the string");
String s=sc.next();
int count=0;
int sum=2;
for(int i=0;i<s.length();i++)
{
if(Character.isDigit(s.charAt(i)) || Character.isLetter(s.charAt(i)) || s.charAt(i)==' ')
{
continue;
}
else
{
System.out.println(s+" is not valid String");
return;
}
}
System.out.println("Enter the sentence");
sc.nextLine();
String sentence=sc.nextLine();
String[] w=sentence.split(" ");
for(int i=0;i<w.length;i++)
{
if(w[i].equalsIgnoreCase(s))
{
count++;
if(count>2)
{
sum=sum*2;
}
}
}
if(count>2)
{
System.out.println("Score is "+sum);
}
else
{
System.out.println("Score is"+count);
}
}
}

*ALTERNATE METHOD

import java.util.Scanner;
public class CountWords {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String word, sentence;ed
int count = 0;
System.out.println("Enter a word:");
word = in.nextLine();
System.out.println("Enter a sentence");
sentence = in.nextLine();

if (!(word.matches("[a-z]+"))) {
System.out.println("Invalid Input");
return;
}
String words[] = sentence.toLowerCase().split(" ");
for (int i = 0; i < words.length; i++) {
if (word.equals(words[i])) {
count++;
}
}
System.out.println("Score is:" + ((int) Math.pow(2, count - 1)));
}
}
*********************************************************************************************
*********************************************************************************************
***

3)BATTERY CAPACITY

INPUT: Enter battery capacity :1230


Enter charging current value: 400

OUTPUT: 3.69 Hours

import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter battery capacity:");
double capacity = sc.nextDouble();
if(!(capacity>=1000 && capacity<=10000)) {
System.out.println("Invalid battery capacity");
return;
}
System.out.println("Enter charging current value:");
double current = sc.nextDouble();
if(!(current>=300 && current<=2100)) {
System.out.println("Invalid output current");
return;
}
double time=0.0f;
time = (capacity/current)*1.2;
System.out.println(String.format("%.2f",time)+" Hours");
}

*********************************************************************************************
*********************************************************************************************
***
4) COMBINE NUMBERS / STUDENTS WHOSE ROLLNO ARE ODD

INPUT: Entr the set of students :5


Enter the roll number :1
3
4
5
6

OUTPUT: 135

import java.util.*;
public class Main
{
public static void main(String[] args) {
System.out.println("Enter the set of students");
Scanner s=new Scanner(System.in);
int setn=s.nextInt();
if(setn<=0)
{
System.out.println(setn+" is an invalid size");
return;
}
System.out.println("Enter the roll number");
int[] rolls=new int[setn];
int oddflag=0;
for(int i=0;i<setn;i++)
{
rolls[i]=s.nextInt();
if(rolls[i]<0)
{
System.out.println(rolls[i]+" is an invalid roll number");
return;
}
if(rolls[i]%2!=0)
{
oddflag=1;
}
}
if(oddflag==0)
{
System.out.println("The "+setn+" numbers are not odd");
return;
}
String str="";
for(int i=0;i<setn;i++)
{
if(rolls[i]%2!=0)
{
str=str+rolls[i];
}
}
for(int n=0;n<str.length();n++)
{
System.out.println(str.charAt(n)+" ");
}
}
}
*********************************************************************************************
*********************************************************************************************
**

5) BIKE RENT / CALCULATING BILL AMOUNT

INPUT : Enter your name : Sam


Enter the time duration: 13
List of payment options
1)Visa card
2)Rupay card
3)Master card
Choose an option : 2

OUTPUT: Dear Sam your bill amount is 1294.80

import java.util.*;
public class Main
{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter your name");
String s=sc.nextLine();double sal=0;double disc=0;
for(int i=0;i<s.length();++i)
{
if(!Character.isLetter(s.charAt(i)))
{
System.out.println("Invalid Name");
return;
}
}
System.out.println("Enter the time duration");
int n=sc.nextInt();int n1;
if(n<=0 || n>24)
{
System.out.println("Invalid duration");
return;
}
System.out.println("List of payment options");
System.out.println("1)Visa card");
System.out.println("2)Rupay card");
System.out.println("3)Master card");
System.out.println("Chosse an option");
while(true)
{
n1=sc.nextInt();
if(n1<0||n1>3)
{
System.out.println("Try again");
}
else
{
break;
}
}
if( n1==1)
{
if(n>=5)
{
sal=120*n;
disc=(sal*0.25);
sal=sal-disc;
}
else
{
sal=n*120;
}
}
if(n1==2)
{
if(n>=5)
{
sal=120*n;
disc=(sal*0.17);
sal=(120*n)-disc;
}
else
{
sal=n*120;
}
}
if(n1==3)
{
sal=n*120;
}
System.out.print("Dear "+s+" your bill amount is ");
System.out.printf("%.2f", sal);
}
}

*********************************************************************************************
*********************************************************************************************
***
6) ODD POSITION CHAR WILL BE IN UPPERCASE & EVEN WILL BE LOWERCASE-

INPUT : school

OUTPUT : sChOol

import java.util.Scanner;
public class UPLC{
public static void main(String []args){
Scanner sc = new Scanner(System.in);
String str = sc.next();
int strlen = str.length();
for(int i = 0 ; i < str.length(); i++){
char ch = str.charAt(i);
if(!(ch >= 'a' && ch <='z' || ch >= 'A' && ch <='Z' )){
System.out.println(str+ " is an invalid input");
return;
}
}

if(strlen >= 5 && strlen <= 20){


StringBuffer updateString = new StringBuffer();
char[] charArr = str.toCharArray();
for(int i = 0 ; i < charArr.length; i++){
char ch = charArr[i];
if(i % 2 != 0){
ch = Character.toUpperCase(ch);
}
updateString.append(ch);
}
System.out.println(updateString.toString());
}
else {
System.out.println(str+ " is an invalid Length");
}
}
}

*********************************************************************************************
*********************************************************************************************
****
7) RATING SCORE

INPUT: ENTER JESSON SCORE


1
2
3
4
8
ENTER JAMES SCORE
0
2
6
5
6

OUTPUT: JESSON SCORE : 2


JAMES SCORE : 2

import java.util.Scanner;
public class Ratingscore {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter Jesson Score");
int[] a1 = new int[5];
int[] a2 = new int[5];
int f = 0;
int t = 0;
int sum = 0;
int sum1 = 0;
for (int i = 0; i < 5; i++) {
a1[i] = sc.nextInt();
if (a1[i] < 0) {
f = 1;
t = a1[i];
break;
}
}
if (f == 1) {
System.out.println(t + " is invalid");
} else {
System.out.println("Enter James Score");
for (int j = 0; j < 5; j++) {
a2[j] = sc.nextInt();
if (a2[j] < 0) {
f = 1;
t = a2[j];
break;
}
}
if (f == 1) {
System.out.println(t + " is invalid");
} else {
for (int k = 0; k < 5; k++) {
if (a1[k] > a2[k]) {
sum++;
}
if (a1[k] < a2[k]) {
sum1++;
}
}
System.out.println("Jesson Score");
System.out.println(sum);
System.out.println("James Score");
System.out.println(sum1);
}
}
}
}

**ALTERNATE METHOD:

import java.util.Scanner;
public class minmax {
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
int jesson=0,james=0,c=0;
int a[]=new int[5];
int b[]=new int[5];
System.out.println("Enter Jesson Score");
for(int i=0;i<a.length;i++)
{
a[i]=sc.nextInt();
if(a[i]<0)
{
System.out.println("Invalid");
Runtime.getRuntime().halt(0);
}
}
System.out.println("Enter James Score");
for(int i=0;i<b.length;i++)
{
b[i]=sc.nextInt();
if(b[i]<0)
{
System.out.println("Invalid");
Runtime.getRuntime().halt(0);
}
}
if(a.length==b.length)
{
for(int i=0;i<a.length;i++)
{
if(a[i]>b[i])
{
jesson++;
}
else if(a[i]<b[i])
{
james++;
}
else if(a[i]==b[i])
{
c++;
}
}
System.out.println("Jesson Score: "+jesson);
System.out.println("James Score: "+james);
}
else{
System.out.println("Length not same");
}
}
}

*********************************************************************************************
*******************************************************************************

8.COUNT OF UPPERCASE AND COUNT OF LOWERCASE & OUTPUT WILL BE IN THE FORM OF
(UP-LC)

INPUT : HosTEL

OUTPUT: 4-2=2

import java.util.Scanner;

public class ContNext {


public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the string");
String str=sc.nextLine();
int uc=0,lc=0;
if(str.matches("[A-Za-z ]+")&&str.length()<10) {
for(int i=0;i<str.length();i++)
if(Character.isUpperCase(str.charAt(i))) {
uc++;
}
else if(Character.isLowerCase(str.charAt(i))){
lc++;
}
System.out.println(uc-lc);
}
}
}
*********************************************************************************************
*******************************************************************************
9) PRODUCT of COUNT of UPPERcase

andLOWERcaseletters

INPUT: ABsdEr

OUTPUT: 6 (3*3)

import java.util.Scanner;
public class minmax {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the String");
String s = sc.nextLine();
int upper = 0;
int lower = 0;
int i;
if (s.matches("[a-zA-Z]+")) {
for (i = 0; i < s.length(); i++) {
char c = s.charAt(i);
if (c >= 'A' && c <= 'Z') {
upper++;
}
if (c >= 'a' && c <= 'z') {
lower++;
}
}
System.out.println(upper * lower);
}
else
{
System.out.println("Invalid String");
}

}
}

*********************************************************************************************
******************************************************************************
10.Count of UPPERcase and LOWERcase and their difference

Enter the String: ColLEgE


Count of uppercase is : 4
Count of lowercase is : 3
Hence the ans is : 1

import java.util.Scanner;
public class MyClass {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the String ");
String str = sc.next();
int strlen = str.length();
for(int i =0; i < str.length() ; i++)
{ char ch = str.charAt(i);
if(!(ch >='a' && ch <= 'z' || ch >= 'A' && ch <= 'Z')){
System.out.println(str + " is an invalid String");
return;
}
}

if(strlen > 0 && strlen <= 10){


int upper = 0, lower = 0, ans = 0;

for(int i = 0; i < str.length(); i++)


{
char ch = str.charAt(i);
if (ch >= 'A' && ch <= 'Z')
upper++;
else if(ch >= 'a' && ch <= 'z')
lower++;
}
ans = upper - lower;
System.out.println("count of uppercase is :"+ upper);
System.out.println("count of lowercase is :"+ lower);
System.out.println("Hence the ans is :"+ ans);
}
else {
System.out.println(str + " is an invalid String");
}
}
}
*********************************************************************************************
*******************************************************************************
11.PUBLIC DISTRIBUTION

INPUT : OKR

OUTPUT : 90

import java.util.*;
public class Main
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
String str = in.nextLine();
int l=str.length();
if(l>5 || l<2)
{
System.out.println("Invalid Input");
}
else
{
int sum=0,flag=0;
for(int i=0;i<l;i++)
{
char c=str.charAt(i);
if(c=='O')
{
sum=sum+24;
}
else if(c=='K')
{
sum=sum+36;
}
else if(c=='S')
{
sum=sum+42;
}
else if(c=='R')
{
sum=sum+30;
}
else if(c=='W')
{
sum=sum+44;
}
else
{
flag=1;
}
}
if(flag==1)
{
System.out.println("Invalid Input");
}
else
{
System.out.println(sum);
}
}
}
}
*********************************************************************************************
******************************************************************************

12.LOTTERY TICKETS

INPUT: Enter the Starting range


23467
Enter the Ending range
23477

OUTPUT: 23469
23472

import java.util.*;
public class Main {
public static void main(String args[])
{
int i,c,n,sum,count;
sum=0;count=0;n=0;c=0;i=0;
Scanner sc = new Scanner(System.in);
System.out.println("Enter the Starting range");
int a = sc.nextInt();
String str = Integer.toString(a);
if(str.length()!=5)
{
System.out.println(str + " is an invalid input");
System.exit(0);
}

System.out.println("Enter the Ending range");


int b = sc.nextInt();
String str1 = Integer.toString(b);
if(str1.length()!=5)
{
System.out.println(str1 + "is an invalid input");
System.exit(0);
}

if(a>b)
{
System.out.println(a+" and "+b+" are invalid serial numbers");
System.exit(0);

}
for(i=a;i<=b;i++)
{
n=i;
while(n!=0)
{
c=n%10;
sum=sum+c;
n=n/10;
}
if((sum%3==0)&&((sum/3)%2==0))
{
System.out.println(i + " ");
count++;
}
sum=0;
}
if(count==0)
{
System.out.println("Eligible tickets are not available from "+a+" to "+b);
System.exit(0);
}
}
}

*********************************************************************************************
******************************************************************************
13.COFFEE STALL NUMEROLOGY

INPUT : Enter the Staff Name


Coffee Bar

OUTPUT : Coffee Bar satisfies the numerology logic

import java.util.*;
public class Main{
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the Staff Name");
String name = sc.nextLine();
int count=0;
for(int i=0;i<name.length();i++){
if(Character.isAlphabetic(name.charAt(i)) || name.charAt(i)==' '){
count++;
}
}
if(count==name.length()){
String str = name.replace(" ","");
int sum=0;
for(int i=0;i<str.length();i++){
sum += i;
}
if(sum%2==0){
System.out.println(name+" satisfies the numerology logic");
}else{
System.out.println(name+" does not satisfy the numerology logic");
}
}else{
System.out.println("Invalid Input");
}
}
}

*ALTERNATE METHOD USING -matches for same question

import java.util.*;
public class Main{
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the Staff Name");
String name = sc.nextLine();
if(name.matches("[a-zA-Z ]+")){
String str = name.replace(" ","");
int sum=0;
for(int i=0;i<str.length();i++){
sum += i;
}
if(sum%2==0){
System.out.println(name+" satisfies the numerology logic");
}else{
System.out.println(name+" does not satisfy the numerology logic");
}
}else{
System.out.println("Invalid Input");
}
}
}

*ALTERNATE METHOD

import java.util.Scanner;
public class CoffeeHouse {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the Stall Name");
String name = sc.nextLine();
if (name.matches("^[A-Za-z ]*$")) {
int sum = 0;
String fName = name.replaceAll(" ", "");
for (int i = 0; i < fName.length(); i++)
sum = sum + i;
if (sum % 2 == 0) {
System.out.println(name + " satisfies the numerology logic");
} else {
System.out.println(name + " not satisfies the numerology logic");
}
} else
System.out.println("Invalid Input");
}
}

*********************************************************************************************
******************************************************************************

14.ANAGRAM OR TWO WORDS OF SAME LETTER

INPUT : cat
act

OUTPUT: Same

import java.util.Arrays;
import java.util.Scanner;
public class minmax {
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter sentence 1");
String s1=sc.next();
s1=s1.toLowerCase();
System.out.println("Enter sentence 2");
String s2=sc.next();
s2=s2.toLowerCase();
if(s1.length()!=s2.length())
{
System.out.println("Invalid");
}
if(s1.matches("^[a-zA-Z]*")){
char c1[] = s1.toLowerCase().toCharArray();
char c2[] = s2.toLowerCase().toCharArray();
Arrays.sort(c1);
Arrays.sort(c2);
if (Arrays.equals(c1, c2)) {
System.out.println(s1 + " and " + s2 + " contain the same characters");
} else {
System.out.println(s1 + " and " + s2 + " contain the different characters");
}
}
else
{
System.out.println("Invalid");
}
}
}

ALTERNATE METHOD:

import java.util.*;
public class Main{
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
String first=sc.next();
String secound=sc.next();
String word1=Main.checker(first);
String word2=Main.checker(secound);
if(word1.equals(word2)){
System.out.println("Same");
}else{
System.out.println("Different");
}
}
public static String checker(String word){
char arr[]=word.toCharArray();
Arrays.sort(arr);
int index=0;
for(int i=0;i<arr.length;i++){
int j;
for(j=0;j<i;j++){
if(arr[j]==arr[i]){
break;
}
}
if(i==j){
arr[index++]=arr[i];
}
}
char arr1[]=Arrays.copyOf(arr,index);
String newword= new String(arr1);
return newword;
}
}

ALTERNATE METHOD

import java.util.*;
public class arraysquare {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int f1=0,f2=0;
String s1=sc.nextLine();
char c1[]=s1.toCharArray();
String s2=sc.nextLine();
char c2[]=s2.toCharArray();
for(int i=0;i<c1.length;i++)
{
f1=0;
for(int j=0;j<c2.length;j++)
{
if(c1[i]==c2[j])
{
f1=1;
break;
}
}
if(f1==0)
{
break;
}
}
for(int i=0;i<c2.length;i++)
{
f2=0;
for(int j=0;j<c1.length;j++)
{
if(c2[i]==c1[j])
{
f2=1;
break;
}
}
if(f2==0)
{
break;
}
}
if(f1==1 && f2==1)
{
System.out.println("Same Char");
}
else{
System.out.println("Different char");
}
}
}

*********************************************************************************************
*****************************************************************************
15.SUMMATION OF EVEN NUMBERS IN THE ARRAY

INPUT : Enter array size


4
Enter array elements in 1st array
2
4
6
8
Enter array elements in 2nd array
1
2
5
2

OTPUT: 0
6
0
10

import java.util.*;
public class Main
{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter array size");
int n=sc.nextInt();
if(n>=10 || n<1)
{
System.out.println(n+" is an invalid input");
Runtime.getRuntime().halt(0);
}
int arr1[]=new int[n];
int arr2[]=new int[n];
int result[]=new int[n];
System.out.println("Enter array elements in 1st array");
for(int i=0;i<n;i++)
{
arr1[i]=sc.nextInt();
}
System.out.println("Enter array elements in 2nd array");
for(int i=0;i<n;i++)
{
arr2[i]=sc.nextInt();
}
//PROGRAM LOGIC
int count=0;
for(int i=0;i<n;i++)
{
if((arr1[i]%2==0 || arr1[i]==0) && (arr2[i]%2==0 || arr2[i]==0))
{
result[i]=arr1[i]+arr2[i];
count++;
}
else
{
result[i]=0;
}
}
if(count==0)
{
System.out.println("No even number is present in an Array");
}
for(int i=0;i<n;i++)
{
System.out.println(result[i]);
}
}
}

*********************************************************************************************
******************************************************************************
16.RUNNERS COMPETITION

INPUT :Enter the number of runners


5

Enter the runner details


Robert,9.38
Richard,9.35
Christiano,9.35
Williams,9.36
Vinix,9.35

OUTPUT: Richard
Christiano
Vinix

import java.util.*;
public class Main{
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
sc.useDelimiter("\n");
System.out.println("Enter the number of runners");
int n = sc.nextInt();
if(n<=0 || n>10){
System.out.println(n+" is an invalid number of runners");
Runtime.getRuntime().halt(0);
}
String temp = "";
String name[] = new String[n];
float time[] = new float[n];
System.out.println("Enter the runner details");
for(int i=0;i<n;i++){
temp = sc.next();
String temparr[] = temp.split(",");
name[i] = temparr[0];
time[i] = Float.parseFloat(temparr[1]);
if(time[i]>12 || time[i]<8){
System.out.println(time[i]+" is an invalid input");
Runtime.getRuntime().halt(0);
}
}
int maxcount = 0;
float maxrep = 0;
for(int i=0;i<n;i++){
int count = 0;
for(int j=i+1;j<n;j++){
if(time[i]==time[j]){
count++;
}
}
if(count>=maxcount){
maxcount = count;
maxrep = time[i];
}
}
if(maxcount==n){
System.out.println(n+" runners have same timing");
}
else if(maxcount==0){
System.out.println("No runners with same time.");
}
else{
for(int i=0;i<n;i++){
if(maxrep == time[i]){
System.out.println(name[i]);
}
}
}
}
}

****ALTERNATE METHOD****

public static void main(String[] args) {


// TODO code application logic here
Scanner sc=new Scanner(System.in);
System.out.println("Enter the no of students");
int n=sc.nextInt();
if(n>10)
{
System.out.println(n+" is an invalid nuber of runners");
return;
}
String input;
String name[]=new String[n]; //name array
Double time[]=new Double[n]; //another time array
System.out.println("Enter the details");
for(int i=0;i<n;i++)
{
input=sc.next();
String[] a=input.split(","); // a[0] stores name a[1] stores time
name[i]=a[0]; //string->string
time[i]=Double.parseDouble(a[1]); //double<-string
if(time[i]<8 || time[i]>12)
{
System.out.println(time[i]+" is an invalid input");
return;
}

}
boolean flag = true;

double min=time[0];
int index=0;

for(int i=0;i<n;i++)
{
if(time[i]<min)
{
min=time[i];
//index=i;
}

if(min!=time[i])
{
flag=false;
System.out.println(name[i-1]);
}

}
if (flag) System.out.println(n+" runners have same timing");
}

}
*********************************************************************************************
******************************************************************************
17.REEDME

INPUT : Enter the customer name


Abi
Enter the category
History
Enter the quantity of books ordered
2900

OUTPUT : Total cost is 334080.0


import java.util.*;
public class Main{
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the customer name");
String name = sc.nextLine();
System.out.println("Enter the category");
String category = sc.nextLine();
category = category.toLowerCase();

if(!category.equals("adventure") && !category.equals("comics") && !category.equals("history") && !categ


ory.equals("thriller")){
System.out.println(category+" is invalid category");
Runtime.getRuntime().halt(0);
}
System.out.println("Enter the quantity of books ordered");
int quantity = sc.nextInt();
if(quantity <= 0){
System.out.println(quantity+" is an invalid quantity");
Runtime.getRuntime().halt(0);
}
int discount = 0;
int price = 0;
if(category.equals("adventure")){
price = 150;
if(quantity>=1700)
discount = 5;
}
else if(category.equals("comics")){
price = 230;
if(quantity>=1950)
discount = 5;
}
else if(category.equals("history")){
price = 120;
if(quantity>=2600)
discount = 4;
}
else if(category.equals("thriller") && quantity>=1700){
price = 190;
if(quantity>=6300)
discount = 3;
}
float totalcost = (price*quantity) - (price*quantity*discount/100);
System.out.println("Total cost is "+totalcost);
}
}

*********************************************************************************************
******************************************************************************
18)HARSHAD NUMBER (Sum of digit completely divide that

number) For example: 18= 1+8=9 and in 18/9 remainder is 0

INPUT: Enter array size: 5


Enter array elements : 18 14 12 24 13

OUTPUT: 18 12 24

import java.util.Scanner;
public class Harshad {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the number of values");
int n = sc.nextInt();
int i;
System.out.println("Enter the numbers");
int[] a = new int[n];
if (n > 0)
{
int flag = 0;
int k = 0;
for (i = 0; i < n; i++)
{
k = sc.nextInt();
if (k > 9)
a[i] = k;
else
{
flag = 1;
break;
}
}
if (flag != 1)
{
int c = 0;
for (i = 0; i < n; i++)
{
int x = a[i];
int sum = 0;
do {
int r = x % 10;
sum = sum + r;
x = x / 10;
}
while (x != 0);
if (a[i] % sum == 0)
{
c++;
System.out.println(a[i]);
}
}
if (c == 0)
System.out.println("The " + n + " values are not harshad number");
}
else
System.out.println("Provided " + k + " is not valid");
} else
System.out.println(n + " is an invalid input");
}
}
****ALTERNATE METHOD******

import java.util.Scanner;
class Main
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number of values");
int n=sc.nextInt();
System.out.println("Enter the numbers");
int a[]=new int[n];
if(n>0)
{
int flag=0;
int k=0;
for(int i=0;i<n;i++)
{
k=sc.nextInt();
if(k>9) a[i]=k; else
{
flag=1;
break;
}
}
if(flag!=1)
{
int c=0;
for(int i=0;i<n;i++)
{
int x=a[i];
int sum=0;
do
{
int r=x%10; sum=sum+r; x=x/10;
}while(x!=0);
if(a[i]%sum==0)
{ c++;
System.out.println(a[i]);
}
}
if(c==0)
System.out.println("The "+n+" values are not harshad number");
}else
System.out.println("Provided "+k+" is not valid");
}else
System.out.println(n+" is an invalid input");
}
}
*********************************************************************************************
*********************************************************************************************
*******
19) VIDEO GAME PLAYER (PS1)

INPUT : Enter the amount


18000
Enter the Video Game Player Type
PS4

OUTPUT: You can buy PS4

public class PS {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the amount");
int amount = sc.nextInt();
if (amount >= 3000) {
System.out.println("Enter the Video Game Player Type");
String type = sc.next();
if (type.matches("[P][S][1-5]")) {
if (type.equals("PS1")) {
if (amount >= 5000) {
System.out.println("You can buy PS1");
} else {
System.out.println("You need more money to buy a PS1");
}
} else if (type.equals("PS2")) {
if (amount >= 7800) {
System.out.println("You can buy PS2");
} else {
System.out.println("You need more money to buy a PS2");
}
} else if (type.equals("PS3")) {
if (amount >= 9500) {
System.out.println("You can buy PS3");
} else {
System.out.println("You need more money to buy a PS3");
}
} else if (type.equals("PS4")) {
if (amount >= 12000) {
System.out.println("You can buy PS4");
} else {
System.out.println("You need more money to buy a PS4");
}
} else if (type.equals("PS5")) {
if (amount >= 15000) {
System.out.println("You can buy PS5");
} else {
System.out.println("You need more money to buy a PS5");
}
}
} else {
System.out.println(type + " is Invalid Type");
}
} else {
System.out.println(amount + " is too less");
}
}
}

*********************************************************************************************
*********************************************************************************************
****
20) ABSOLUTE DIFFERENCE / ALTERNATE SUM DIFFERENCE

INPUT :Enter number


6
Enter values
12
13
6
8
9
7
(((( logic: (12-7=a
13-9=b
6-8=c
a+b+c=ans)))))

OUTPUT 2
3
4
5
5-2=3
4-3=1
So 3+1= 4
*/

import java.util.*;
public class AltDiff {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int sum=0;
int n=sc.nextInt();
int a[]=new int[n];
for(int i=0;i<n;i++)
{
a[i]=sc.nextInt();
}
for(int i=0;i<n/2;i++)
{
sum+=Math.abs(a[i]-a[n-i-1]);
}
System.out.println(sum);
}
}
*********************************************************************************************
*********************************************************************************************
*****
21.CHARACTER
ADDITION

INPUT : Enter : 3
Enter the sentences:
ks436
Agh73
7222

OUTPUT: 222
240
0

import java.util.*;
public class arraysquare{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int sum=0;
System.out.println("Enter:");
int n=sc.nextInt();
if(n<=0)
{
System.out.println("The number of sentences "+n+" is invalid");
return;
}
System.out.println("Enter the sentences:");
String str[]=new String[n];
for(int i=0;i<n;i++)
{
str[i]=sc.next();
}
for(int i=0;i<str.length;i++)
{
String s=str[i].replaceAll("[0-9]","");
for(int j=0;j<s.length();j++)
{
char c=s.charAt(j);
int ascii=c;
sum+=ascii;
}
System.out.println(sum);
sum=0;
}

}
}

*********************************************************************************************
******************************************************************************************
22. REVERSE FIRST HALF/MIDDLE LETTER of the string if string length is ODD

Input:
if length of string is even, the reverse the string:
Ex: Food
Output:
dooF

Input:
If length of the string is odd,then find the middle char and then ,reverse the string till mid char and print remain char
acters as it is.
Ex: Samsung
Output:
maSsung

package FinalAss;
import java.util.*;
public class MidLett {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
String str=sc.nextLine();//rahul
int len=str.length();
if(len%2==0)
{
StringBuilder sb=new StringBuilder(str);
sb.reverse();
System.out.println(sb.toString());
}
else if(len%2!=0)
{
System.out.println("Length of string is " +len);
int mid=len/2;
mid++;
System.out.println("Substring of string is "+mid);
String substr=str.substring(0,mid-1);
String remainSub=str.substring(mid-1,len);
StringBuilder sb=new StringBuilder(substr);
sb.reverse();
System.out.println(sb.toString()+remainSub);

}
}
}

ALTERNATE METHOD:::

import java.util.Scanner;
import java.util.regex.Pattern;
public class minmax {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
String str=sc.nextLine();//rahul
if(!Pattern.matches("[A-Za-z]+",str))
{
System.out.println(str+" is not a valid string");
return;
}
else if(str.length()<2)
{
System.out.println("Size of string "+str.length()+" is too small");
return;
}
int len=str.length();
if(len%2==0)
{
StringBuilder sb=new StringBuilder(str);
sb.reverse();
System.out.println(sb.toString());
}
else if(len%2!=0)
{
int mid=len/2;
String substr=str.substring(0,mid);
String remainSub=str.substring(mid,len);
StringBuilder sb=new StringBuilder(substr);
sb.reverse();
System.out.println(sb.toString()+remainSub);

}
}
}

*********************************************************************************************
*********************************************************************************************
*****

23 .ONLINE SHOPPING

input:
enter the product
laptop
Actual price
45000
exchange?
yes
bill amount:
27000.00

import java.util.*;
public class arraysquare {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the Product:");
String prod=sc.nextLine();
int ed=0,pd=0;
if(prod.equals("Mobile"))
{
ed=15;
pd=15;
}
else if(prod.equals("Laptop"))
{
ed=20;
pd=20;
}
else if(prod.equals("Headset"))
{
ed=0;
pd=10;
}
else if(prod.equals("Charger"))
{
ed=0;
pd=5;
}
else{
System.out.println("Not available");
return;
}
System.out.println("Enter the actual Price: ");
int price=sc.nextInt();
if(price<100)
{
System.out.println("Invalid Price");
return;
}
System.out.println("Do u want to Exchange?");
String exc=sc.next();
if(exc.equals("Yes") || exc.equals("yes"))
{
double ap=price-(price*pd)/100;
double ev=(price*ed)/100;
double total=ap-ev;
System.out.printf("Total=%.2f",total);
}
else if(exc.equals("No") || exc.equals("no"))
{
double total=price-(price*pd)/100;
System.out.printf("Total=%.2f",total);
}
else
{
System.out.println("Invalid Option");
}
}
}

*********************************************************************************************
********************************************************************************************
24 .OPERATOR FOUND

input:
45
23

22
output
45-23=22

import java.util.*;
public class arraysquare {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter n1 and n2:");
int n1=sc.nextInt();
if(n1>0)
{
int n2=sc.nextInt();
if(n2>0)
{
System.out.println("Enter n3:");
int n3=sc.nextInt();
if(n3>0)
{
if(n1+n2==n3)
{
System.out.println(n1+"+"+n2+"="+n3);
}
else if(n1-n2==n3)
{
System.out.println(n1+"-"+n2+"="+n3);
}
else if(n1*n2==n3)
{
System.out.println(n1+"*"+n2+"="+n3);
}
else if(n1/n2==n3)
{
System.out.println(n1+"/"+n2+"="+n3);
}
else
{
System.out.println(n3+" is an invalid answer");
}
}
else{
System.out.println("Invalid");
}
}
else{
System.out.println("Invalid");
}
}
else{
System.out.println("Invalid");
}

}
}

***ALNERNATE METHOD****

import java.util.*;
public class Main{
public static void main(String args[]){
Scanner sc = new Scanner(System.in);

System.out.println("Enter the n1 and n2");


int n1 = sc.nextInt();
if(n1<=0){
System.out.println(n1+" is an invalid number");
return;
}
int n2 = sc.nextInt();
if(n2<0){
System.out.println(n2+" is an invalid number");
return;
}
boolean b = false;
System.out.println("Function answer n3");
int n3 = sc.nextInt();

if((n1+n2)==n3){
System.out.println(n1+"+"+n2+"="+n3);
b=true;
}
if((n1-n2)==n3){
System.out.println(n1+"-"+n2+"="+n3);
b=true;
}
if((n1*n2)==n3){
System.out.println(n1+"*"+n2+"="+n3);
b=true;
}
if((n1/n2)==n3){
System.out.println(n1+"/"+n2+"="+n3);
b=true;
}
if(b== false){
System.out.println(n3+" is an invalid number");
}
}
}

*********************************************************************************************
*********************************************************************************************
****

25 .PRODUCT EQUAL SUM

INPUT : Enter the array size


4
Enter the elements of the first array
12
35
56
34
Enter the elements of the second array
261
195
112
813
OUTPUT: 35,195
34,813

import java.util.*;
public class arraysquare
{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the array size");
int n=sc.nextInt();
if(n<=0)
{
System.out.println("Invalid array size");
return;
}
int a[]=new int[n];
System.out.println("Enter the elements of the first array");
for(int i=0;i<n;i++)
{
a[i]=sc.nextInt();
}
System.out.println("Enter the elements of the second array");
int b[]=new int[n];
for(int i=0;i<n;i++)
{
b[i]=sc.nextInt();
}
int x[]=new int[n];
int y[]=new int[n];
for(int i=0;i<n;i++)
{
int c=a[i];
int prod=1;
while(c!=0)
{
prod*=(c%10);
c/=10;
}
x[i]=prod;
prod=0;
}
for(int i=0;i<n;i++)
{
int s=b[i];
int sum=0;
while(s!=0)
{
sum+=(s%10);
s/=10;
}
y[i]=sum;
sum=0;
}
for(int i=0;i<n;i++)
{
if(x[i]==y[i])
{
System.out.println(a[i]+","+b[i]);
}
}
}
}

*********************************************************************************************
*********************************************************************************************
*

26. UNIQUE CHAR

input:
LIfe is inherently risky

output:
life is ihrtly risky

package FinalAss;
import java.util.*;
public class nonuniquetwo {
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
String sentence = sc.nextLine();
String[] words = sentence.split(" ");
for(String word : words)
{
System.out.print(getUnique(word) + " ");
}
sc.close();
}
public static String getUnique(String str)
{
StringBuffer sb = new StringBuffer();
for(int i = 0; i<str.length(); i++)
{
if(countFrequency(str.charAt(i), str) == 1)
{
sb.append(str.charAt(i));
}
}
String result = sb.toString();
return result;
}
public static int countFrequency(char c, String str)
{
int count = 0 ;
for(int i = 0; i<str.length(); i++)
{
if(str.charAt(i) == c)
{
count++;
}
}
return count;
}
}

***ALTERNATE METHOD*****

import java.util.*;
public class Main
{
public static void main(String[] args)
{
System.out.println("Enter the String");
Scanner sc=new Scanner(System. in);
String str=sc.nextLine();
String output="";
String[] word=str.split(" ");
for(int i=0;i<word.length;i++)
{
for(int j=0;j<word[i].length();j++)
{
int count=0;
char c=word[i].charAt(j);
for(int k=0;k<word[i].length();k++)
{
if(c==word[i].charAt(k))
count++;
}
if(count==1)
{
output+=Character.toLowerCase(c);
}
}
output+=" ";
}
System.out.println(output);
}
}

*********************************************************************************************
*********************************************************************************************
*
27. BOX SIZE

INPUT : Enter the box size


6
Enter the numbers
5
55
3
59
42
8
OUTPUT: 32 is even its a valid box

import java.util.Scanner;
public class minmax {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the box size");
int a=sc.nextInt();
if(a<=0)
{
System.out.println(a+" is an invalid box size");
return;
}
int b[]=new int[a];
int c=0,sum=0,temp=0;
System.out.println("Enter the numbers");
for(int i=0;i<a;i++)
{
b[i]=sc.nextInt();
if(b[i]<=0)
{
System.out.println(b[i]+" is an invalid input");
return;
}
}
for(int i=0;i<a;i++)
{
c=b[i]%10;
sum+=c;
c=0;
}
if(sum%2==0)
{
System.out.println(sum+" is even its a valid box");
return;
}
else
{
System.out.println(sum+" is odd its an invalid box");
return;
}

}
}
****ALTERNATE METHOD***********

Box consists of n numbers and n>0


Enter the numbers and numbers should be greater than 0 and add all the last digits of the numbers.If the sum is
even print valid box else invalid box

Input:
Enter size:5
Enter numbers:
2
34
456
67
123

22 is even it's a valid box

Explanation:
22=(2+4+6+7+3)
Similarly for invalid box also

public class BoxGame {

public static void main(String[] args) {


Scanner sc = new Scanner(System.in);
System.out.println("Enter the box size");
int size = sc.nextInt();
int n=0;
int sum=0;
if(size<=0) {
System.out.println(size+" is an invalid box size");
return;
} else {
System.out.println("Enter the numbers");
int [] arr = new int [size];
for(int i=0;i<size;i++) {
arr[i] = sc.nextInt();
}
for(int i=0;i<size;i++) {
if(arr[i]<=0) {
System.out.println(arr[i]+" is an invalid input");
return;
}
}
for(int i=0;i<size;i++) {
n = arr[i]%10;
sum = sum+n;
}
if(sum%2==0) {
System.out.println(sum+" is even its a valid box");
}else {
System.out.println(sum+" is odd its an invalid box");
}
}

}
********************************************************************************************
****************************************************
28. ORDER IDENTIFICATION:(check where elements are in ascending

order) INPUT : Enter the array size : 5


Enter the elements: 32
44
55
66
77

OUTPUT : 32 44 55 66 77 are in ascending order

import java.util.Arrays;
import java.util.Scanner;

public class orderidentification {


public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the array size");
int a=sc.nextInt();
if(a<2 || a>10)
{
System.out.println(a+" is not a valid array size");
return;
}
int b[]=new int[a];
int count=0;
System.out.println("Enter the elements");
for(int i=0;i<a;i++)
{
b[i]=sc.nextInt();
}
int d[]= Arrays.copyOf(b,b.length);
Arrays.sort(d);

if(Arrays.equals(b,d))
{
count++;
}
if(count>0)
{
for(int i=0;i<b.length;i++)
{
System.out.print(b[i]+" ");

}
System.out.print("are in ascending order");
return;
}
else
{
for(int i=0;i<a;i++)
{
System.out.print(b[i]+" ");
}
System.out.print("are not in ascending order");
return;
}
}
***ALTERNATE METHOD***

public class ascendingDesceding {


public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter array size: ");
int n = sc.nextInt();
int[] arr = new int[n];
int[] temp = new int[n];
if (n < 2 || n > 10) {
System.out.println("Invalid size");
return;
}
for (int i = 0; i < n; i++) {
arr[i] = sc.nextInt();
temp[i]=arr[i]; //store the array elements in temp array for comaparison later
}
Arrays.sort(arr); //sort the original array
int count=0;
for(int i=0;i<n;i++) {
if(arr[i]==temp[i]){ //checking if elements of sorted array is equal to
temp array
count++;
} else {
count=0;
break;
}}
if(count!=0) {
System.out.println("All elements are in ascending order");
} else {
System.out.println("Elements are not in ascending order");
}}}

********************************************************************************************
********************************************************************************************
********************************
29) DATE ,MONTH AND

YEAR INPUT:13081995

OUTPUT: date: 13
month: 08
year: 1998

import java.util.Scanner;
public class minmax {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
String str=sc.nextLine();
int n=str.length();
for(int i=0;i<str.length() ;i++)
{
if(!(str.charAt(i)>='0' && str.charAt(i)<='9'))
{
System.out.println("Invalid input");
return;
}
if(n!=8)
{
System.out.println("Enter valid date");
return;
}
}
String date=str.substring(0,2);
String mon=str.substring(2,4);
String year=str.substring(4,8);

System.out.println("date:"+date);
System.out.println("Month:"+mon);
System.out.print("Year:"+year);

}
}

*********************************************************************************************
*********************************************************************************************
*
30) MEGA MART CUSTOMER IDENTIFICATION(String and SUBSTRING)

import java.util.*;
public class arraysquare{
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the customer id");
String cid = sc.next();
String shop = cid.substring(0,4);
//System.out.println("shop");
if(!shop.equals("Mega")){
System.out.println("Invalid Shop Name");
Runtime.getRuntime().halt(0);
}
String type = cid.substring(4,cid.length()-3);
//System.out.println(type);
if(!type.equals("Silver") && !type.equals("Gold") && !type.equals("Platinum")){
System.out.println("Invalid Customer Type");
Runtime.getRuntime().halt(0);
}
int mid = Integer.parseInt(cid.substring(cid.length()-3,cid.length()));
//System.out.println(mid);
if(mid<=99 || mid>=1000){
System.out.println("Invalid Member id");
Runtime.getRuntime().halt(0);
}
System.out.println("Welcome Mega Mart "+type+" Customer");

}
}

*********************************************************************************************
***********************************
31) MALE AND FEMALE COUNT

INPUT: MmFMff
OUTPUT: 3 MALE
3 FEMALE

import java.util.Scanner;
import java.util.regex.*;
public class minmax {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
String s=sc.nextLine();
int count1=0;
int count2=0;
if(Pattern.matches("[MmFf ]+",s)){
for (int i = 0; i < s.length(); i++) {
if (s.charAt(i) == 'M' || s.charAt(i) == 'm') {
count1++;
} else if (s.charAt(i) == 'F' || s.charAt(i) == 'f') {
count2++;
}
}
System.out.println(count1 + " Male");
System.out.println(count2 + " Female");
}
else
{
System.out.println("Invalid Input");
}
}
}
*********************************************************************************************
*********************************************************************************************
***
32) RAINFALL

INPUT: Enter the length of the roof in meters: 4


Enter the breadth of the roof in meters: 3
Enter the rainfall level: 3

OUTPUT: 360.00 Litres

import java.util.Scanner;
public class minmax {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
System.out.println("Enter the length of the roof in meters");
double l=sc.nextDouble();
if(l<=0)
{
System.out.println("Invalid Length");
return;
}
System.out.println("Enter the breadth of the roof in meters");
double b=sc.nextDouble();
if(b<=0)
{
System.out.println("Invalid breadth");
return;
}
System.out.println("Enter the rainfall level");
double r=sc.nextDouble();
if(r<=0)
{
System.out.println("Invalid rainfall");
return;
}
double h;
h=(l*b) *(r*10);
System.out.println(String.format("%.2f",h)+"Litres");
}
}

*********************************************************************************************
*********
33) NUMEROLOGY NAME CHECKING

import java.util.*;
import java.util.regex.Pattern;

public class arraysquare{


public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the name");
String a=sc.next();
if(!Pattern.matches("[A-Za-z]+",a))
{
System.out.println(a+" is an Invalid name");
return;
}
int sum=0;
char b[]=a.toCharArray();
for(int i=0;i<b.length;i++)
{
if(b[i]=='A'||b[i]=='a')
{
sum+=1;
}
else if(b[i]=='B'||b[i]=='b')
{
sum+=2;
}
else if(b[i]=='C'||b[i]=='c')
{
sum+=3;
}
else if(b[i]=='D'||b[i]=='d')
{
sum+=4;
}
else if(b[i]=='E'||b[i]=='e')
{
sum+=5;
}
else if(b[i]=='F'||b[i]=='f')
{
sum+=6;
}
else if(b[i]=='G'||b[i]=='g')
{
sum+=7;
}
else if(b[i]=='H'||b[i]=='h')
{
sum+=8;
}
else if(b[i]=='I'||b[i]=='i')
{
sum+=9;
}
else if(b[i]=='J'||b[i]=='j')
{
sum+=10;
}
else if(b[i]=='K'||b[i]=='k')
{
sum+=11;
}
else if(b[i]=='L'||b[i]=='l')
{
sum+=12;
}
else if(b[i]=='M'||b[i]=='m')
{
sum+=13;
}
if(b[i]=='N'||b[i]=='n')
{
sum+=14;
}
if(b[i]=='O'||b[i]=='o')
{
sum+=15;
}
if(b[i]=='P'||b[i]=='p')
{
sum+=16;
}
if(b[i]=='Q'||b[i]=='q')
{
sum+=17;
}
if(b[i]=='R'||b[i]=='r')
{
sum+=18;
}
if(b[i]=='S'||b[i]=='s')
{
sum+=19;
}
if(b[i]=='T'||b[i]=='t')
{
sum+=20;
}
if(b[i]=='U'||b[i]=='u')
{
sum+=21;
}
if(b[i]=='V'||b[i]=='v')
{
sum+=22;
}
if(b[i]=='W'||b[i]=='w')
{
sum+=23;
}
if(b[i]=='X'||b[i]=='x')
{
sum+=24;
}
if(b[i]=='Y'||b[i]=='y')
{
sum+=25;
}
if(b[i]=='Z'||b[i]=='z')
{
sum+=26;
}
}
System.out.println(sum);
if(sum%3==0 && sum%2==0)
{
System.out.println(a+" is a numerology name");
}
else
{
System.out.println(a+" is not a numerology name");
}
}
}

*******************************************************************************

34)OMR

import java.util.Scanner;
public class arraysquare{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int i;
System.out.println("Enter the No of questions");
int a=sc.nextInt();
if(a<0)
{
System.out.println("Invalid Number");
return;
}
int count=0;
int mark=0;
char b[]=new char[a];
System.out.println("Enter the answer key");
for (i=0;i<a;i++) {
b[i] = sc.next().charAt(0);

if ((b[i] >= 'a' && b[i] <= 'e')||(b[i] > 'E')) {


System.out.println("Invalid Answers");
return;
}
}
char c[]=new char[a];
System.out.println("Enter the student answers");
for (i=0;i<a;i++)
{
c[i]=sc.next().charAt(0);
if ((c[i] >= 'a' && c[i] <= 'e')||(b[i]>'E')) {
System.out.println("Invalid Answers");
return;
}
}

for(i=0;i<a;i++)
{
if(b[i]==c[i])
{
count++;
}
}
if(count>0)
System.out.println("Correct answers are "+count);
mark=(count*100)/a;
if(count<1)
System.out.println("All answers are wrong");
System.out.println("Mark is "+mark);

}
}

****ALTERNATE METHOD****

import java.util.*;
public class OMREvaluation {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the No of questions");
int no = sc.nextInt();
if (no <= 0) {
System.out.println("Invalid Number");
return;
} else {
char anskey[] = new char[no];
System.out.println("Enter the answer key");
for (int i = 0; i < no; i++) {
char x = sc.next().charAt(0);
if (x >= 'A' && x <= 'E')
anskey[i] = x;
else {
System.out.println("Invalid Answers");
return;
}
}
char studanskey[] = new char[no];
System.out.println("Enter the student answers");
for (int i = 0; i < no; i++) {
char y = sc.next().charAt(0);
if (y >= 'A' && y <= 'E')
studanskey[i] = y;
else {
System.out.println("Invalid Answers");
return;
}
}
int count = 0;
for (int i = 0; i < no; i++) {
if (anskey[i] == studanskey[i])
count++;
}
if (count == 0)
System.out.println("All answers are wrong \nMark is 0");
else {
System.out.println("Correct answers are " + count);
System.out.println("Mark is " + ((count * 100) / no));
}
}
}
}

**********************************************************************************************
***************************************************

35)MULTIPLY WITH POSITION

INPUT:
Enter the array size
5

Enter the elements


12
3
7
9
4

Sample Output:
12
6
21
36
20

Logic:
12*1=12
3*2=6
7*3=21
9*4=36
4*5=20

import java.util.*;
public class Main
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the array size:");
int n=sc.nextInt();
int res=0;
if(n<1 || n>10)
{
System.out.println("Invalid Array Size");
return;
}
int a[]=new int[n];
for(int i=0;i<n;i++)
{
a[i]=sc.nextInt();
}

for(int i=0;i<n;i++)
{
res=a[i]*(i+1);
System.out.println(res);
}

}
}

**********************************************************************************************
******************************************************************
36) CAR PARKING

Sample Input:
Enter the car number
ap 37 1498

Sample Output
Park the car in 3rd floor

import java.util.*;

public class CarPrking {


public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the car number");
String num = sc.nextLine();
if (num.length() != 10) {
System.out.println("Invlid State Code");
return;
}
String floor;
String code = num.substring(0, 2);
if (code.equals("TN")) {
floor = "ground";
} else if (code.equals("KA")) {
floor = "1st";
} else if (code.equals("KL")) {
floor = "2st";
} else if (code.equals("AP")) {
floor = "3st";
} else {
System.out.println("Invlid State Code");
return;
}
System.out.println("Park the car in " + floor + " floor");
}
}

ALTERNATE METHOD:

37) DIGIT COUNT

Sample Input:

Enter the number


56164

Enter the digit


6

Sample output
6 appears in 56164 is 2

Explanation:
Digit 6 appears 2 times in the number 56164

package accenture;
import java.util.*;

public class digitcount {

public static void main(String[] args) {


Scanner sc=new Scanner(System.in);
int count=0;
System.out.println("Enter the number:");
int n=sc.nextInt();
String str=String.valueOf(n);
if(n>0)
{
System.out.println("Enter the digit:");
char d=sc.next().charAt(0);
char ch[]=str.toCharArray();
for(int i=0;i<ch.length;i++)
{

if(ch[i]==d)
{
count++;
}
}
if(count>1)
{
System.out.println(d+" appears "+n+" is "+count);
}
}

38) WORD FINDING (repeated words)

Sample input:
Enter the number of words
5
Enter the words in set1:
good
bad
hello
Nothing
North

Enter the words in set2:


Bad
world
word
north
hello

package practice;
import java.util.*;
public class RepeatedWords {

public static void main(String[] args) {


// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
System.out.println("Enter the number of words");
int n = sc.nextInt();
if(n<=0){
System.out.println(n+" is less than the desired limit");
return;
}

String set1[] = new String[n];


String set2[] = new String[n];
System.out.println("Enter the words in set1:");
for(int i = 0;i<n;i++){
set1[i] = sc.next().toLowerCase();
}
System.out.println("Enter the words in set2:");
for(int i = 0;i<n;i++){
set2[i] = sc.next().toLowerCase();
}
String res[] = new String[n];
int k = 0;
for(int i = 0;i<n;i++){
int flag = 0;
for(int j = 0;j<n;j++){
if(set1[i].equals(set2[j])){
flag = 1;
break;
}
}
if(flag != 1){
res[k++] = set1[i];
}
}
/*for(int i = 0;i<n;i++){
if(set1[i] == set2[i]){
continue;
}
else{
res[k++] = set1[i];
}
}*/
System.out.println("The uncommon words are:");
for(int i = 0;i<k;i++){
System.out.println(res[i]);
}

}
**********************************************************************************************
******************************************************
39) SUM OF INTEGERS AT EVEN OR ODD PLACES

Enter size: 5
Enter numbers:
123(1+3=4)
2536(5+6=11)
2(2)
57(7)
76542(7+5+2=14)

Output:
38(4+11+2+7+14)

import java.util.*;
public class oddevenindex {
public static void main(String[] args)
{
Scanner sc = new Scanner (System.in);
System.out.println("Enter the size of the array: ");
int n = Integer.parseInt(sc.nextLine());
String[] arr = new String[n];
int[] fin = new int[n];
System.out.println("Enter the elements of the array: ");
for(int i=0;i<n;i++)
{
arr[i] = sc.nextLine();
}
int sum = 0;
int total =0;
if(n%2!=0)
{
for(int i=0;i<arr.length;i++) {
String num = arr[i];
char[] digi = num.toCharArray();
sum = 0;
if (digi.length % 2 == 0) {
for (int j = 1; j < digi.length; j += 2) {
char x = digi[j];
sum = sum + Integer.parseInt(String.valueOf(x));
}
fin[i] = sum;
}
else
{
for (int j = 0; j < digi.length; j += 2) {
char x = digi[j];
sum = sum + Integer.parseInt(String.valueOf(x));
}
fin[i] = sum;

}
}
for(int x: fin)
total +=x;
}
else{
for(int i=0;i<arr.length;i++) {
String num = arr[i];
char[] digi = num.toCharArray();
sum = 0;
if (digi.length % 2 == 0) {
for (int j = 1; j < digi.length; j += 2) {
char x = digi[j];
sum = sum + Integer.parseInt(String.valueOf(x));
}
fin[i] = sum;
}
else
{
for (int j = 0; j < digi.length; j += 2) {
char x = digi[j];
sum = sum + Integer.parseInt(String.valueOf(x));
}
fin[i] = sum;

}
}
for(int x: fin)
total +=x;
}

System.out.println("Output: "+total);

}
}

*****ALTERNATE METHOD*****

package practice;
import java.util.*;
public class SumOfEvenOrOdd {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
System.out.println("Enter the size");
int n = sc.nextInt();
if(n<=0){
System.out.println("Invalid size");
return;
}
System.out.println("Enter the elements:");
int sum = 0;
String str[] = new String[n];
for(int i=0;i<n;i++){
str[i] = sc.next();
}
for(int i = 0;i<n;i++){
String s = str[i];
if(s.length()%2 == 0){
for(int j = 1;j<s.length();j+=2){
sum+=Integer.parseInt(s.substring(j,j+1));
}
}else{
for(int j = 0;j<s.length();j+=2){
sum+=Integer.parseInt(s.substring(j,j+1));
}
}
}
System.out.println(sum);
}

}
**********************************************************************************************
**********************************************************************
40) SUM OF EVEN ELEMENTS

Here, size of the array should be taken as input, and it should be between 1 and 10 (inclusive)
If it is not in 1 and 10, print it as "invalid"
Now, by the comparing the values at the same indices of both the arrays, if both values are even, then print the sum
of the two values, otherwise print "0".
Before performing operation, make sure if no even element is present in both the arrays, then print it as "There are no
even elements in both the arrays", otherwise perform the above operation.

For example, see the following inputs and outputs:

1. Sample input:
Enter the size of array: 3
Enter the elements in first array:
2
3
4
Enter the elements in second array:
1
5
8
Sample output:
0
0
12

2. Enter the size of array: 3


Enter the elements in first array:
5
3
1
Enter the elements in second array:
1
5
9
Sample output:
There are no even elements in both the arrays

3.Sample input:
Enter the size of array: 1
Enter the elements in first array:
5
Enter the elements in second array:
1
Sample output:
There are no even elements in both the arrays

package practice;
import java.util.*;
public class SumOfEvenElements {

public static void main(String[] args) {


// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
System.out.println("Enter the size of the array:");
int n = sc.nextInt();
if(n<=0 || n>10){
System.out.println("Invalid");
return;
}
System.out.println("Enter the elements in the first array:");
int arr1[] = new int[n];
for(int i = 0;i<n;i++)
arr1[i] = sc.nextInt();
System.out.println("Enter the elements in the second array:");
int arr2[] = new int[n];
for(int i = 0;i<n;i++)
arr2[i] = sc.nextInt();
int count = 0;
for(int i = 0;i<n;i++){
if(arr1[i]%2 !=0 && arr2[i]%2 != 0){
count++;
}
}
if(count == n){
System.out.println("There are no even elements in both arrays:");
return;
}else{
for(int i = 0;i<n;i++){
if(arr1[i]%2 == 0 && arr2[i]%2 == 0){
System.out.println(arr1[i]+arr2[i]);
}else{
System.out.println("0");
}
}
}
}
}
**********************************************************************************************
*********************************************************************
41) COUNT OF OCCURRENCES OF SUBSTRING IN A STRING

Sample input:
Enter the string
Entertainment

Enter substring
en

Sample output: 2

package accenture;
import java.util.*;
import java.util.regex.*;
public class countofoccurencesofsubstringinastring {

public static void main(String[] args) {


Scanner sc=new Scanner(System.in);
int count=0;
System.out.println("Enter the string:");
String str=sc.next();
if(Pattern.matches("[a-z]+", str))
{
System.out.println("Enter pattern:");
String pat=sc.next();
if(Pattern.matches("[a-z]+", pat))
{
Pattern p=Pattern.compile(pat);
Matcher m=p.matcher(str);
while(m.find())
{
count++;
}
System.out.println("Count is: "+count);
}
else
{
System.out.println("Invalid Pattern");
}
}
else
{
System.out.println("Invalid String");
}

}
**********************************************************************************************
******************************************************************
42) LARGEST SORTED SUBSTRING FROM INPUT STRING

Find longest sorted substring from input string..


Input : abczgdpqrstubg
Output: pqrstu
*/
import java.util.*;
public class Main
{
public static void main (String[] args)
{
Scanner sc=new Scanner(System.in);
String s=sc.next();
int firstindex=0,lastindex=0,length=0;
for(int i=0;i<s.length();i++)
{
int asci=s.charAt(i);
int count=1;
for(int j=i+1;j<s.length();j++)
{
if(s.charAt(j)==++asci)
{
count++;
continue;
}
else
{
if(count>length)
{
firstindex=i;
lastindex=j;
length=count;
break;
}
}
}
}
System.out.println(s.substring(firstindex,lastindex));
}
}
**********************************************************************************************
********************************************************************
43) NON-UNIQUE ELIMINATION

package com.company;
import java.util.Scanner;

public class NonUniqueElimination {


public static void main(String[] args){
Scanner sc=new Scanner(System.in);
String name=sc.nextLine(),abc="";
int count=0;
for(int i=0;i<name.length();i++)
{
for(int j=1;j<name.length()-1;j++)
{
if(name.charAt(i)==name.charAt(j))
{
name=name.replace(String.valueOf(name.charAt(j)),"");
count+=1;
}
}
}
if(count==0) {
System.out.println("All are unique character");
return;
}
else {
System.out.println(name);
}
}
**********************************************************************************************
**********************************************************************************************
**

44) THEATER SEAT DETAILS

Sample input 1:
A2S3D06D13

Sample output 2:
Seat Number
D13
D14
D15
D16
D17

Sample input 2:
A2S3D02C01

Sample Output2:
Seat Number
C1
C2

import java.util.*;
import java.util.regex.Pattern;
public class Main{
public static void main(String args[]){
Scanner sc = new Scanner(System.in);

String str = sc.next();


if(str.length()!=10){
System.out.println("Invalid Input");
return;
}

if(Pattern.matches("[0-9]+",str.substring(5,7)) && Integer.parseInt(str.substring(5,7))>=1


&& Integer.parseInt(str.substring(5,7))<=10){
int seatnumber = Integer.parseInt(str.substring(5,7));
String eightletter = str.substring(7,8);
if(Pattern.matches("[A-Za-z]",eightletter) && Pattern.matches("[0-9]+",str.substring(8,10))){
int n = Integer.parseInt(str.substring(8,10));
for(int i=0;i<seatnumber;i++){
System.out.println(eightletter + (n++));
}
}
else{
System.out.println("Invalid Seat Number");
return;
}
}
else{
System.out.println("Invalid Count");
return;
}
}
}
**********************************************************************************************
***************************************************************************

45) CALCULATE OFFER PRICE (DISCOUNT PRICE)

import java.util.Scanner;

public class DiscountPrice {


public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
String code=sc.nextLine();
int len=code.length();
if(len<6 || len>8)
{
System.out.println("Invalid Input");
return;
}
String mrps=code.substring(4);
int mrp=Integer.parseInt(mrps);
System.out.println("MRP Price :"+mrp);
if(mrp>=1 && mrp<=10)
{
System.out.println("Offer Price: Rs"+mrp);
}
else if(mrp>=11 && mrp<=50)
{
System.out.println("Offer Price: Rs"+(mrp-5));
}
else if(mrp>=51 && mrp<=500)
{
System.out.println("Offer Price: Rs"+(mrp-15));
}
else if(mrp>= 501 && mrp<=5000)
{
System.out.println("Offer Price: Rs"+(mrp-105));
}
else if(mrp>=5001 && mrp<=9999)
{
System.out.println("Offer Price: Rs"+(mrp-1005));
}
}
}
**********************************************************************************************
*******************************************************************************

46) THREE’S

Sample input:
Enter the string
Long live

import java.util.*;
import java.lang.*;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("Enter the String");
String str =in.nextLine();
for(int i=0;i<str.length();i++)
{
if((Character.isLetter(str.charAt(i)) || Character.isWhitespace(str.charAt(i))))
continue;
else{
System.out.println(str+" is not a valid string");
return;
}
}
int sum=0;
for(int i=0;i<str.length();i++){
if((i+1)%3==0){
sum+=(int)str.charAt(i);
}
}
System.out.println("Sum is "+sum);
}
}
**********************************************************************************************
**********************************************************************************
47) EVEN POSITION CAPS (CAPITAL LETTERS)

import java.util.Scanner;
import java.util.regex.Pattern;

public class EvenPositionCaps {


public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Input string");
String s = sc.nextLine();
if (!Pattern.matches("[A-Za-z]+", s)) {
System.out.println(s + " is an invalid input");
return;
} else {
if (s.length() < 5 || s.length() > 20) {
System.out.println(s + " is an invalid length");
return;
}
String output = s.charAt(0) + "";
for (int i = 0; i < s.length() - 1; i++) {
if ((i) % 2 == 0)
output += Character.toString(s.charAt(i + 1)).toUpperCase();
else
output += s.charAt(i + 1);
}
System.out.println(output);
}
}
}

***ALTERNATE METHOD***

import java.util.*;
import java.util.regex.Pattern;
public class Main{
public static void main(String args[]){
Scanner sc = new Scanner(System.in);

System.out.println("Input string");
String str = sc.next();
if(Pattern.matches("[A-Za-z]+",str)){

if(str.length()<5 || str.length()>20){
System.out.println(str+" is an invalid length");
return;
}
String output = str.charAt(0)+"";
for(int i=0;i<str.length()-1;i++){
if(i%2==0){
output = output+ Character.toString(str.charAt(i+1)).toUpperCase();
}
else
output = output + str.charAt(i+1);
}
System.out.println(output);
}
else{
System.out.println(str+" is an invalid input");
return;
}
}
}
**********************************************************************************************
****************************************************************************************

48) FUN COUNT

public class FunCount {


public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number of toys:");
int n=sc.nextInt();
if(n<=0)
{
System.out.println("Invalid Input");
}
else if(n>15)
{
System.out.println("Number exceeds the limit");
}
else{
String[] a=new String[n];
System.out.println("Enter the toy list");
for(int i=0;i<n;i++)
{
a[i]=sc.next().toLowerCase();
}
Arrays.sort(a);
int count=0;
for(int i=0;i<n;i++)
{
count=1;
for(int j=i+1;j<n;j++)
{
if(a[i].equalsIgnoreCase(a[j]))
{
count++;
a[j]="0";
}
}
if((a[i])!="0")
{
System.out.println(a[i]+"="+count);
}

}
}
}
}
**********************************************************************************************
*******************************************************************************

49) SPEED ESTIMATION

import java.util.*;
public class Main{
public static void main(String args[]){
Scanner sc = new Scanner(System.in);

System.out.println("Enter the distance in kilometre");


int km = sc.nextInt();

if(km<=0){
System.out.println("Invalid Input");
return;
}

System.out.println("Enter the time to reach in hours");


int time = sc.nextInt();
if(time<=0){
System.out.println("Invalid Input");
return;
}

int sp = km/time;
if(sp>30){
int in_sp = sp-30;
System.out.println("You want to increase a speed "+in_sp+" km/hr from a normal speed");
}
else{
System.out.println("You drive a car at a normal speed");
}
}
}
***********************************************************************************************
*********************************************************************************
50) SUM OF SQUARES (RE-TEST)

Sample input
Enter the number of values
4
Enter the values
2
7
9
8

Sample output
130

Explanation
Odd numbers are 7,9 = 7*7 +9*9 = 49+81=130
import java.util.*;
public class Main
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number of values");
int n=sc.nextInt();
if(n<=0)
{
System.out.println(n+" is an invalid size");
return;
}
int a[]=new int[n];
int count=0;
int sum=0;
System.out.println("Enter the values");
for(int i=0;i<n;i++)
{
a[i]=sc.nextInt();
if(a[i]%2!=0)
count=count+1;
}
if(count<=0)
{
System.out.println("These "+n+" values are not a odd digit");
return;
}
else
{
for(int i=0;i<n;i++)
{
if(a[i]%2!=0)
{
sum=sum+a[i]*a[i];
}
}
System.out.println(sum);
}

}
}

JAVA END
*********************************************************************************************
*********************************************************************************************
********

RDBMS IMPORTANT CODES(NOT TESTED)


1.)Select concat(concat(customer_name,'has taken a
policy on'),date_of_policy) as Enrollment_details
from customer JOIN Policy using (customer_id)
order by customer_name,date_of_policy;

2.)select plolicy_id,policy_name,rate_of_interest, bonus_percentage


from policy
where minimum_primeium_amount = 1200
order by policy_d;

3.)select fine_range,fine_amount
CASE
When fine_range=L1
then 5+fine_amount
when fine_range=L2
then 10+fine_amount
When fine_range=M1
then 15+fine_amount
when fine_range=M2
then 20+fine_amount
When fine_range=H1
then 25+fine_amount
when fine_range=H2
then 30+fine_amount
END as NEW_FINE_AMOUNT

4.)select leave_type,allocated_days
CASE
when leave_type='CASUAL'
then allocated_days+2
when leave_type='SICK'
then allocated_days+5
when leave_type='MATERNITY'
then allocated_days+90
when leave_type='MARRIAGE'
then allocated_days+3
when leave_type='STUDY'
then allocated_days-2
END as NEW_ALLOCATED_TYPES
from table_name
order by leave_type;

5.) select emp_id,emp_name,department_id,department_name


from Department JOIN Employee using (department_id)
JOIN Leave+Avail_details using (Emp_id)
JOIN Leave using (Leave_type)
where Allocated_days = 0
order by emp_id;
*********************************************************************************************
**

1.) Account Info - "HDVL002"


select account_type, count(account_id) as TOTAL_ACCOUNTS
from Acount_Info where IFC_Code = 'HDVL002'
group by account_type order by account_type;

2.)select customer_id,customer_name,phone_no,order_date
from Customer_info JOIN Orders using (customer_id)
where order_amount > 500
order by customer_id,order_date;

3.) select distinct customer_id,customer_name,phone_no,loan_amount as


total_loan_amount from customers JOIN loans_taken using
(customer_id)
order by customer_id;

4.) select distinct boat_id,seat_capacity,count(ride_id) as ride_count


From Boat_details JOIN Ride_details using (boat_id)
order by boat_id;

5.) select customer_id,customer_name,contact_no,mail_id


from Coustomer_details where Gender = 'M'
order by customer_id;
6.) select customer_name,total_amount_paid
from Customer_master JOIN Booking_details using (customer_id)
where total_amount_paid < (select max(total_amount_paid) from booking_details
where total_amount_paid < (select max(total_amount_paid) from booking_details))
order by customer_name;

7.) select book_code,book_title, author,rack_num


from book_details where category = 'JAVA'
order by book_code;

8.) select customer_name,policy_enrollment as Enrollment_details


from customer JOIN policy_enrolmment using (customer_id)
order by customer_name,date_of_enrollment;

9.)DECODE QUESTION
select fine_range, fine_amount,
decode(fine_range, 'L1',fine_amount+5,
'L2',fine_amount+10,
'M1',fine_amount+10,
'M2',fine_amount+10,
'H1',fine_amount+10,
'H2',fine_amount+10)new_fine_amount
from fine_details;

10.)select customer_name||" has taken policy on"|| date_of_enrollment as


enrollment_details form customer
join policyenrollent using (customer_id)
order by customr_name,date_of_enrollment;

11.)select policy_id,policy_name,rate_of_interest,bonus_percentage
from policy where mimum_premium_amount = 1200
order by policy_id;

12.) select customer_id,customer_name, street,phone_no,email


from Customers JOIN loan_taken using (customer_id)
where loan_amount > = 500000 and loan_amonunt <1500000
order by customer_id;

13.)select distinct boat_id, boat_name,boat_type


from boat_details JOIN ride_details using (boat_id)
where DOT LIKE '%-AUG-%' and Shift = 'evening'
order by boat_id;

14.) select policy_id,policy_name,rate_of_interest


from policy where miniimum_ppremium_amount < 3000 AND bonus_percent > 85
order by policy_id;

RDBMS ANSWERS

1.1) Write a query to display boat_type and number of boats running under each type. Give an alias name as 'NO_OF
_BOATS'.
Note: Boat_type can be 'DELUXE' or 'SUPER DELUXE'.

select boat_type,count(Boat_id) as NO_OF_BOATS


from boat_details
group by Boat_type;

1.2) select boat_name,boat_type from boat_details


where seat_capacity between 100 and 200
order by boat_name desc;

2.1) select vehicle_type,count(vehicle_id)


from vehicle_details
group by vehicle_type
order by vehicle_type;

2.2) select driver_id,driver_name,phone_no,Driver_rating


from driver_details where driver_rating between 3 and 5
order by driver_rating desc;

3.1) select coursename from course


c join registration r on
c.courseid=r.courseid
having count(studid)>=2
group by coursename
order by coursename;

3.2) select s.studid,sum(fees) as TOTALFEES


from student s join registration r
on s.studid=r.studid join course c
on r.courseid=c.courseid
group by s.studid
order by s.studid;

3.3) select studid,count(CourseID) as NOOFCOURSES


from registration
group by Studid
order by NOOFCOURSES desc,Studid;

3.4) select student.stuid,firstname from student


join registration on registration.stuid=student.stuid
where lower(to_char(doj,'MON'))='jan';

3.5) select courseid,coursename from


course where duration between 10 and 15;

3.6) select courseid,registration.stuid from registration


join student on registration.stuid=student.stuid
where lower(to_char(doj,'MON'))=lower(to_char(dob,'MON'));
JAVA

1. LCM OF DAY INTERVAL/LUNCH TOGETHER/DINNER TOGETHER

INPUT: Enter the day interval of Tony : 4


Enter the day interval of Potts: 6

OUTPUT: Tony and Potts will have dinner together on 12th day.

import java.util.Scanner;
public class lcm {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the day interval of Sam:");
int n1 = sc.nextInt();
System.out.println("Enter the day interval of Riya:");
int n2 = sc.nextInt();
if(n1<=0 || n2<=0)
{
System.out.println("Given interval is not valid");
return;
}
int lcm;
lcm = (n1 > n2) ? n1 : n2;
while(true) {
if( lcm % n1 == 0 && lcm % n2 == 0 ) {
System.out.printf("Sam and Riya will have their dinner on day "+lcm);
break;
}
++lcm;
}
}
}

ALTERNATE METHOD

import java.util.Scanner;
public class Lunchlcm {
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the day interval of Tony");
int n1=sc.nextInt();
System.out.println("Enter the day interval of Potts");
int n2=sc.nextInt();
if(n1<=0 && n2<=0)
{
System.out.println("Given interval is not valid");
return;
}
int a=n1;
int b=n2;
while(n2>0)
{
if (n1 > n2)
{
n1 = n1 - n2;
} else
{
n2 = n2 - n1;
}
}
int gcd = n1;
int lcm = (a * b) / gcd;

System.out.println("Tony and Potts will have lunch together on " + lcm + " day");
}
}

*********************************************************************************************
*********************************************************************************************
**
2.SCORE OF REPEATING WORDS/ WORD REPETITION

INPUT: Enter the String: GOOD


Enter the sentence: GOOD FOOD GOOD LIFE

OUTPUT: Score is 2

import java.util.*;
class PrintMessage
{
public static void main (String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the string");
String s=sc.next();
int count=0;
int sum=2;
for(int i=0;i<s.length();i++)
{
if(Character.isDigit(s.charAt(i)) || Character.isLetter(s.charAt(i)) || s.charAt(i)==' ')
{
continue;
}
else
{
System.out.println(s+" is not valid String");
return;
}
}
System.out.println("Enter the sentence");
sc.nextLine();
String sentence=sc.nextLine();
String[] w=sentence.split(" ");
for(int i=0;i<w.length;i++)
{
if(w[i].equalsIgnoreCase(s))
{
count++;
if(count>2)
{
sum=sum*2;
}
}
}
if(count>2)
{
System.out.println("Score is "+sum);
}
else
{
System.out.println("Score is"+count);
}
}
}

*ALTERNATE METHOD

import java.util.Scanner;
public class CountWords {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String word, sentence;ed
int count = 0;
System.out.println("Enter a word:");
word = in.nextLine();
System.out.println("Enter a sentence");
sentence = in.nextLine();

if (!(word.matches("[a-z]+"))) {
System.out.println("Invalid Input");
return;
}
String words[] = sentence.toLowerCase().split(" ");
for (int i = 0; i < words.length; i++) {
if (word.equals(words[i])) {
count++;
}
}
System.out.println("Score is:" + ((int) Math.pow(2, count - 1)));
}
}
*********************************************************************************************
*********************************************************************************************
***

3)BATTERY CAPACITY

INPUT: Enter battery capacity :1230


Enter charging current value: 400

OUTPUT: 3.69 Hours

import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter battery capacity:");
double capacity = sc.nextDouble();
if(!(capacity>=1000 && capacity<=10000)) {
System.out.println("Invalid battery capacity");
return;
}
System.out.println("Enter charging current value:");
double current = sc.nextDouble();
if(!(current>=300 && current<=2100)) {
System.out.println("Invalid output current");
return;
}
double time=0.0f;
time = (capacity/current)*1.2;
System.out.println(String.format("%.2f",time)+" Hours");
}

*********************************************************************************************
*********************************************************************************************
***
4) COMBINE NUMBERS / STUDENTS WHOSE ROLLNO ARE ODD

INPUT: Entr the set of students :5


Enter the roll number :1
3
4
5
6

OUTPUT: 135

import java.util.*;
public class Main
{
public static void main(String[] args) {
System.out.println("Enter the set of students");
Scanner s=new Scanner(System.in);
int setn=s.nextInt();
if(setn<=0)
{
System.out.println(setn+" is an invalid size");
return;
}
System.out.println("Enter the roll number");
int[] rolls=new int[setn];
int oddflag=0;
for(int i=0;i<setn;i++)
{
rolls[i]=s.nextInt();
if(rolls[i]<0)
{
System.out.println(rolls[i]+" is an invalid roll number");
return;
}
if(rolls[i]%2!=0)
{
oddflag=1;
}
}
if(oddflag==0)
{
System.out.println("The "+setn+" numbers are not odd");
return;
}
String str="";
for(int i=0;i<setn;i++)
{
if(rolls[i]%2!=0)
{
str=str+rolls[i];
}
}
for(int n=0;n<str.length();n++)
{
System.out.println(str.charAt(n)+" ");
}
}
}
*********************************************************************************************
*********************************************************************************************
**

5) BIKE RENT / CALCULATING BILL AMOUNT

INPUT : Enter your name : Sam


Enter the time duration: 13
List of payment options
1)Visa card
2)Rupay card
3)Master card
Choose an option : 2

OUTPUT: Dear Sam your bill amount is 1294.80

import java.util.*;
public class Main
{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter your name");
String s=sc.nextLine();double sal=0;double disc=0;
for(int i=0;i<s.length();++i)
{
if(!Character.isLetter(s.charAt(i)))
{
System.out.println("Invalid Name");
return;
}
}
System.out.println("Enter the time duration");
int n=sc.nextInt();int n1;
if(n<=0 || n>24)
{
System.out.println("Invalid duration");
return;
}
System.out.println("List of payment options");
System.out.println("1)Visa card");
System.out.println("2)Rupay card");
System.out.println("3)Master card");
System.out.println("Chosse an option");
while(true)
{
n1=sc.nextInt();
if(n1<0||n1>3)
{
System.out.println("Try again");
}
else
{
break;
}
}
if( n1==1)
{
if(n>=5)
{
sal=120*n;
disc=(sal*0.25);
sal=sal-disc;
}
else
{
sal=n*120;
}
}
if(n1==2)
{
if(n>=5)
{
sal=120*n;
disc=(sal*0.17);
sal=(120*n)-disc;
}
else
{
sal=n*120;
}
}
if(n1==3)
{
sal=n*120;
}
System.out.print("Dear "+s+" your bill amount is ");
System.out.printf("%.2f", sal);
}
}

*********************************************************************************************
*********************************************************************************************
***
6) ODD POSITION CHAR WILL BE IN UPPERCASE & EVEN WILL BE LOWERCASE-

INPUT : school

OUTPUT : sChOol

import java.util.Scanner;
public class UPLC{
public static void main(String []args){
Scanner sc = new Scanner(System.in);
String str = sc.next();
int strlen = str.length();
for(int i = 0 ; i < str.length(); i++){
char ch = str.charAt(i);
if(!(ch >= 'a' && ch <='z' || ch >= 'A' && ch <='Z' )){
System.out.println(str+ " is an invalid input");
return;
}
}

if(strlen >= 5 && strlen <= 20){


StringBuffer updateString = new StringBuffer();
char[] charArr = str.toCharArray();
for(int i = 0 ; i < charArr.length; i++){
char ch = charArr[i];
if(i % 2 != 0){
ch = Character.toUpperCase(ch);
}
updateString.append(ch);
}
System.out.println(updateString.toString());
}
else {
System.out.println(str+ " is an invalid Length");
}
}
}

*********************************************************************************************
*********************************************************************************************
****
7) RATING SCORE

INPUT: ENTER JESSON SCORE


1
2
3
4
8
ENTER JAMES SCORE
0
2
6
5
6

OUTPUT: JESSON SCORE : 2


JAMES SCORE : 2

import java.util.Scanner;
public class Ratingscore {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter Jesson Score");
int[] a1 = new int[5];
int[] a2 = new int[5];
int f = 0;
int t = 0;
int sum = 0;
int sum1 = 0;
for (int i = 0; i < 5; i++) {
a1[i] = sc.nextInt();
if (a1[i] < 0) {
f = 1;
t = a1[i];
break;
}
}
if (f == 1) {
System.out.println(t + " is invalid");
} else {
System.out.println("Enter James Score");
for (int j = 0; j < 5; j++) {
a2[j] = sc.nextInt();
if (a2[j] < 0) {
f = 1;
t = a2[j];
break;
}
}
if (f == 1) {
System.out.println(t + " is invalid");
} else {
for (int k = 0; k < 5; k++) {
if (a1[k] > a2[k]) {
sum++;
}
if (a1[k] < a2[k]) {
sum1++;
}
}
System.out.println("Jesson Score");
System.out.println(sum);
System.out.println("James Score");
System.out.println(sum1);
}
}
}
}

**ALTERNATE METHOD:

import java.util.Scanner;
public class minmax {
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
int jesson=0,james=0,c=0;
int a[]=new int[5];
int b[]=new int[5];
System.out.println("Enter Jesson Score");
for(int i=0;i<a.length;i++)
{
a[i]=sc.nextInt();
if(a[i]<0)
{
System.out.println("Invalid");
Runtime.getRuntime().halt(0);
}
}
System.out.println("Enter James Score");
for(int i=0;i<b.length;i++)
{
b[i]=sc.nextInt();
if(b[i]<0)
{
System.out.println("Invalid");
Runtime.getRuntime().halt(0);
}
}
if(a.length==b.length)
{
for(int i=0;i<a.length;i++)
{
if(a[i]>b[i])
{
jesson++;
}
else if(a[i]<b[i])
{
james++;
}
else if(a[i]==b[i])
{
c++;
}
}
System.out.println("Jesson Score: "+jesson);
System.out.println("James Score: "+james);
}
else{
System.out.println("Length not same");
}
}
}

*********************************************************************************************
*******************************************************************************

8.COUNT OF UPPERCASE AND COUNT OF LOWERCASE & OUTPUT WILL BE IN THE FORM OF
(UP-LC)

INPUT : HosTEL

OUTPUT: 4-2=2

import java.util.Scanner;

public class ContNext {


public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the string");
String str=sc.nextLine();
int uc=0,lc=0;
if(str.matches("[A-Za-z ]+")&&str.length()<10) {
for(int i=0;i<str.length();i++)
if(Character.isUpperCase(str.charAt(i))) {
uc++;
}
else if(Character.isLowerCase(str.charAt(i))){
lc++;
}
System.out.println(uc-lc);
}
}
}
*********************************************************************************************
*******************************************************************************
9) PRODUCT of COUNT of UPPERcase

andLOWERcaseletters

INPUT: ABsdEr

OUTPUT: 6 (3*3)

import java.util.Scanner;
public class minmax {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the String");
String s = sc.nextLine();
int upper = 0;
int lower = 0;
int i;
if (s.matches("[a-zA-Z]+")) {
for (i = 0; i < s.length(); i++) {
char c = s.charAt(i);
if (c >= 'A' && c <= 'Z') {
upper++;
}
if (c >= 'a' && c <= 'z') {
lower++;
}
}
System.out.println(upper * lower);
}
else
{
System.out.println("Invalid String");
}

}
}

*********************************************************************************************
******************************************************************************
10.Count of UPPERcase and LOWERcase and their difference

Enter the String: ColLEgE


Count of uppercase is : 4
Count of lowercase is : 3
Hence the ans is : 1

import java.util.Scanner;
public class MyClass {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the String ");
String str = sc.next();
int strlen = str.length();
for(int i =0; i < str.length() ; i++)
{ char ch = str.charAt(i);
if(!(ch >='a' && ch <= 'z' || ch >= 'A' && ch <= 'Z')){
System.out.println(str + " is an invalid String");
return;
}
}

if(strlen > 0 && strlen <= 10){


int upper = 0, lower = 0, ans = 0;

for(int i = 0; i < str.length(); i++)


{
char ch = str.charAt(i);
if (ch >= 'A' && ch <= 'Z')
upper++;
else if(ch >= 'a' && ch <= 'z')
lower++;
}
ans = upper - lower;
System.out.println("count of uppercase is :"+ upper);
System.out.println("count of lowercase is :"+ lower);
System.out.println("Hence the ans is :"+ ans);
}
else {
System.out.println(str + " is an invalid String");
}
}
}
*********************************************************************************************
*******************************************************************************
11.PUBLIC DISTRIBUTION

INPUT : OKR

OUTPUT : 90

import java.util.*;
public class Main
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
String str = in.nextLine();
int l=str.length();
if(l>5 || l<2)
{
System.out.println("Invalid Input");
}
else
{
int sum=0,flag=0;
for(int i=0;i<l;i++)
{
char c=str.charAt(i);
if(c=='O')
{
sum=sum+24;
}
else if(c=='K')
{
sum=sum+36;
}
else if(c=='S')
{
sum=sum+42;
}
else if(c=='R')
{
sum=sum+30;
}
else if(c=='W')
{
sum=sum+44;
}
else
{
flag=1;
}
}
if(flag==1)
{
System.out.println("Invalid Input");
}
else
{
System.out.println(sum);
}
}
}
}
*********************************************************************************************
******************************************************************************

12.LOTTERY TICKETS

INPUT: Enter the Starting range


23467
Enter the Ending range
23477

OUTPUT: 23469
23472

import java.util.*;
public class Main {
public static void main(String args[])
{
int i,c,n,sum,count;
sum=0;count=0;n=0;c=0;i=0;
Scanner sc = new Scanner(System.in);
System.out.println("Enter the Starting range");
int a = sc.nextInt();
String str = Integer.toString(a);
if(str.length()!=5)
{
System.out.println(str + " is an invalid input");
System.exit(0);
}

System.out.println("Enter the Ending range");


int b = sc.nextInt();
String str1 = Integer.toString(b);
if(str1.length()!=5)
{
System.out.println(str1 + "is an invalid input");
System.exit(0);
}

if(a>b)
{
System.out.println(a+" and "+b+" are invalid serial numbers");
System.exit(0);

}
for(i=a;i<=b;i++)
{
n=i;
while(n!=0)
{
c=n%10;
sum=sum+c;
n=n/10;
}
if((sum%3==0)&&((sum/3)%2==0))
{
System.out.println(i + " ");
count++;
}
sum=0;
}
if(count==0)
{
System.out.println("Eligible tickets are not available from "+a+" to "+b);
System.exit(0);
}
}
}

*********************************************************************************************
******************************************************************************
13.COFFEE STALL NUMEROLOGY

INPUT : Enter the Staff Name


Coffee Bar

OUTPUT : Coffee Bar satisfies the numerology logic

import java.util.*;
public class Main{
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the Staff Name");
String name = sc.nextLine();
int count=0;
for(int i=0;i<name.length();i++){
if(Character.isAlphabetic(name.charAt(i)) || name.charAt(i)==' '){
count++;
}
}
if(count==name.length()){
String str = name.replace(" ","");
int sum=0;
for(int i=0;i<str.length();i++){
sum += i;
}
if(sum%2==0){
System.out.println(name+" satisfies the numerology logic");
}else{
System.out.println(name+" does not satisfy the numerology logic");
}
}else{
System.out.println("Invalid Input");
}
}
}

*ALTERNATE METHOD USING -matches for same question

import java.util.*;
public class Main{
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the Staff Name");
String name = sc.nextLine();
if(name.matches("[a-zA-Z ]+")){
String str = name.replace(" ","");
int sum=0;
for(int i=0;i<str.length();i++){
sum += i;
}
if(sum%2==0){
System.out.println(name+" satisfies the numerology logic");
}else{
System.out.println(name+" does not satisfy the numerology logic");
}
}else{
System.out.println("Invalid Input");
}
}
}

*ALTERNATE METHOD

import java.util.Scanner;
public class CoffeeHouse {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the Stall Name");
String name = sc.nextLine();
if (name.matches("^[A-Za-z ]*$")) {
int sum = 0;
String fName = name.replaceAll(" ", "");
for (int i = 0; i < fName.length(); i++)
sum = sum + i;
if (sum % 2 == 0) {
System.out.println(name + " satisfies the numerology logic");
} else {
System.out.println(name + " not satisfies the numerology logic");
}
} else
System.out.println("Invalid Input");
}
}

*********************************************************************************************
******************************************************************************

14.ANAGRAM OR TWO WORDS OF SAME LETTER

INPUT : cat
act

OUTPUT: Same

import java.util.Arrays;
import java.util.Scanner;
public class minmax {
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter sentence 1");
String s1=sc.next();
s1=s1.toLowerCase();
System.out.println("Enter sentence 2");
String s2=sc.next();
s2=s2.toLowerCase();
if(s1.length()!=s2.length())
{
System.out.println("Invalid");
}
if(s1.matches("^[a-zA-Z]*")){
char c1[] = s1.toLowerCase().toCharArray();
char c2[] = s2.toLowerCase().toCharArray();
Arrays.sort(c1);
Arrays.sort(c2);
if (Arrays.equals(c1, c2)) {
System.out.println(s1 + " and " + s2 + " contain the same characters");
} else {
System.out.println(s1 + " and " + s2 + " contain the different characters");
}
}
else
{
System.out.println("Invalid");
}
}
}

ALTERNATE METHOD:

import java.util.*;
public class Main{
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
String first=sc.next();
String secound=sc.next();
String word1=Main.checker(first);
String word2=Main.checker(secound);
if(word1.equals(word2)){
System.out.println("Same");
}else{
System.out.println("Different");
}
}
public static String checker(String word){
char arr[]=word.toCharArray();
Arrays.sort(arr);
int index=0;
for(int i=0;i<arr.length;i++){
int j;
for(j=0;j<i;j++){
if(arr[j]==arr[i]){
break;
}
}
if(i==j){
arr[index++]=arr[i];
}
}
char arr1[]=Arrays.copyOf(arr,index);
String newword= new String(arr1);
return newword;
}
}

ALTERNATE METHOD

import java.util.*;
public class arraysquare {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int f1=0,f2=0;
String s1=sc.nextLine();
char c1[]=s1.toCharArray();
String s2=sc.nextLine();
char c2[]=s2.toCharArray();
for(int i=0;i<c1.length;i++)
{
f1=0;
for(int j=0;j<c2.length;j++)
{
if(c1[i]==c2[j])
{
f1=1;
break;
}
}
if(f1==0)
{
break;
}
}
for(int i=0;i<c2.length;i++)
{
f2=0;
for(int j=0;j<c1.length;j++)
{
if(c2[i]==c1[j])
{
f2=1;
break;
}
}
if(f2==0)
{
break;
}
}
if(f1==1 && f2==1)
{
System.out.println("Same Char");
}
else{
System.out.println("Different char");
}
}
}

*********************************************************************************************
*****************************************************************************
15.SUMMATION OF EVEN NUMBERS IN THE ARRAY

INPUT : Enter array size


4
Enter array elements in 1st array
2
4
6
8
Enter array elements in 2nd array
1
2
5
2

OTPUT: 0
6
0
10

import java.util.*;
public class Main
{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter array size");
int n=sc.nextInt();
if(n>=10 || n<1)
{
System.out.println(n+" is an invalid input");
Runtime.getRuntime().halt(0);
}
int arr1[]=new int[n];
int arr2[]=new int[n];
int result[]=new int[n];
System.out.println("Enter array elements in 1st array");
for(int i=0;i<n;i++)
{
arr1[i]=sc.nextInt();
}
System.out.println("Enter array elements in 2nd array");
for(int i=0;i<n;i++)
{
arr2[i]=sc.nextInt();
}
//PROGRAM LOGIC
int count=0;
for(int i=0;i<n;i++)
{
if((arr1[i]%2==0 || arr1[i]==0) && (arr2[i]%2==0 || arr2[i]==0))
{
result[i]=arr1[i]+arr2[i];
count++;
}
else
{
result[i]=0;
}
}
if(count==0)
{
System.out.println("No even number is present in an Array");
}
for(int i=0;i<n;i++)
{
System.out.println(result[i]);
}
}
}

*********************************************************************************************
******************************************************************************
16.RUNNERS COMPETITION

INPUT :Enter the number of runners


5

Enter the runner details


Robert,9.38
Richard,9.35
Christiano,9.35
Williams,9.36
Vinix,9.35

OUTPUT: Richard
Christiano
Vinix

import java.util.*;
public class Main{
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
sc.useDelimiter("\n");
System.out.println("Enter the number of runners");
int n = sc.nextInt();
if(n<=0 || n>10){
System.out.println(n+" is an invalid number of runners");
Runtime.getRuntime().halt(0);
}
String temp = "";
String name[] = new String[n];
float time[] = new float[n];
System.out.println("Enter the runner details");
for(int i=0;i<n;i++){
temp = sc.next();
String temparr[] = temp.split(",");
name[i] = temparr[0];
time[i] = Float.parseFloat(temparr[1]);
if(time[i]>12 || time[i]<8){
System.out.println(time[i]+" is an invalid input");
Runtime.getRuntime().halt(0);
}
}
int maxcount = 0;
float maxrep = 0;
for(int i=0;i<n;i++){
int count = 0;
for(int j=i+1;j<n;j++){
if(time[i]==time[j]){
count++;
}
}
if(count>=maxcount){
maxcount = count;
maxrep = time[i];
}
}
if(maxcount==n){
System.out.println(n+" runners have same timing");
}
else if(maxcount==0){
System.out.println("No runners with same time.");
}
else{
for(int i=0;i<n;i++){
if(maxrep == time[i]){
System.out.println(name[i]);
}
}
}
}
}

****ALTERNATE METHOD****

public static void main(String[] args) {


// TODO code application logic here
Scanner sc=new Scanner(System.in);
System.out.println("Enter the no of students");
int n=sc.nextInt();
if(n>10)
{
System.out.println(n+" is an invalid nuber of runners");
return;
}
String input;
String name[]=new String[n]; //name array
Double time[]=new Double[n]; //another time array
System.out.println("Enter the details");
for(int i=0;i<n;i++)
{
input=sc.next();
String[] a=input.split(","); // a[0] stores name a[1] stores time
name[i]=a[0]; //string->string
time[i]=Double.parseDouble(a[1]); //double<-string
if(time[i]<8 || time[i]>12)
{
System.out.println(time[i]+" is an invalid input");
return;
}

}
boolean flag = true;

double min=time[0];
int index=0;

for(int i=0;i<n;i++)
{
if(time[i]<min)
{
min=time[i];
//index=i;
}

if(min!=time[i])
{
flag=false;
System.out.println(name[i-1]);
}

}
if (flag) System.out.println(n+" runners have same timing");
}

}
*********************************************************************************************
******************************************************************************
17.REEDME

INPUT : Enter the customer name


Abi
Enter the category
History
Enter the quantity of books ordered
2900

OUTPUT : Total cost is 334080.0


import java.util.*;
public class Main{
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the customer name");
String name = sc.nextLine();
System.out.println("Enter the category");
String category = sc.nextLine();
category = category.toLowerCase();

if(!category.equals("adventure") && !category.equals("comics") && !category.equals("history") && !categ


ory.equals("thriller")){
System.out.println(category+" is invalid category");
Runtime.getRuntime().halt(0);
}
System.out.println("Enter the quantity of books ordered");
int quantity = sc.nextInt();
if(quantity <= 0){
System.out.println(quantity+" is an invalid quantity");
Runtime.getRuntime().halt(0);
}
int discount = 0;
int price = 0;
if(category.equals("adventure")){
price = 150;
if(quantity>=1700)
discount = 5;
}
else if(category.equals("comics")){
price = 230;
if(quantity>=1950)
discount = 5;
}
else if(category.equals("history")){
price = 120;
if(quantity>=2600)
discount = 4;
}
else if(category.equals("thriller") && quantity>=1700){
price = 190;
if(quantity>=6300)
discount = 3;
}
float totalcost = (price*quantity) - (price*quantity*discount/100);
System.out.println("Total cost is "+totalcost);
}
}

*********************************************************************************************
******************************************************************************
18)HARSHAD NUMBER (Sum of digit completely divide that

number) For example: 18= 1+8=9 and in 18/9 remainder is 0

INPUT: Enter array size: 5


Enter array elements : 18 14 12 24 13

OUTPUT: 18 12 24

import java.util.Scanner;
public class Harshad {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the number of values");
int n = sc.nextInt();
int i;
System.out.println("Enter the numbers");
int[] a = new int[n];
if (n > 0)
{
int flag = 0;
int k = 0;
for (i = 0; i < n; i++)
{
k = sc.nextInt();
if (k > 9)
a[i] = k;
else
{
flag = 1;
break;
}
}
if (flag != 1)
{
int c = 0;
for (i = 0; i < n; i++)
{
int x = a[i];
int sum = 0;
do {
int r = x % 10;
sum = sum + r;
x = x / 10;
}
while (x != 0);
if (a[i] % sum == 0)
{
c++;
System.out.println(a[i]);
}
}
if (c == 0)
System.out.println("The " + n + " values are not harshad number");
}
else
System.out.println("Provided " + k + " is not valid");
} else
System.out.println(n + " is an invalid input");
}
}
****ALTERNATE METHOD******

import java.util.Scanner;
class Main
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number of values");
int n=sc.nextInt();
System.out.println("Enter the numbers");
int a[]=new int[n];
if(n>0)
{
int flag=0;
int k=0;
for(int i=0;i<n;i++)
{
k=sc.nextInt();
if(k>9) a[i]=k; else
{
flag=1;
break;
}
}
if(flag!=1)
{
int c=0;
for(int i=0;i<n;i++)
{
int x=a[i];
int sum=0;
do
{
int r=x%10; sum=sum+r; x=x/10;
}while(x!=0);
if(a[i]%sum==0)
{ c++;
System.out.println(a[i]);
}
}
if(c==0)
System.out.println("The "+n+" values are not harshad number");
}else
System.out.println("Provided "+k+" is not valid");
}else
System.out.println(n+" is an invalid input");
}
}
*********************************************************************************************
*********************************************************************************************
*******
19) VIDEO GAME PLAYER (PS1)

INPUT : Enter the amount


18000
Enter the Video Game Player Type
PS4

OUTPUT: You can buy PS4

public class PS {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the amount");
int amount = sc.nextInt();
if (amount >= 3000) {
System.out.println("Enter the Video Game Player Type");
String type = sc.next();
if (type.matches("[P][S][1-5]")) {
if (type.equals("PS1")) {
if (amount >= 5000) {
System.out.println("You can buy PS1");
} else {
System.out.println("You need more money to buy a PS1");
}
} else if (type.equals("PS2")) {
if (amount >= 7800) {
System.out.println("You can buy PS2");
} else {
System.out.println("You need more money to buy a PS2");
}
} else if (type.equals("PS3")) {
if (amount >= 9500) {
System.out.println("You can buy PS3");
} else {
System.out.println("You need more money to buy a PS3");
}
} else if (type.equals("PS4")) {
if (amount >= 12000) {
System.out.println("You can buy PS4");
} else {
System.out.println("You need more money to buy a PS4");
}
} else if (type.equals("PS5")) {
if (amount >= 15000) {
System.out.println("You can buy PS5");
} else {
System.out.println("You need more money to buy a PS5");
}
}
} else {
System.out.println(type + " is Invalid Type");
}
} else {
System.out.println(amount + " is too less");
}
}
}

*********************************************************************************************
*********************************************************************************************
****
20) ABSOLUTE DIFFERENCE / ALTERNATE SUM DIFFERENCE

INPUT :Enter number


6
Enter values
12
13
6
8
9
7
(((( logic: (12-7=a
13-9=b
6-8=c
a+b+c=ans)))))

OUTPUT 2
3
4
5
5-2=3
4-3=1
So 3+1= 4
*/

import java.util.*;
public class AltDiff {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int sum=0;
int n=sc.nextInt();
int a[]=new int[n];
for(int i=0;i<n;i++)
{
a[i]=sc.nextInt();
}
for(int i=0;i<n/2;i++)
{
sum+=Math.abs(a[i]-a[n-i-1]);
}
System.out.println(sum);
}
}
*********************************************************************************************
*********************************************************************************************
*****
21.CHARACTER
ADDITION

INPUT : Enter : 3
Enter the sentences:
ks436
Agh73
7222

OUTPUT: 222
240
0

import java.util.*;
public class arraysquare{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int sum=0;
System.out.println("Enter:");
int n=sc.nextInt();
if(n<=0)
{
System.out.println("The number of sentences "+n+" is invalid");
return;
}
System.out.println("Enter the sentences:");
String str[]=new String[n];
for(int i=0;i<n;i++)
{
str[i]=sc.next();
}
for(int i=0;i<str.length;i++)
{
String s=str[i].replaceAll("[0-9]","");
for(int j=0;j<s.length();j++)
{
char c=s.charAt(j);
int ascii=c;
sum+=ascii;
}
System.out.println(sum);
sum=0;
}

}
}

*********************************************************************************************
******************************************************************************************
22. REVERSE FIRST HALF/MIDDLE LETTER of the string if string length is ODD

Input:
if length of string is even, the reverse the string:
Ex: Food
Output:
dooF

Input:
If length of the string is odd,then find the middle char and then ,reverse the string till mid char and print remain char
acters as it is.
Ex: Samsung
Output:
maSsung

package FinalAss;
import java.util.*;
public class MidLett {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
String str=sc.nextLine();//rahul
int len=str.length();
if(len%2==0)
{
StringBuilder sb=new StringBuilder(str);
sb.reverse();
System.out.println(sb.toString());
}
else if(len%2!=0)
{
System.out.println("Length of string is " +len);
int mid=len/2;
mid++;
System.out.println("Substring of string is "+mid);
String substr=str.substring(0,mid-1);
String remainSub=str.substring(mid-1,len);
StringBuilder sb=new StringBuilder(substr);
sb.reverse();
System.out.println(sb.toString()+remainSub);

}
}
}

ALTERNATE METHOD:::

import java.util.Scanner;
import java.util.regex.Pattern;
public class minmax {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
String str=sc.nextLine();//rahul
if(!Pattern.matches("[A-Za-z]+",str))
{
System.out.println(str+" is not a valid string");
return;
}
else if(str.length()<2)
{
System.out.println("Size of string "+str.length()+" is too small");
return;
}
int len=str.length();
if(len%2==0)
{
StringBuilder sb=new StringBuilder(str);
sb.reverse();
System.out.println(sb.toString());
}
else if(len%2!=0)
{
int mid=len/2;
String substr=str.substring(0,mid);
String remainSub=str.substring(mid,len);
StringBuilder sb=new StringBuilder(substr);
sb.reverse();
System.out.println(sb.toString()+remainSub);

}
}
}

*********************************************************************************************
*********************************************************************************************
*****

23 .ONLINE SHOPPING

input:
enter the product
laptop
Actual price
45000
exchange?
yes
bill amount:
27000.00

import java.util.*;
public class arraysquare {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the Product:");
String prod=sc.nextLine();
int ed=0,pd=0;
if(prod.equals("Mobile"))
{
ed=15;
pd=15;
}
else if(prod.equals("Laptop"))
{
ed=20;
pd=20;
}
else if(prod.equals("Headset"))
{
ed=0;
pd=10;
}
else if(prod.equals("Charger"))
{
ed=0;
pd=5;
}
else{
System.out.println("Not available");
return;
}
System.out.println("Enter the actual Price: ");
int price=sc.nextInt();
if(price<100)
{
System.out.println("Invalid Price");
return;
}
System.out.println("Do u want to Exchange?");
String exc=sc.next();
if(exc.equals("Yes") || exc.equals("yes"))
{
double ap=price-(price*pd)/100;
double ev=(price*ed)/100;
double total=ap-ev;
System.out.printf("Total=%.2f",total);
}
else if(exc.equals("No") || exc.equals("no"))
{
double total=price-(price*pd)/100;
System.out.printf("Total=%.2f",total);
}
else
{
System.out.println("Invalid Option");
}
}
}

*********************************************************************************************
********************************************************************************************
24 .OPERATOR FOUND

input:
45
23

22
output
45-23=22

import java.util.*;
public class arraysquare {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter n1 and n2:");
int n1=sc.nextInt();
if(n1>0)
{
int n2=sc.nextInt();
if(n2>0)
{
System.out.println("Enter n3:");
int n3=sc.nextInt();
if(n3>0)
{
if(n1+n2==n3)
{
System.out.println(n1+"+"+n2+"="+n3);
}
else if(n1-n2==n3)
{
System.out.println(n1+"-"+n2+"="+n3);
}
else if(n1*n2==n3)
{
System.out.println(n1+"*"+n2+"="+n3);
}
else if(n1/n2==n3)
{
System.out.println(n1+"/"+n2+"="+n3);
}
else
{
System.out.println(n3+" is an invalid answer");
}
}
else{
System.out.println("Invalid");
}
}
else{
System.out.println("Invalid");
}
}
else{
System.out.println("Invalid");
}

}
}

***ALNERNATE METHOD****

import java.util.*;
public class Main{
public static void main(String args[]){
Scanner sc = new Scanner(System.in);

System.out.println("Enter the n1 and n2");


int n1 = sc.nextInt();
if(n1<=0){
System.out.println(n1+" is an invalid number");
return;
}
int n2 = sc.nextInt();
if(n2<0){
System.out.println(n2+" is an invalid number");
return;
}
boolean b = false;
System.out.println("Function answer n3");
int n3 = sc.nextInt();

if((n1+n2)==n3){
System.out.println(n1+"+"+n2+"="+n3);
b=true;
}
if((n1-n2)==n3){
System.out.println(n1+"-"+n2+"="+n3);
b=true;
}
if((n1*n2)==n3){
System.out.println(n1+"*"+n2+"="+n3);
b=true;
}
if((n1/n2)==n3){
System.out.println(n1+"/"+n2+"="+n3);
b=true;
}
if(b== false){
System.out.println(n3+" is an invalid number");
}
}
}

*********************************************************************************************
*********************************************************************************************
****

25 .PRODUCT EQUAL SUM

INPUT : Enter the array size


4
Enter the elements of the first array
12
35
56
34
Enter the elements of the second array
261
195
112
813
OUTPUT: 35,195
34,813

import java.util.*;
public class arraysquare
{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the array size");
int n=sc.nextInt();
if(n<=0)
{
System.out.println("Invalid array size");
return;
}
int a[]=new int[n];
System.out.println("Enter the elements of the first array");
for(int i=0;i<n;i++)
{
a[i]=sc.nextInt();
}
System.out.println("Enter the elements of the second array");
int b[]=new int[n];
for(int i=0;i<n;i++)
{
b[i]=sc.nextInt();
}
int x[]=new int[n];
int y[]=new int[n];
for(int i=0;i<n;i++)
{
int c=a[i];
int prod=1;
while(c!=0)
{
prod*=(c%10);
c/=10;
}
x[i]=prod;
prod=0;
}
for(int i=0;i<n;i++)
{
int s=b[i];
int sum=0;
while(s!=0)
{
sum+=(s%10);
s/=10;
}
y[i]=sum;
sum=0;
}
for(int i=0;i<n;i++)
{
if(x[i]==y[i])
{
System.out.println(a[i]+","+b[i]);
}
}
}
}

*********************************************************************************************
*********************************************************************************************
*

26. UNIQUE CHAR

input:
LIfe is inherently risky

output:
life is ihrtly risky

package FinalAss;
import java.util.*;
public class nonuniquetwo {
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
String sentence = sc.nextLine();
String[] words = sentence.split(" ");
for(String word : words)
{
System.out.print(getUnique(word) + " ");
}
sc.close();
}
public static String getUnique(String str)
{
StringBuffer sb = new StringBuffer();
for(int i = 0; i<str.length(); i++)
{
if(countFrequency(str.charAt(i), str) == 1)
{
sb.append(str.charAt(i));
}
}
String result = sb.toString();
return result;
}
public static int countFrequency(char c, String str)
{
int count = 0 ;
for(int i = 0; i<str.length(); i++)
{
if(str.charAt(i) == c)
{
count++;
}
}
return count;
}
}

***ALTERNATE METHOD*****

import java.util.*;
public class Main
{
public static void main(String[] args)
{
System.out.println("Enter the String");
Scanner sc=new Scanner(System. in);
String str=sc.nextLine();
String output="";
String[] word=str.split(" ");
for(int i=0;i<word.length;i++)
{
for(int j=0;j<word[i].length();j++)
{
int count=0;
char c=word[i].charAt(j);
for(int k=0;k<word[i].length();k++)
{
if(c==word[i].charAt(k))
count++;
}
if(count==1)
{
output+=Character.toLowerCase(c);
}
}
output+=" ";
}
System.out.println(output);
}
}

*********************************************************************************************
*********************************************************************************************
*
27. BOX SIZE

INPUT : Enter the box size


6
Enter the numbers
5
55
3
59
42
8
OUTPUT: 32 is even its a valid box

import java.util.Scanner;
public class minmax {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the box size");
int a=sc.nextInt();
if(a<=0)
{
System.out.println(a+" is an invalid box size");
return;
}
int b[]=new int[a];
int c=0,sum=0,temp=0;
System.out.println("Enter the numbers");
for(int i=0;i<a;i++)
{
b[i]=sc.nextInt();
if(b[i]<=0)
{
System.out.println(b[i]+" is an invalid input");
return;
}
}
for(int i=0;i<a;i++)
{
c=b[i]%10;
sum+=c;
c=0;
}
if(sum%2==0)
{
System.out.println(sum+" is even its a valid box");
return;
}
else
{
System.out.println(sum+" is odd its an invalid box");
return;
}

}
}
****ALTERNATE METHOD***********

Box consists of n numbers and n>0


Enter the numbers and numbers should be greater than 0 and add all the last digits of the numbers.If the sum is
even print valid box else invalid box

Input:
Enter size:5
Enter numbers:
2
34
456
67
123

22 is even it's a valid box

Explanation:
22=(2+4+6+7+3)
Similarly for invalid box also

public class BoxGame {

public static void main(String[] args) {


Scanner sc = new Scanner(System.in);
System.out.println("Enter the box size");
int size = sc.nextInt();
int n=0;
int sum=0;
if(size<=0) {
System.out.println(size+" is an invalid box size");
return;
} else {
System.out.println("Enter the numbers");
int [] arr = new int [size];
for(int i=0;i<size;i++) {
arr[i] = sc.nextInt();
}
for(int i=0;i<size;i++) {
if(arr[i]<=0) {
System.out.println(arr[i]+" is an invalid input");
return;
}
}
for(int i=0;i<size;i++) {
n = arr[i]%10;
sum = sum+n;
}
if(sum%2==0) {
System.out.println(sum+" is even its a valid box");
}else {
System.out.println(sum+" is odd its an invalid box");
}
}

}
********************************************************************************************
****************************************************
28. ORDER IDENTIFICATION:(check where elements are in ascending

order) INPUT : Enter the array size : 5


Enter the elements: 32
44
55
66
77

OUTPUT : 32 44 55 66 77 are in ascending order

import java.util.Arrays;
import java.util.Scanner;

public class orderidentification {


public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the array size");
int a=sc.nextInt();
if(a<2 || a>10)
{
System.out.println(a+" is not a valid array size");
return;
}
int b[]=new int[a];
int count=0;
System.out.println("Enter the elements");
for(int i=0;i<a;i++)
{
b[i]=sc.nextInt();
}
int d[]= Arrays.copyOf(b,b.length);
Arrays.sort(d);

if(Arrays.equals(b,d))
{
count++;
}
if(count>0)
{
for(int i=0;i<b.length;i++)
{
System.out.print(b[i]+" ");

}
System.out.print("are in ascending order");
return;
}
else
{
for(int i=0;i<a;i++)
{
System.out.print(b[i]+" ");
}
System.out.print("are not in ascending order");
return;
}
}
***ALTERNATE METHOD***

public class ascendingDesceding {


public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter array size: ");
int n = sc.nextInt();
int[] arr = new int[n];
int[] temp = new int[n];
if (n < 2 || n > 10) {
System.out.println("Invalid size");
return;
}
for (int i = 0; i < n; i++) {
arr[i] = sc.nextInt();
temp[i]=arr[i]; //store the array elements in temp array for comaparison later
}
Arrays.sort(arr); //sort the original array
int count=0;
for(int i=0;i<n;i++) {
if(arr[i]==temp[i]){ //checking if elements of sorted array is equal to
temp array
count++;
} else {
count=0;
break;
}}
if(count!=0) {
System.out.println("All elements are in ascending order");
} else {
System.out.println("Elements are not in ascending order");
}}}

********************************************************************************************
********************************************************************************************
********************************
29) DATE ,MONTH AND

YEAR INPUT:13081995

OUTPUT: date: 13
month: 08
year: 1998

import java.util.Scanner;
public class minmax {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
String str=sc.nextLine();
int n=str.length();
for(int i=0;i<str.length() ;i++)
{
if(!(str.charAt(i)>='0' && str.charAt(i)<='9'))
{
System.out.println("Invalid input");
return;
}
if(n!=8)
{
System.out.println("Enter valid date");
return;
}
}
String date=str.substring(0,2);
String mon=str.substring(2,4);
String year=str.substring(4,8);

System.out.println("date:"+date);
System.out.println("Month:"+mon);
System.out.print("Year:"+year);

}
}

*********************************************************************************************
*********************************************************************************************
*
30) MEGA MART CUSTOMER IDENTIFICATION(String and SUBSTRING)

import java.util.*;
public class arraysquare{
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the customer id");
String cid = sc.next();
String shop = cid.substring(0,4);
//System.out.println("shop");
if(!shop.equals("Mega")){
System.out.println("Invalid Shop Name");
Runtime.getRuntime().halt(0);
}
String type = cid.substring(4,cid.length()-3);
//System.out.println(type);
if(!type.equals("Silver") && !type.equals("Gold") && !type.equals("Platinum")){
System.out.println("Invalid Customer Type");
Runtime.getRuntime().halt(0);
}
int mid = Integer.parseInt(cid.substring(cid.length()-3,cid.length()));
//System.out.println(mid);
if(mid<=99 || mid>=1000){
System.out.println("Invalid Member id");
Runtime.getRuntime().halt(0);
}
System.out.println("Welcome Mega Mart "+type+" Customer");

}
}

*********************************************************************************************
***********************************
31) MALE AND FEMALE COUNT

INPUT: MmFMff
OUTPUT: 3 MALE
3 FEMALE

import java.util.Scanner;
import java.util.regex.*;
public class minmax {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
String s=sc.nextLine();
int count1=0;
int count2=0;
if(Pattern.matches("[MmFf ]+",s)){
for (int i = 0; i < s.length(); i++) {
if (s.charAt(i) == 'M' || s.charAt(i) == 'm') {
count1++;
} else if (s.charAt(i) == 'F' || s.charAt(i) == 'f') {
count2++;
}
}
System.out.println(count1 + " Male");
System.out.println(count2 + " Female");
}
else
{
System.out.println("Invalid Input");
}
}
}
*********************************************************************************************
*********************************************************************************************
***
32) RAINFALL

INPUT: Enter the length of the roof in meters: 4


Enter the breadth of the roof in meters: 3
Enter the rainfall level: 3

OUTPUT: 360.00 Litres

import java.util.Scanner;
public class minmax {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
System.out.println("Enter the length of the roof in meters");
double l=sc.nextDouble();
if(l<=0)
{
System.out.println("Invalid Length");
return;
}
System.out.println("Enter the breadth of the roof in meters");
double b=sc.nextDouble();
if(b<=0)
{
System.out.println("Invalid breadth");
return;
}
System.out.println("Enter the rainfall level");
double r=sc.nextDouble();
if(r<=0)
{
System.out.println("Invalid rainfall");
return;
}
double h;
h=(l*b) *(r*10);
System.out.println(String.format("%.2f",h)+"Litres");
}
}

*********************************************************************************************
*********
33) NUMEROLOGY NAME CHECKING

import java.util.*;
import java.util.regex.Pattern;

public class arraysquare{


public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the name");
String a=sc.next();
if(!Pattern.matches("[A-Za-z]+",a))
{
System.out.println(a+" is an Invalid name");
return;
}
int sum=0;
char b[]=a.toCharArray();
for(int i=0;i<b.length;i++)
{
if(b[i]=='A'||b[i]=='a')
{
sum+=1;
}
else if(b[i]=='B'||b[i]=='b')
{
sum+=2;
}
else if(b[i]=='C'||b[i]=='c')
{
sum+=3;
}
else if(b[i]=='D'||b[i]=='d')
{
sum+=4;
}
else if(b[i]=='E'||b[i]=='e')
{
sum+=5;
}
else if(b[i]=='F'||b[i]=='f')
{
sum+=6;
}
else if(b[i]=='G'||b[i]=='g')
{
sum+=7;
}
else if(b[i]=='H'||b[i]=='h')
{
sum+=8;
}
else if(b[i]=='I'||b[i]=='i')
{
sum+=9;
}
else if(b[i]=='J'||b[i]=='j')
{
sum+=10;
}
else if(b[i]=='K'||b[i]=='k')
{
sum+=11;
}
else if(b[i]=='L'||b[i]=='l')
{
sum+=12;
}
else if(b[i]=='M'||b[i]=='m')
{
sum+=13;
}
if(b[i]=='N'||b[i]=='n')
{
sum+=14;
}
if(b[i]=='O'||b[i]=='o')
{
sum+=15;
}
if(b[i]=='P'||b[i]=='p')
{
sum+=16;
}
if(b[i]=='Q'||b[i]=='q')
{
sum+=17;
}
if(b[i]=='R'||b[i]=='r')
{
sum+=18;
}
if(b[i]=='S'||b[i]=='s')
{
sum+=19;
}
if(b[i]=='T'||b[i]=='t')
{
sum+=20;
}
if(b[i]=='U'||b[i]=='u')
{
sum+=21;
}
if(b[i]=='V'||b[i]=='v')
{
sum+=22;
}
if(b[i]=='W'||b[i]=='w')
{
sum+=23;
}
if(b[i]=='X'||b[i]=='x')
{
sum+=24;
}
if(b[i]=='Y'||b[i]=='y')
{
sum+=25;
}
if(b[i]=='Z'||b[i]=='z')
{
sum+=26;
}
}
System.out.println(sum);
if(sum%3==0 && sum%2==0)
{
System.out.println(a+" is a numerology name");
}
else
{
System.out.println(a+" is not a numerology name");
}
}
}

*******************************************************************************

34)OMR

import java.util.Scanner;
public class arraysquare{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int i;
System.out.println("Enter the No of questions");
int a=sc.nextInt();
if(a<0)
{
System.out.println("Invalid Number");
return;
}
int count=0;
int mark=0;
char b[]=new char[a];
System.out.println("Enter the answer key");
for (i=0;i<a;i++) {
b[i] = sc.next().charAt(0);

if ((b[i] >= 'a' && b[i] <= 'e')||(b[i] > 'E')) {


System.out.println("Invalid Answers");
return;
}
}
char c[]=new char[a];
System.out.println("Enter the student answers");
for (i=0;i<a;i++)
{
c[i]=sc.next().charAt(0);
if ((c[i] >= 'a' && c[i] <= 'e')||(b[i]>'E')) {
System.out.println("Invalid Answers");
return;
}
}

for(i=0;i<a;i++)
{
if(b[i]==c[i])
{
count++;
}
}
if(count>0)
System.out.println("Correct answers are "+count);
mark=(count*100)/a;
if(count<1)
System.out.println("All answers are wrong");
System.out.println("Mark is "+mark);

}
}

****ALTERNATE METHOD****

import java.util.*;
public class OMREvaluation {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the No of questions");
int no = sc.nextInt();
if (no <= 0) {
System.out.println("Invalid Number");
return;
} else {
char anskey[] = new char[no];
System.out.println("Enter the answer key");
for (int i = 0; i < no; i++) {
char x = sc.next().charAt(0);
if (x >= 'A' && x <= 'E')
anskey[i] = x;
else {
System.out.println("Invalid Answers");
return;
}
}
char studanskey[] = new char[no];
System.out.println("Enter the student answers");
for (int i = 0; i < no; i++) {
char y = sc.next().charAt(0);
if (y >= 'A' && y <= 'E')
studanskey[i] = y;
else {
System.out.println("Invalid Answers");
return;
}
}
int count = 0;
for (int i = 0; i < no; i++) {
if (anskey[i] == studanskey[i])
count++;
}
if (count == 0)
System.out.println("All answers are wrong \nMark is 0");
else {
System.out.println("Correct answers are " + count);
System.out.println("Mark is " + ((count * 100) / no));
}
}
}
}

**********************************************************************************************
***************************************************

35)MULTIPLY WITH POSITION

INPUT:
Enter the array size
5

Enter the elements


12
3
7
9
4

Sample Output:
12
6
21
36
20

Logic:
12*1=12
3*2=6
7*3=21
9*4=36
4*5=20

import java.util.*;
public class Main
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the array size:");
int n=sc.nextInt();
int res=0;
if(n<1 || n>10)
{
System.out.println("Invalid Array Size");
return;
}
int a[]=new int[n];
for(int i=0;i<n;i++)
{
a[i]=sc.nextInt();
}

for(int i=0;i<n;i++)
{
res=a[i]*(i+1);
System.out.println(res);
}

}
}

**********************************************************************************************
******************************************************************
36) CAR PARKING

Sample Input:
Enter the car number
ap 37 1498

Sample Output
Park the car in 3rd floor

import java.util.*;

public class CarPrking {


public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the car number");
String num = sc.nextLine();
if (num.length() != 10) {
System.out.println("Invlid State Code");
return;
}
String floor;
String code = num.substring(0, 2);
if (code.equals("TN")) {
floor = "ground";
} else if (code.equals("KA")) {
floor = "1st";
} else if (code.equals("KL")) {
floor = "2st";
} else if (code.equals("AP")) {
floor = "3st";
} else {
System.out.println("Invlid State Code");
return;
}
System.out.println("Park the car in " + floor + " floor");
}
}

ALTERNATE METHOD:

37) DIGIT COUNT

Sample Input:

Enter the number


56164

Enter the digit


6

Sample output
6 appears in 56164 is 2

Explanation:
Digit 6 appears 2 times in the number 56164

package accenture;
import java.util.*;

public class digitcount {

public static void main(String[] args) {


Scanner sc=new Scanner(System.in);
int count=0;
System.out.println("Enter the number:");
int n=sc.nextInt();
String str=String.valueOf(n);
if(n>0)
{
System.out.println("Enter the digit:");
char d=sc.next().charAt(0);
char ch[]=str.toCharArray();
for(int i=0;i<ch.length;i++)
{

if(ch[i]==d)
{
count++;
}
}
if(count>1)
{
System.out.println(d+" appears "+n+" is "+count);
}
}

38) WORD FINDING (repeated words)

Sample input:
Enter the number of words
5
Enter the words in set1:
good
bad
hello
Nothing
North

Enter the words in set2:


Bad
world
word
north
hello

package practice;
import java.util.*;
public class RepeatedWords {

public static void main(String[] args) {


// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
System.out.println("Enter the number of words");
int n = sc.nextInt();
if(n<=0){
System.out.println(n+" is less than the desired limit");
return;
}

String set1[] = new String[n];


String set2[] = new String[n];
System.out.println("Enter the words in set1:");
for(int i = 0;i<n;i++){
set1[i] = sc.next().toLowerCase();
}
System.out.println("Enter the words in set2:");
for(int i = 0;i<n;i++){
set2[i] = sc.next().toLowerCase();
}
String res[] = new String[n];
int k = 0;
for(int i = 0;i<n;i++){
int flag = 0;
for(int j = 0;j<n;j++){
if(set1[i].equals(set2[j])){
flag = 1;
break;
}
}
if(flag != 1){
res[k++] = set1[i];
}
}
/*for(int i = 0;i<n;i++){
if(set1[i] == set2[i]){
continue;
}
else{
res[k++] = set1[i];
}
}*/
System.out.println("The uncommon words are:");
for(int i = 0;i<k;i++){
System.out.println(res[i]);
}

}
**********************************************************************************************
******************************************************
39) SUM OF INTEGERS AT EVEN OR ODD PLACES

Enter size: 5
Enter numbers:
123(1+3=4)
2536(5+6=11)
2(2)
57(7)
76542(7+5+2=14)

Output:
38(4+11+2+7+14)

import java.util.*;
public class oddevenindex {
public static void main(String[] args)
{
Scanner sc = new Scanner (System.in);
System.out.println("Enter the size of the array: ");
int n = Integer.parseInt(sc.nextLine());
String[] arr = new String[n];
int[] fin = new int[n];
System.out.println("Enter the elements of the array: ");
for(int i=0;i<n;i++)
{
arr[i] = sc.nextLine();
}
int sum = 0;
int total =0;
if(n%2!=0)
{
for(int i=0;i<arr.length;i++) {
String num = arr[i];
char[] digi = num.toCharArray();
sum = 0;
if (digi.length % 2 == 0) {
for (int j = 1; j < digi.length; j += 2) {
char x = digi[j];
sum = sum + Integer.parseInt(String.valueOf(x));
}
fin[i] = sum;
}
else
{
for (int j = 0; j < digi.length; j += 2) {
char x = digi[j];
sum = sum + Integer.parseInt(String.valueOf(x));
}
fin[i] = sum;

}
}
for(int x: fin)
total +=x;
}
else{
for(int i=0;i<arr.length;i++) {
String num = arr[i];
char[] digi = num.toCharArray();
sum = 0;
if (digi.length % 2 == 0) {
for (int j = 1; j < digi.length; j += 2) {
char x = digi[j];
sum = sum + Integer.parseInt(String.valueOf(x));
}
fin[i] = sum;
}
else
{
for (int j = 0; j < digi.length; j += 2) {
char x = digi[j];
sum = sum + Integer.parseInt(String.valueOf(x));
}
fin[i] = sum;

}
}
for(int x: fin)
total +=x;
}

System.out.println("Output: "+total);

}
}

*****ALTERNATE METHOD*****

package practice;
import java.util.*;
public class SumOfEvenOrOdd {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
System.out.println("Enter the size");
int n = sc.nextInt();
if(n<=0){
System.out.println("Invalid size");
return;
}
System.out.println("Enter the elements:");
int sum = 0;
String str[] = new String[n];
for(int i=0;i<n;i++){
str[i] = sc.next();
}
for(int i = 0;i<n;i++){
String s = str[i];
if(s.length()%2 == 0){
for(int j = 1;j<s.length();j+=2){
sum+=Integer.parseInt(s.substring(j,j+1));
}
}else{
for(int j = 0;j<s.length();j+=2){
sum+=Integer.parseInt(s.substring(j,j+1));
}
}
}
System.out.println(sum);
}

}
**********************************************************************************************
**********************************************************************
40) SUM OF EVEN ELEMENTS

Here, size of the array should be taken as input, and it should be between 1 and 10 (inclusive)
If it is not in 1 and 10, print it as "invalid"
Now, by the comparing the values at the same indices of both the arrays, if both values are even, then print the sum
of the two values, otherwise print "0".
Before performing operation, make sure if no even element is present in both the arrays, then print it as "There are no
even elements in both the arrays", otherwise perform the above operation.

For example, see the following inputs and outputs:

1. Sample input:
Enter the size of array: 3
Enter the elements in first array:
2
3
4
Enter the elements in second array:
1
5
8
Sample output:
0
0
12

2. Enter the size of array: 3


Enter the elements in first array:
5
3
1
Enter the elements in second array:
1
5
9
Sample output:
There are no even elements in both the arrays

3.Sample input:
Enter the size of array: 1
Enter the elements in first array:
5
Enter the elements in second array:
1
Sample output:
There are no even elements in both the arrays

package practice;
import java.util.*;
public class SumOfEvenElements {

public static void main(String[] args) {


// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
System.out.println("Enter the size of the array:");
int n = sc.nextInt();
if(n<=0 || n>10){
System.out.println("Invalid");
return;
}
System.out.println("Enter the elements in the first array:");
int arr1[] = new int[n];
for(int i = 0;i<n;i++)
arr1[i] = sc.nextInt();
System.out.println("Enter the elements in the second array:");
int arr2[] = new int[n];
for(int i = 0;i<n;i++)
arr2[i] = sc.nextInt();
int count = 0;
for(int i = 0;i<n;i++){
if(arr1[i]%2 !=0 && arr2[i]%2 != 0){
count++;
}
}
if(count == n){
System.out.println("There are no even elements in both arrays:");
return;
}else{
for(int i = 0;i<n;i++){
if(arr1[i]%2 == 0 && arr2[i]%2 == 0){
System.out.println(arr1[i]+arr2[i]);
}else{
System.out.println("0");
}
}
}
}
}
**********************************************************************************************
*********************************************************************
41) COUNT OF OCCURRENCES OF SUBSTRING IN A STRING

Sample input:
Enter the string
Entertainment

Enter substring
en

Sample output: 2

package accenture;
import java.util.*;
import java.util.regex.*;
public class countofoccurencesofsubstringinastring {

public static void main(String[] args) {


Scanner sc=new Scanner(System.in);
int count=0;
System.out.println("Enter the string:");
String str=sc.next();
if(Pattern.matches("[a-z]+", str))
{
System.out.println("Enter pattern:");
String pat=sc.next();
if(Pattern.matches("[a-z]+", pat))
{
Pattern p=Pattern.compile(pat);
Matcher m=p.matcher(str);
while(m.find())
{
count++;
}
System.out.println("Count is: "+count);
}
else
{
System.out.println("Invalid Pattern");
}
}
else
{
System.out.println("Invalid String");
}

}
**********************************************************************************************
******************************************************************
42) LARGEST SORTED SUBSTRING FROM INPUT STRING

Find longest sorted substring from input string..


Input : abczgdpqrstubg
Output: pqrstu
*/
import java.util.*;
public class Main
{
public static void main (String[] args)
{
Scanner sc=new Scanner(System.in);
String s=sc.next();
int firstindex=0,lastindex=0,length=0;
for(int i=0;i<s.length();i++)
{
int asci=s.charAt(i);
int count=1;
for(int j=i+1;j<s.length();j++)
{
if(s.charAt(j)==++asci)
{
count++;
continue;
}
else
{
if(count>length)
{
firstindex=i;
lastindex=j;
length=count;
break;
}
}
}
}
System.out.println(s.substring(firstindex,lastindex));
}
}
**********************************************************************************************
********************************************************************
43) NON-UNIQUE ELIMINATION

package com.company;
import java.util.Scanner;

public class NonUniqueElimination {


public static void main(String[] args){
Scanner sc=new Scanner(System.in);
String name=sc.nextLine(),abc="";
int count=0;
for(int i=0;i<name.length();i++)
{
for(int j=1;j<name.length()-1;j++)
{
if(name.charAt(i)==name.charAt(j))
{
name=name.replace(String.valueOf(name.charAt(j)),"");
count+=1;
}
}
}
if(count==0) {
System.out.println("All are unique character");
return;
}
else {
System.out.println(name);
}
}
**********************************************************************************************
**********************************************************************************************
**

44) THEATER SEAT DETAILS

Sample input 1:
A2S3D06D13

Sample output 2:
Seat Number
D13
D14
D15
D16
D17

Sample input 2:
A2S3D02C01

Sample Output2:
Seat Number
C1
C2

import java.util.*;
import java.util.regex.Pattern;
public class Main{
public static void main(String args[]){
Scanner sc = new Scanner(System.in);

String str = sc.next();


if(str.length()!=10){
System.out.println("Invalid Input");
return;
}

if(Pattern.matches("[0-9]+",str.substring(5,7)) && Integer.parseInt(str.substring(5,7))>=1


&& Integer.parseInt(str.substring(5,7))<=10){
int seatnumber = Integer.parseInt(str.substring(5,7));
String eightletter = str.substring(7,8);
if(Pattern.matches("[A-Za-z]",eightletter) && Pattern.matches("[0-9]+",str.substring(8,10))){
int n = Integer.parseInt(str.substring(8,10));
for(int i=0;i<seatnumber;i++){
System.out.println(eightletter + (n++));
}
}
else{
System.out.println("Invalid Seat Number");
return;
}
}
else{
System.out.println("Invalid Count");
return;
}
}
}
**********************************************************************************************
***************************************************************************

45) CALCULATE OFFER PRICE (DISCOUNT PRICE)

import java.util.Scanner;

public class DiscountPrice {


public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
String code=sc.nextLine();
int len=code.length();
if(len<6 || len>8)
{
System.out.println("Invalid Input");
return;
}
String mrps=code.substring(4);
int mrp=Integer.parseInt(mrps);
System.out.println("MRP Price :"+mrp);
if(mrp>=1 && mrp<=10)
{
System.out.println("Offer Price: Rs"+mrp);
}
else if(mrp>=11 && mrp<=50)
{
System.out.println("Offer Price: Rs"+(mrp-5));
}
else if(mrp>=51 && mrp<=500)
{
System.out.println("Offer Price: Rs"+(mrp-15));
}
else if(mrp>= 501 && mrp<=5000)
{
System.out.println("Offer Price: Rs"+(mrp-105));
}
else if(mrp>=5001 && mrp<=9999)
{
System.out.println("Offer Price: Rs"+(mrp-1005));
}
}
}
**********************************************************************************************
*******************************************************************************

46) THREE’S

Sample input:
Enter the string
Long live

import java.util.*;
import java.lang.*;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("Enter the String");
String str =in.nextLine();
for(int i=0;i<str.length();i++)
{
if((Character.isLetter(str.charAt(i)) || Character.isWhitespace(str.charAt(i))))
continue;
else{
System.out.println(str+" is not a valid string");
return;
}
}
int sum=0;
for(int i=0;i<str.length();i++){
if((i+1)%3==0){
sum+=(int)str.charAt(i);
}
}
System.out.println("Sum is "+sum);
}
}
**********************************************************************************************
**********************************************************************************
47) EVEN POSITION CAPS (CAPITAL LETTERS)

import java.util.Scanner;
import java.util.regex.Pattern;

public class EvenPositionCaps {


public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Input string");
String s = sc.nextLine();
if (!Pattern.matches("[A-Za-z]+", s)) {
System.out.println(s + " is an invalid input");
return;
} else {
if (s.length() < 5 || s.length() > 20) {
System.out.println(s + " is an invalid length");
return;
}
String output = s.charAt(0) + "";
for (int i = 0; i < s.length() - 1; i++) {
if ((i) % 2 == 0)
output += Character.toString(s.charAt(i + 1)).toUpperCase();
else
output += s.charAt(i + 1);
}
System.out.println(output);
}
}
}

***ALTERNATE METHOD***

import java.util.*;
import java.util.regex.Pattern;
public class Main{
public static void main(String args[]){
Scanner sc = new Scanner(System.in);

System.out.println("Input string");
String str = sc.next();
if(Pattern.matches("[A-Za-z]+",str)){

if(str.length()<5 || str.length()>20){
System.out.println(str+" is an invalid length");
return;
}
String output = str.charAt(0)+"";
for(int i=0;i<str.length()-1;i++){
if(i%2==0){
output = output+ Character.toString(str.charAt(i+1)).toUpperCase();
}
else
output = output + str.charAt(i+1);
}
System.out.println(output);
}
else{
System.out.println(str+" is an invalid input");
return;
}
}
}
**********************************************************************************************
****************************************************************************************

48) FUN COUNT

public class FunCount {


public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number of toys:");
int n=sc.nextInt();
if(n<=0)
{
System.out.println("Invalid Input");
}
else if(n>15)
{
System.out.println("Number exceeds the limit");
}
else{
String[] a=new String[n];
System.out.println("Enter the toy list");
for(int i=0;i<n;i++)
{
a[i]=sc.next().toLowerCase();
}
Arrays.sort(a);
int count=0;
for(int i=0;i<n;i++)
{
count=1;
for(int j=i+1;j<n;j++)
{
if(a[i].equalsIgnoreCase(a[j]))
{
count++;
a[j]="0";
}
}
if((a[i])!="0")
{
System.out.println(a[i]+"="+count);
}

}
}
}
}
**********************************************************************************************
*******************************************************************************

49) SPEED ESTIMATION

import java.util.*;
public class Main{
public static void main(String args[]){
Scanner sc = new Scanner(System.in);

System.out.println("Enter the distance in kilometre");


int km = sc.nextInt();

if(km<=0){
System.out.println("Invalid Input");
return;
}

System.out.println("Enter the time to reach in hours");


int time = sc.nextInt();
if(time<=0){
System.out.println("Invalid Input");
return;
}

int sp = km/time;
if(sp>30){
int in_sp = sp-30;
System.out.println("You want to increase a speed "+in_sp+" km/hr from a normal speed");
}
else{
System.out.println("You drive a car at a normal speed");
}
}
}
***********************************************************************************************
*********************************************************************************
50) SUM OF SQUARES (RE-TEST)

Sample input
Enter the number of values
4
Enter the values
2
7
9
8

Sample output
130

Explanation
Odd numbers are 7,9 = 7*7 +9*9 = 49+81=130
import java.util.*;
public class Main
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number of values");
int n=sc.nextInt();
if(n<=0)
{
System.out.println(n+" is an invalid size");
return;
}
int a[]=new int[n];
int count=0;
int sum=0;
System.out.println("Enter the values");
for(int i=0;i<n;i++)
{
a[i]=sc.nextInt();
if(a[i]%2!=0)
count=count+1;
}
if(count<=0)
{
System.out.println("These "+n+" values are not a odd digit");
return;
}
else
{
for(int i=0;i<n;i++)
{
if(a[i]%2!=0)
{
sum=sum+a[i]*a[i];
}
}
System.out.println(sum);
}

}
}

JAVA END
*********************************************************************************************
*********************************************************************************************
********

RDBMS IMPORTANT CODES(NOT TESTED)


6. Max Min product
import java.util.Scanner;
class Main
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the array size");
int n=sc.nextInt();
if(n>=3 && n<=20)
{
int a[]=new int[n];
System.out.println("Enter the array elements");
for(int i=0;i<n;i++)
{
a[i]=sc.nextInt();
}
int min=a[0];
int max=a[0];
for(int i=1;i<n;i++)
{
if(min>a[i])
min=a[i];
else if(max<a[i])
max=a[i];
}
System.out.println(min*max);
}
else
{
if(n<3)
System.out.println(n+" is too small");
else
System.out.println(n+" exceeds limit");
}
}
}
Block Score
import java.util.*;
class Main
{
public static void main (String[] args) {
int sum=0,p=0;
Scanner sc=new Scanner(System.in);
System.out.println("Enter the String");
String s=sc.nextLine().toLowerCase();
String s1="";
for(int i=0;i<s.length();i++)
{
if(Character.isDigit(s.charAt(i)) || s.charAt(i)==' ' ||
Character.isLetter(s.charAt(i)))
{
continue;
}
else
{
System.out.println(s+" is not a valid a String");
return;
}
}
System.out.println("Enter the Letter");
char ch=sc.next().charAt(0);
ch=Character.toLowerCase(ch);
for(int i=0;i<s.length();i++)
{
if(ch==s.charAt(i))
{
sum=sum+i;
}
else
{
p=p+i;
}
}
System.out.println("Score is "+sum*p);

}
}
2

Gender Determination :

import java.util.*;
public class Main {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
String s=sc.next();
int count=0,count1=0;
if(!(s.matches("[mfMF]+")))
{
System.out.println("Invalid Input");
return;
}
else
for(int i=0;i<s.length();i++)
{
if(s.charAt(i)=='m' ||s.charAt(i)=='M')
count++;
else
count1++;
}
System.out.println(count+" "+"Male");
System.out.println(count1+" "+"Female");
}}
LCM OF DAY INTERVAL/LUNCH/DINNER TOGETHER :

import java.util.*;
public class Main {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
System.out.println("Enter the day interval of person 1:");
int a=sc.nextInt();
System.out.println("Enter the day interval of person 2:");
int b=sc.nextInt();
if(a<=0 || b<=0)
{
System.out.println("Given interval is not valid");
return;
7

SPEED ESTIMATION :
import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
System.out.println("Enter the distance in kilometer");
int km=sc.nextInt();
if(km<0) {
System.out.println("Invalid Input");
return;
}
System.out.println("Enter the time to reach in hours");
int hours=sc.nextInt();
if(hours<0){
System.out.println("Invalid Input");
return;
}
int speed=km/hours;
if(speed<30){
System.out.println("You drive a car at normal speed");
return;
}
int inc=speed-30;
System.out.println("You want to increase a speed "+inc+"
km/hr from a normal speed");
}}

Prime Number

import java.util.Scanner;

public class Main{

public static void main(String[] args){

Scanner sc=new Scanner(System.in);

int a = sc.nextInt();

int b = sc.nextInt();

int count=0;
8

if(a<0 || b<0){

System.out.println("Negative integers cannot be prime");

return;

for(int i=a;i<=b;i++){

count = 0;

for(int j=2;j<=i;j++){

if(i % j == 0)

count = count+1;

if(count == 1)

System.out.print(i+" ");

if(count!=1)

System.out.println("There are no prime numbers in the range


"+a+" to "+b);

Theatre

import java.util.*;
public class Main {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
String s=sc.next();
if(s.length()==6)
{
10

Customer details

import java.util.Scanner;

public class Main{


public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number of customers:");
int cust=sc.nextInt();
if(cust<0)
{
System.out.println("Invalid Input");
return;
}
if(cust<3)
{
System.out.println("Customer count is too low");
return;
}
if(cust>50)
{
System.out.println("Customer count is too high");
return;
}
System.out.println("Enter the customer details:");
String[] arr=new String[cust];
for (int i=0;i<cust;i++)
{
arr[i]=sc.next();
}
System.out.println("Enter the plan to be searched");
String plan=sc.next();
for (int i=0;i<cust;i++)
{
String[] custdetails=arr[i].split(":");
if(plan.equals(custdetails[1]))
{
System.out.println(custdetails[2]+" "+custdetails[3]);
11

}
}
}
}

Team Win/Loose
import java.util.*;
public class Main {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
String str=sc.next();
int count=0;
if(str.length()<3) {
System.out.println("Invalid input");
return;
}
if(str.matches("[htHT]+")) {
String s=str.toLowerCase();
for(int i=0;i<s.length()-2;i++){
if(s.charAt(i)!=s.charAt(i+1) &&
s.charAt(i)==s.charAt(i+2))
count++;
}
if(count==s.length()-2)
System.out.println("Team will win");
else
System.out.println("Team may loose");
}
else {
System.out.println("Invalid Input");
return;
}
}}

Holiday Fun

import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
12

int sum=0,sum1=0;
int n=sc.nextInt();
if(n>0){
String[] a=new String[n];
for(int i=0;i<n;i++){
a[i]=sc.next();
}
for(int i=0;i<n;i++){
int len=a[i].length();
if(len%2==0)
{
for(int j=1;j<len;j++){

sum=sum+Integer.parseInt(String.valueOf(a[i].charAt(j)));
j++;
}}
else
{
for(int k=0;k<len;k++){

sum1=sum1+Integer.parseInt(String.valueOf(a[i].charAt(k)));
k++;
}}
}
System.out.println(sum+sum1);
}
else
System.out.println("Invalid size");
}}

Reverse Prime

import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
int count=0,c=0,f=0,r=0,prime=0;
int n=sc.nextInt();
if(n>0) {
int[] a=new int[n];
13

for(int i=0;i<n;i++) {
int num=sc.nextInt();
if(num>9)
a[i]=num;
else {
System.out.println("Provided "+num+" is not valid");
return;
}}
for(int i=0;i<n;i++) {
count=0;
for(int j=2;j<a[i];j++)
{
if(a[i]%j==0)
count++;
}
if(count==0) {
prime++;
f=a[i];
r=0;
while(a[i]!=0) {
r=r*10;
r=r+a[i]%10;
a[i] =a[i]/10;
}
for(int k=2;k<r;k++) {
if(r%k==0)
c++;
}
if(c==0)
System.out.println(f);
}}}
else {
System.out.println(n+" is less than a limit");
return;
}
if(prime==0)
System.out.println(n+" values are not prime numbers");
}}
14

Even number addition in arrays

import java.util.*;
public class Main {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
int count=0;
System.out.println("Enter the size of array ");
int n=sc.nextInt();
int[] sum=new int[n];
if(n>=1 && n<=10)
{
int[] a=new int[n];
System.out.println("Enter the elements of the first array ");
for(int i=0;i<n;i++)
a[i]=sc.nextInt();
int[] b=new int[n];
System.out.println("Enter the elements of second array ");
for(int i=0;i<n;i++)
b[i]=sc.nextInt();
for(int i=0;i<n;i++)
{
if(a[i]%2==0 && b[i]%2==0)
{
count++;
sum[i]=a[i]+b[i];
}
else
sum[i]=0;
}
if(count==0)
System.out.println("There are no even elements");
else
for(int result:sum)
System.out.println(result);
}
else
System.out.println("Invalid");
}}
15

Groceries Bill

import java.util.*;
public class Main {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
String s=sc.next();
int a=0,b=0,c=0,d=0,count=0;
if(s.matches("[ORWKorwk]+")) {
for(int i=0;i<s.length();i++) {
for(int j=0;j<s.length();j++) {
if(s.charAt(i)==s.charAt(j))
count++;
}}
if(count==s.length()) {
for(int k=0;k<s.length();k++)
{
if(s.charAt(k)=='O')
a=4*20;
else if(s.charAt(k)=='R')
b=3*5;
else if(s.charAt(k)=='W')
c=2*10;
else
d=5*15;
}
System.out.println(a+b+c+d);
}
else
System.out.println("Duplicates are not allowed");
}
else
System.out.println("Invalid");
}}
16

Cake Order

import java.util.*;

public class CakeProgram {

public static void main(String[] args) {


Scanner sc=new Scanner(System.in);
System.out.println("Enter the Customer instructions: ");
String cd=sc.nextLine();

if (cd.matches("[a-zA-Z0-9]*")) {
String w=cd.substring(0, 4);

if(!w.matches("[0-9]*")){
System.out.println("Invalid weight");
return;
}

float wg=Integer.parseInt(w);
if (wg>999) {
float fwg=wg/1000;
double weight= (Math.round(fwg * 100.0) / 100.0);

String o=cd.substring(cd.length()-3);
if (!o.matches("[0-9]*")) {
System.out.println("Invalid order number");
return;
}
int on=Integer.parseInt(o);
if(on>99) {
String flavour=cd.substring(4,cd.length()-3);

System.out.println("Weight of Cake in Kgs:


"+String.format("%.2f", weight));
System.out.println("Order No: "+on);
System.out.println("Flavour Name: "+flavour);

double cakePrice=450*weight;
17

System.out.printf("Cake Price is: %.2f


Rupees",cakePrice);
}
else {
System.out.println("Invalid order number");
}
}
else {
System.out.println("Invalid weight");
}
}
else {
System.out.println("Invalid Input");
}
}

}
1. Maze Runner
Solution:

import java.util.*;

class Main

public static void main(String args[])

Scanner sc=new Scanner(System.in);

System.out.println("Enter the points of the first player:");

int points1=sc.nextInt();

if(points1<1000 || points1>5000)

System.out.println("Invalid Input");

else

System.out.println("Enter the string:");

String s1=sc.next();

int flag=0;

char ch1[]=s1.toCharArray();

for(char c:ch1)

if(c=='L' || c=='R' || c=='F' ||c=='B')

//System.out.println(c);
flag++;

if(flag!=s1.length())

System.out.println("Invalid Input");

else

System.out.println("Enter the points of the second player:");

int points2=sc.nextInt();

if(points2<1000 || points2>5000)

System.out.println("Invalid Input");

else

System.out.println("Enter the string:");

String s2=sc.next();

if(s1.length()!=s2.length())

System.out.println("Invalid Input");

else

{
int flag1=0;

char ch2[]=s2.toCharArray();

for(char c:ch2)

if(c=='L' ||c=='R' || c=='F' ||c=='B')

flag1++;

if(flag1!=s2.length())

System.out.println("Invalid Input");

else

for(char c:ch1)

if(c=='L')

points1+=50;

if(c=='R')

points1-=50;

}
if(c=='B')

points1*=2;

if(c=='F')

points1/=2;

for(char c:ch2)

if(c=='L')

points2+=50;

if(c=='R')

points2-=50;

if(c=='B')

points2*=2;

if(c=='F')

{
points2/=2;

if(points1>points2)

System.out.println("Player 1 Wins");

else if(points1<points2)

System.out.println("Player 2 Wins");

else

System.out.println("Draw Nobody Wins");

}
2. Holiday Trip:
Solution:

import java.util.*;

public class Main{

public static void main(String[] args){

Scanner sc=new Scanner(System.in);

Scanner sc1=new Scanner(System.in);

System.out.println("Enter the flight name:");

String fname=sc.nextLine();

System.out.println("Enter the class:");

String fclass=sc.nextLine();

System.out.println("Enter the number of seats:");

int no=sc.nextInt();

System.out.println("Card Payment:");

char pay=sc.next().charAt(0);

int cost=0;

switch(fname){

case "Air India":

// System.out.println("Hai1111");

switch(fclass){

case "Travel class":{

//System.out.println("Hai");

cost=3200;

break;
}

case "Economy class":{

cost=6950;

break;

case "Business class":{

cost=10340;

break;

break;

case "Spice Jet":

switch(fclass){

case "Travel class":{

if(no<=5){

cost=3450;

else if(no>5&&no<=10){

cost=(int)(3450*0.9);

else{
cost=(int)(3450*0.85);

break;

case "Economy class":{

if(no<=5){

cost=7945;

else if(no>5&&no<=10){

cost=(int)(7945*0.9);

else{

cost=(int)(7945*0.85);

break;

case "Business class":{

if(no<=5){

cost=9500;

else if(no>5&&no<=10){

cost=(int)(9500*0.9);

else{

cost=(int)(9500*0.85);
}

break;

break;

case "Go Air":

switch(fclass){

case "Travel class":{

cost=3300;

break;

case "Economy class":{

cost=7250;

break;

case "Business class":{

cost=9890;

break;

break;
case "IndiGo":{

switch(fclass){

case "Travel class":{

if(no<=5){

cost=3490;

else if(no>5&&no<=10){

cost=(int)(3490*0.9);

else{

cost=(int)(3490*0.85);

break;

case "Economy class":{

if(no<=5){

cost=7560;

else if(no>5&&no<=10){

cost=(int)(7560*0.9);

else{

cost=(int)(7560*0.85);

}
break;

case "Business class":{

if(no<=5){

cost=9990;

else if(no>5&&no<=10){

cost=(int)(9990*0.9);

else{

cost=(int)(9990*0.85);

break;

break;

int res=cost*no;

if(pay=='Y')

switch(fname){

case "Air India":

res=(int)(res*0.895);
}

break;

case "Spice Jet":

res=(int)(res*0.925);

break;

case "Go Air":

res=(int)(res*0.905);

break;

case "IndiGo":

res=(int)(res*0.915);

break;

System.out.println(res);

}
3. Tell the time
Solution:

import java.util.Scanner;

public class Main

public static void main(String args[])

Scanner sc=new Scanner(System.in);

//System.out.println("Enter the word:");

String s=sc.next();

String ch[]=s.split(":");

int m[]=new int[2];int count=0;

for(int i=0;i<2;i++)

int m1=Integer.valueOf(ch[i]);

m[i]=m1;

if(m[0]>=00 && m[0]<=23 && m[1]>=00 && m[1]<=59)

{ int n=sc.nextInt();

if(n<=59 && n>=0)

int k=m[1]+n;

if(k>59)

{ int l=m[0]+1; m[1]=k-60;


if(l>23)

System.out.println("Notification cannot be sent for the day");

else

{m[0]=l;

count++;}

else

{ m[1]=k;

count++; }

if(count!=0 && m[1]<=9)

System.out.println(m[0]+":0"+m[1]);

if(count!=0 && m[1]>9)

System.out.println(m[0]+":"+m[1]);

else

System.out.println("Input is not valid");

else

System.out.println("Input is not valid");

}
4.Fuel Quantity Calculation

Solution:
import java.util.*;

public class Main

public static void main(String[] args)

Scanner read=new Scanner(System.in);

System.out.println("Enter the amount in Rupees:");

int rs=read.nextInt();

if(rs<1)

System.out.println("Invalid Input");

else

System.out.println("Fuel rate per liter:");

float liter=read.nextFloat();

if(liter<0)

System.out.println("Invalid Input");

else

float petrol=rs/liter;

System.out.printf("%.2f Liters",petrol);

}}
5.Vowel Pair Removal
Solution:

import java.util.Scanner;

public class Main

public static void main(String args[])

Scanner sc=new Scanner(System.in);

System.out.println("Enter the word:");

String s=sc.next();int count=0;

if(s.length()>=3 && s.length()<=8)

for(int i=0;i<s.length();i++)

if(Character.isLetter(s.charAt(i)))

count++;

if(count==s.length())

for(int i=0;i<s.length();i++)

{ if(i<s.length())

if(((s.charAt(i)=='a')||(s.charAt(i)=='e')||(s.charAt(i)=='i')||(s.charAt(i)=='o')||(s.charAt(i)=='u'))&&

((s.charAt(i+1)=='a')||(s.charAt(i+1)=='e')||(s.charAt(i+1)=='i')||(s.charAt(i+1)=='o')||(s.charAt(i+1)=='u'))
)
{i++;

continue;

else

System.out.print(s.charAt(i));

else

System.out.print(s.charAt(i));

//System.out.println(s);

else

System.out.println("Invalid Input");

if(s.length()>8)

System.out.println("Word length exceeds the limit");

if(s.length()<3)

System.out.println("Word length is too short");

6. MAC Validation
Solution:

import java.lang.*;

import java.util.*;
public class Main{

public static void main(String[] args){

Scanner sc=new Scanner(System.in);

String s=sc.nextLine();

int len=s.length();

int dc=0,cc=0,colonc=0,flag=0;

if(len==17){

char[] a=s.toCharArray();

for(char b:a){

if(Character.isLetter(b)){

if(b>=65&&b<=70)

cc++;

if(Character.isDigit(b)){

dc++;

if(b==':'){

colonc++;

if(!(Character.isLetter(b)||Character.isDigit(b)||b==':')){
flag++;

break;

if(flag==1){

System.out.println("Invalid Input");

// System.exit(0);

if(flag==0){

int res=cc+dc+colonc;

if(res==17){

System.out.println("Valid MAC address");

else{

System.out.println("Invalid MAC address");

}
else if(len<17){

System.out.println("String is too short");

else{

System.out.println("String is too long");

7. Unique products
Solution:

import java.util.Scanner;

public class Main {

public static void main(String[] args)

Scanner sc=new Scanner(System.in);

System.out.println("Enter the number of items:");

int item_count=sc.nextInt();

if(item_count<5 || item_count>20)

{
System.out.println("Invalid item count");

else

int item[]=new int[item_count];

int flag=1;

System.out.println("Enter the bar code ID for "+item_count+" items:");

int count=0;

for(int i=0;i<item_count;i++)

int it=sc.nextInt();

if(it<100 || it>999)

System.out.println("Invalid bar code ID");

flag=0;

break;

else

item[i]=it;

if(flag!=0)

for(int j:item)
{

String s="";

s=s.valueOf(j);

if(s.charAt(0)!=s.charAt(1)&&s.charAt(0)!=s.charAt(2)&&s.charAt(2)!=s.charAt(1))

System.out.println(j);

count++;

if(count==0)

System.out.println("There are no item with Unique number in the bar


code ID");

else

System.out.println("There are "+count+" items with Unique number in


the bar code ID");

}
}

8.Toggle word
Solution:

import java.util.*;

class Main

public static void main(String args[])

Scanner sc=new Scanner(System.in);

System.out.println("Enter the word:");

String s=sc.next();

int length=s.length();

if(length<3)

System.out.println("Word length is too short");

else if(length>8)

System.out.println("Word length exceeds the limit");

}
else

char c[]=s.toCharArray();

int flag=0;

for(char c1:c)

if(Character.isLetter(c1))

flag++;

if(flag!=length)

System.out.println("Invalid Input");

else

int i=0;

for(char c1:c)

if(i%2==0)

System.out.print(Character.toUpperCase(c1));

i++;

}
else

System.out.print(c1);

i++;

9.Prime Number Multiples


Solution:

import java.util.*;

class Main

public static void main(String args[])

Scanner sc=new Scanner(System.in);

int num=sc.nextInt();

int product=1;

if(num<0 || num>32767)

System.out.println("Invalid Input");

}
else

while(num>0)

int a=num%10;

if(a==2 || a==3 ||a==5 || a==7)

product*=a;

num=num/10;

if(product==1)

System.out.println("No Prime Digit Found");

else

System.out.println(product);

10.Estimated Parcel Delivery Time


Solution:

import java.util.*;
public class Main

public static void main(String[] args)

Scanner read=new Scanner(System.in);

System.out.println("Enter the distance in Km:");

int distance=read.nextInt();

if(distance<1)

System.out.println("Invalid Input");

else

float dism=distance*1000;

float div=dism/10;

float time=div/60;

System.out.println("Estimated Time:");

System.out.printf("%.2f Minutes",time);

}
Product of case count

you need to count uppercase letters and lower case letters in a given string
Multiply the counts and display
Note: string shouldn't contain any digits, special characters
Length shouldn't be greater than 10
Input:
YouRName
Output:
Product value is 15
Explanation
Uppercase letters=3
Lowercase letters=5
Display 3*5=15

import java.util.*;
public class Program{

public static void main(String[] args){


Scanner sc = new Scanner(System.in);
int countj=0,countk=0,i;
System.out.println("Enter string:");
String str=sc.next();
char str1[]=new char[str.length()];
for( i=0;i<str.length();i++) {
if(str.charAt(i)<=122&&str.charAt(i)>=97) {
countj++;
}
else if(str.charAt(i)<=90&&str.charAt(i)>=65) {
countk++;
}
}
System.out.println(countj+" "+countk);
int product=countj*countk;

System.out.println(product);

}}
Offer to customers
Toll fee for region code
Take input string of numbers. Extract last four numbers from the string. Calculate
the discount price of the product based on those four numbers.

We need to input the product code as a string


The length of that string shd be of 6-8
If not print invalid
And we need to extract last 4 characters from that string, that will be the MRP of
the product
If the MRP is between 0 to 10, then offer is 0₹
If MRP between 11 to 50, offer is 5₹
If MRP between 51 to 500, offer is 15
If MRP between 501 to 5000, offer is 105
If MRP is above 500, offer is 1005

We need to print the MRP as well as the price after the offer is applied

Sample input 1
20220050
Output 1
MRP : ₹50
Offer price : ₹45

Sample input 2
350004
Output 2
MRP: ₹4
Offer price :₹4

Sample input 3:
202200050
Output 3:
Invalid input
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String n = sc.nextLine();
if (5 < n.length() && n.length() < 9) {
String s = n.substring(n.length() - 4);
int price = Integer.parseInt(s);
if (0 < price && price < 10) {
System.out.println("MRP: Rs " + price);
System.out.println("Offer Price: Rs " + price);
} else if (10 < price && price < 51) {
System.out.println("MRP: Rs " + price);
System.out.println("Offer Price: Rs " + (price - 5));
} else if (50 < price && price < 501) {
System.out.println("MRP: Rs " + price);
System.out.println("Offer Price: Rs " + (price - 15));
} else if (500 < price && price < 5001) {
System.out.println("MRP: Rs " + price);
System.out.println("Offer Price: Rs " + (price - 105));
} else if (5000 < price) {
System.out.println("MRP: Rs " + price);
System.out.println("Offer Price: Rs " + (price - 1005));
}
} else {
System.out.println("Invalid Input");
}
}

Reverse and Concatenate

She sells seashells


Same first letter for all words so reverse the last word and concatenate first word
Output: sllehsaesShe

If first letter is not same then reverse first word and concatenate with last word
NEXT MISSING LETTER
import java.util.*;
public class Accenture {
static boolean flag = true;
public static void main(String[] arg) {

Scanner sc=new Scanner(System.in);


System.out.println("Enter the String");
String input = sc.next().toLowerCase();

String str = "abcdefghijklmnopqrstuvwxyz";


str = str + str ;

char[] arr = input.toCharArray();


Arrays.sort(arr);
String msg = "";
for(int i = 0;i<arr.length ; i++)
msg = msg + arr[i];

if ( ! msg.equalsIgnoreCase(input) )
flag = false;

System.out.println("Enter the Sequence time");


int seq = sc.nextInt();

if( seq>0)
{
int diff=0, min=0;
for(int i=1 ; i<input.length() ; i++)
{
if(i==1)
diff = Math.abs((int)input.charAt(i-1) - (int)input.charAt(i));
else
{
min = Math.abs((int)input.charAt(i-1) - (int)input.charAt(i));
if( min != diff)
{
System.out.println(input+" not in correct sequence");
return;
}
}
}

if(flag) // input is in ascending order


{
int index = str.indexOf(input.charAt(input.length() - 1));
for(int i=0 ; i<seq ; i++)
{
System.out.print(str.charAt(index+diff));
index = index+diff;
}
}
else // input is in descending order
{
int index = str.lastIndexOf(input.charAt(input.length() - 1));
for(int i=0 ; i<seq ; i++)
{
System.out.print(str.charAt(index-diff));
index = index-diff;
}
}
}
else
System.out.println(seq+" is invalid");
}
}
Next missing letter... Fix

import java.util.*;
public class JavaApplication55 {

null
public static void main(String[] args) {
// TODO code application logic here
Scanner sc=new Scanner(System.in);
System.out.println("Enter the string");
String str=sc.next();
int diff=str.charAt(0)-str.charAt((1));
System.out.println("Enter the sequnece");
int seq=sc.nextInt();
if(seq {
System.out.println(seq+ "is invalid");
}
for(int i = 0; i {
int val1=str.charAt(i);
int val2=str.charAt(i+1);
if(diff!=(val1-val2))
{
System.out.print(str+" not in order");
return;
}
}
int temp=str.charAt(str.length()-1);
for(int i = 0; i {
temp=temp-diff;

if(temp>122)
{
temp=temp-26;
System.out.print((char)temp);
}
else if(temp {
temp=temp+26;
System.out.print((char)temp);
}
else
{
System.out.print((char)temp);
}

}
}

}
Add with index

import java.util.*;
public class Main
{

public static void main(String[] args)


{
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
int size;
System.out.println("Enter size");
size=sc.nextInt();
if(size {
System.out.println(size+ " is to low");
return;
}
if(size>10)
{
System.out.println(size+ " is to high");
return;
}
int array[]=new int[size];
System.out.println("Enter array:");
for(int i=0;i {
array[i]=sc.nextInt();
}
boolean flag = true;
int first = array[0];
for(int i = 0; i {
if (array[i] != first)
flag = false;
}
if (flag)
{
System.out.println(size+" contains same elements ");
return;
}
int max=array[0],index=0;
for(int i=0;i {
if(max {
max=array[i];
index=i;
}
}
//System.out.println(index);
for(int i=0;i {
array[i]=array[i]+index;
System.out.println(array[i]);
}
}

}
1.Adams
Input:hththt
Output:-Team May Win
package sda;
import java.util.*;
public class Main{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
String str=sc.nextLine();
int len=str.length();
//boolean flag=false;
if(len>=2) {
boolean flag=false;
for(int i=0;i<str.length()-1;i=i+2) {
char ch=str.toLowerCase().charAt(i);
if(ch=='h') {
char ch1=str.toLowerCase().charAt(i+1);
if(ch1=='t') {
flag=true;
}else if(ch1=='h') {
//flag=false;
System.out.println("Team may lose");
return;
}
else {
System.out.println("Invalid string");
return;
}
}

else if(ch=='t') {
char ch1=str.toLowerCase().charAt(i+1);
if(ch1=='h') {
flag=true;
}else if(ch1=='t') {
//flag=false;
System.out.println("Team may lose");
return;
}
else {
System.out.println("Invalid string");
return;
}
}
}
if(flag==true) {
System.out.println("win");
}else {
System.out.println("lose");

}
}

}
}

2.Alternate Number differences


Input:
Array element:4
Element:
4
5
6
7
4-7+5-6
Output:4

package sda;
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int no=sc.nextInt();
int arr[]=new int[no];
int diff=0,sum=0;
for(int i=0;i<no;i++) {
arr[i]=sc.nextInt();
}
for(int i=0;i<no/2;i++) {
diff=arr[i]-arr[no-i-1];
sum+=diff;
}
System.out.println(sum);
}

}
3.Ascending Array:
package sda;
import java.util.*;
public class assendingarray {
public static void main(String args[]) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the Array size:");
int no=sc.nextInt();
int count=0,f=0;
if(no>=2 && no<=10) {
int arr[]=new int[no];
int copy_arr[]=new int[no];
System.out.println("Enter the array element:");
for(int i=0;i<no;i++) {
arr[i]=sc.nextInt();
copy_arr[i]=arr[i];
}for(int i=0;i<no-1;i++) {
if(arr[i]==arr[i+1]) {
f++;
}
}if(f==no) {
System.out.println("Same array");
return;
}
Arrays.sort(copy_arr);
System.out.println(copy_arr);

for(int i=0;i<no;i++) {
if(copy_arr[i]==arr[i]) {
count++;
}
}
System.out.println(count);
if(count==no) {
for(int i=0;i<no;i++) {
System.out.print(arr[i]+" ");
}
System.out.print(" are in ascending order");
}else {
for(int i=0;i<no;i++) {
System.out.print(arr[i]+" ");
}
System.out.print(" are not in ascending order");

}
}else {
System.out.print("Invalid array size");
}

}
4.Bike Rent:
package sda;
import java.util.*;
public class BIkeRent {
public static void main(String args[]) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter your name");
String name=sc.nextLine();
if(name.matches("[a-zA-Z]+")) {
System.out.println("Enter the time duration");
int time=sc.nextInt();
if(time>=1 && time<=24) {
System.out.println("List of the Payment
option;");
System.out.println("1) Visa Card");
System.out.println("2) Rupay card");
System.out.println("3) Master card");
System.out.println("Choose an option\n");
//int op=sc.nextInt();
while(true) {
int op=sc.nextInt();
double bill;
double bill1;
if(op==1) {
if(time>=5) {
bill=(time*120);
bill1=(bill-bill*0.25);
System.out.println("Dear
"+name+" your bill is "+String.format("%.2f",bill1));
}else {
bill=time*120;
System.out.println("Dear
"+name+" your bill is "+String.format("%.2f",bill));
}
}else if(op==2) {
if(time>=5) {
bill=(time*120);
bill1=(bill-bill*0.17);
System.out.println("Dear
"+name+" your bill is "+String.format("%.2f",bill1));
}else {
bill=time*120;
System.out.println("Dear
"+name+" your bill is "+String.format("%.2f",bill));
}
}else if(op==3) {
bill=(time*120);
System.out.println("Dear "+name+" your
bill is "+String.format("%.2f",bill));
}

else {
System.out.println("TRy again");
//break;
//continue;
}
}
}

}
}
}

5.Cake Shop Order


package sda;
import java.util.*;
public class CakeShopOrder {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the customer instrution");
String str=sc.nextLine();
String w=str.substring(0,4);
int weight=0,order_no=0;
String order=str.substring(str.length()-3);
String flavor=str.substring(4,str.length()-3);
if(!(str.matches("[a-zA-z0-9]+"))) {
System.out.println("Invalid Instruction");
return;
}
else if(w.contains("[0-9]+" )) {
weight=Integer.parseInt(w);
System.out.println("Invalid weight");
return;
}
else if(!order.contains("[0-9]+")) {
System.out.println("Invalid Oreder number");
return;

else {
if(weight<999) {
System.out.println("Invalid Weight");
return;
}
double kg=(Double.parseDouble(w))/1000;
System.out.println("Cake weight is "+kg+"kg");
System.out.println("Cake Flavor is "+flavor);
System.out.println("Cake No is "+order);
double price=450*kg;
System.out.println("Price is "+String.format("%.2f",price));
}
}
}

6.Character Addition
package sda;
import java.util.*;
public class CharacterAddition {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number of sentences:");
int no=sc.nextInt();
if(no>0) {
String arr[]=new String[no];
for(int i=0;i<no;i++) {
arr[i]=sc.next();
sc.nextLine();
}
int asci[]=new int[no];
for(int i=0;i<no;i++) {
int sum=0;
for(int j=0;j<arr[i].length();j++) {

if(Character.isAlphabetic(arr[i].charAt(j))) {
sum=arr[i].charAt(j)+sum;
}else {

if(Character.isDigit(arr[i].charAt(j)))
{
continue;
}
}
}asci[i]=sum;
}for(int i=0;i<no;i++) {
System.out.println(asci[i]);
}

}else {
System.out.println("Invalid input");
}

}
7.Product Case Count:

package sda;
import java.util.*;
import java.lang.*;
public class CountUpperLowerChar {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the String:");
String str=sc.nextLine();
if(str.matches("[a-zA-Z]+")) {
int ucount=0,lcount=0;

for(int i=0;i<str.length();i++) {
if(str.charAt(i)>='A' && str.charAt(i)<='Z') {

ucount++;
}
else {
lcount++;
}
}
//System.out.print(ucount+" "+ lcount);
System.out.print("Product value is "+ucount*lcount);

}else {
System.out.println("Invalid String");
}
}

}
8.Non unique char:

package sda;
import java.util.*;
public class DescString {
public static void main(String[] arge) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the string");
String str=sc.nextLine();
StringBuilder sb=new StringBuilder(str);
for(int i=0;i<sb.length()-1;i++) {
for(int j=i+1;j<sb.length();j++) {
if(sb.charAt(i)==sb.charAt(j)) {
sb.deleteCharAt(j);
j--;
}
}

}
char[] c=sb.toString().toCharArray();
Arrays.sort(c);
sb=new StringBuilder(new String(c));
sb.reverse();
System.out.println(sb);

}
9.Divide by three:

package sda;
import java.util.*;
public class DivdeByThree {
public static void main(String args[]) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the String");
String str=sc.nextLine();
if(!str.matches("[]a-zA-Z ]+")) {
System.out.println("Invalid String");
return;

}else {
int sum=0,c=0;
for(int i=0;i<str.length();i++) {
if((i+1)%3==0) {
//System.out.println(c);
sum+=str.charAt(i);
c++;
}
}if(c==0) {
System.out.println("sum is "+sum);
}else {
System.out.println("sum is "+sum);
}
}
}

10.Fastest Runner:
Input:
Shraddha,9.45
Aanushree 9.34
Output:
Aanushree,9.34

package sda;
import java.util.*
public class FastRunner {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number of runners:");
int no=sc.nextInt();
if(no>0 && no<=10) {
System.out.println("Enter the runners:");
String run[]=new String[no];
String name[]=new String[no];
String run_time[]=new String[no];

for(int i=0;i<no;i++) {
run[i]=sc.next();
sc.nextLine();
String time[]=run[i].split(",");
name[i]=time[0];
run_time[i]=time[1];
float time1=Float.parseFloat(time[1]);
if(time1<8.00 || time1>12.00) {
System.out.println(time[1]+" is an invalid
input");
return;
}
}
String min=run_time[0];
int count=0;
float min1=Float.parseFloat(min);
for(int j=0;j<no;j++)
{
float val=Float.parseFloat(run_time[j]);
if(val<=min1)
min1=val;
}
for(int i=0;i<no;i++) {
float val=Float.parseFloat(run_time[i]);
if(val==min1) {
System.out.println(name[i]);
count++;
}
}
if(count==no) {
System.out.println("All the runner have same
time");
return;
}

}else {
System.out.println("Invalid");
}
}
}

11.Fun Count

package sda;
import java.util.*;
public class FunCount {
public static void main(String args[]) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number of element in array");
int no=sc.nextInt();
int count=1;
String arr[]=new String[no];
//String count1[]=new String[no];
for(int i=0;i<no;i++) {
arr[i]=sc.next();
sc.nextLine();
}for(int i=0;i<no;i++) {
for(int j=i+1;j<no;j++) {
if(arr[i].equals(arr[j])) {
count++;
arr[j]="";
}
}if(arr[i]!="") {
System.out.println(arr[i]+"="+count);
}
}

12.Gender Count:

package sda;
import java.util.*;
public class GenderCount {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
String str=sc.nextLine();
sc.close();
int mcount=0,fcount=0;
for(int i=0;i<str.length();i++) {
char ch=str.toLowerCase().charAt(i);
if(ch=='m') {
mcount++;

}else if(ch=='f') {
fcount++;
}else {
System.out.println("Invalid input");
return;

}
}
System.out.println(mcount+" Male");
System.out.println(fcount+" Female");
}

13.Harshad Number

package sda;
import java.util.*;
public class HarShadNumber {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the Number:");
int no=sc.nextInt();
if(no<=0) {
System.out.println("Invalid Input");
System.exit(0);
}
int rem=0;
int arr[]=new int[no];
int arr1[]=new int[no];
System.out.println("Enter the Element:");

for(int i=0;i<no;i++) {
arr[i]=sc.nextInt();
arr1[i]=arr[i];
}
int sum1[]=new int[no];
for(int i=0;i<no;i++) {
int sum=0;

while(arr[i]>0) {
rem=arr[i]%10;
sum=sum+rem;
arr[i]/=10;
sum1[i]=sum;
//sum=0;
}}

for(int i=0;i<no;i++) {
if(arr1[i]%sum1[i]==0) {

System.out.println(arr1[i]);
//System.out.println(sum1[i]);
}
}
}
}

14.Longest String:
package sda;
import java.util.*;
public class LongestString {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the string:");
String str=sc.nextLine();
int findex=0,lindex=0,length=0;
for(int i=0;i<str.length();i++) {
int asci=str.charAt(i);
System.out.println(str.charAt(i)+"1"+asci);

int count=1;
for(int j=i+1;j<str.length();j++) {
if(str.charAt(j)==++asci) {
System.out.println(str.charAt(j)+"2"+asci);
count++;
continue;
}else {
if(count>length) {
System.out.println(count+"3");

findex=i;
lindex=j;
length=count;
break;
}
}

}
}System.out.println(str.substring(findex,lindex));
}
}

15.Maximun No ADDition

package sda;
import java.util.*;
public class MaxAdd {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number of element in array:");
int no=sc.nextInt();
int max=0;
System.out.println("Enter the of element of array:");
int arr[]=new int[no];
for(int i=0;i<no;i++) {
arr[i]=sc.nextInt();
if(max<arr[i]) {
max=arr[i];
}
}
System.out.println(max);
}

16.Add with index

package sda;
import java.util.*;
public class MaxIndex {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the no of elements in arrays: ");
int no=sc.nextInt();
if(no<5) {
System.out.println(no+" is too low");
return;
}
if(no>10) {
System.out.println(no+" is too high");
}
int arr[]=new int[no];
int max=arr[0];
int index=0;

for(int i=0;i<no;i++) {
arr[i]=sc.nextInt();
if(arr[i]>max) {
max=arr[i];
System.out.println(max+" "+arr[i]);
index=i;
System.out.println(index);
}
}
for(int i=0;i<no;i++) {

if(i!=index) {
System.out.println(arr[i]+index);
}else {
System.out.println(arr[i]);
}
}
}

17.Product of Maximun and Minimun no


package sda;
import java.util.*;
public class MaxMinNo {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the array size:");
int no=sc.nextInt();
if(no>2) {
if(no<11) {
int arr[]=new int[no];
System.out.println("Enter the array element:");
for(int i=0;i<no;i++) {
arr[i]=sc.nextInt();
}
Arrays.sort(arr);
System.out.println(arr[0]*arr[no-1]);

}else {
System.out.println(no+" exceeds limit");

}
}else {
System.out.println(no+" is too small");

18.Mega Mart

package sda;
import java.util.*;
public class MeghaMart {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the customer id:");
String str=sc.nextLine();
String name=str.substring(0,4);
String mid=str.substring(str.length()-3,str.length());
System.out.println(mid);
String cus_type=str.substring(4,str.length()-3);
System.out.println(cus_type);
//System.out.println(mem_id);
String sname="Mega";
if(!name.equals(sname)) {
System.out.println("Invalid shop name");
return;
}else if(!mid.contains("[0-9]+")){
System.out.println("Invalid member id");
}
else if(mid.contains("[0-9]+")){
int mem_id=Integer.parseInt(str.substring(str.length()-
3,str.length()));

if(mem_id>99 && mem_id<1000) {


System.out.println("Invalid mem_id");
return;
}else {
System.out.println("Invalid member id");
return;
}
}
else if(!(cus_type.equals("Sliver") || cus_type.equals("Gold") ||
cus_type.equals("Paltinum")))
{
System.out.println("Invalid customer type");
}else {

System.out.println("Welcome "+name+" Mart "+cus_type+"


Customet");
}

19.MRP

package sda;
import java.util.*;

public class MrpAssesment {


public static void main(String args[]) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number");
String no=sc.nextLine();
int len=no.length();
int dis=0;
if(len>=6 && len<=8) {
String mrp=no.substring(len-4);
int mrp1=Integer.parseInt(mrp);
System.out.println("MRP: Rs "+mrp1);
if(mrp1>=1 && mrp1<=10) {
dis=mrp1;
}
else if(mrp1>=11 && mrp1<=50)
{
dis=mrp1-5;
//System.out.println("Offer price: Rs "+ mrp1);

}
else if(mrp1>=51 && mrp1<=500) {
dis=mrp1-15;
}
else if(mrp1>=501 && mrp1<=5000)
{
dis=mrp1-105;
}
else {
dis=mrp1-1005;
}

System.out.println("Offer price: Rs "+ dis);


}else {
System.out.println("Invalid Input");
}

}
}

20.Next Missing letter


package sda;
import java.util.*;
public class NextMixingLetter {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
String str=sc.nextLine();
int sub=str.charAt(0)-str.charAt(1);
for(int i=0;i<str.length()-1;i++) {
int no1=str.charAt(i);
int no2=str.charAt(i+1);
int diff=no1-no2;
if(sub!=diff) {
System.out.println(str+" is not a squence");
return;
}
}
System.out.println("Enter the sequence times");
int seq=sc.nextInt();
if(seq<=0) {
System.out.println(seq+" is invalid");
return;
}

int temp=str.charAt(str.length()-1);
System.out.print(temp+" "+(char)temp);
for(int j=0;j<seq;j++) {
temp=temp-sub;
System.out.print(temp+" "+(char)temp);
if(temp>122) {
// System.out.print(temp+"
"+(char)temp);
temp=temp-26;
System.out.print((char)temp);
}else if(temp<97) {
//System.out.print(temp+"
"+(char)temp);
temp=temp+26;
System.out.print((char)temp);
}else {
System.out.print((char)temp);
}

}
}

21.Find particular Number


Input
123453
No to find
3
Output
2

package sda;
import java.util.*;
public class NoFind {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the numbe");
int n=sc.nextInt();
System.out.println("Enter number to be search");
int sea=sc.nextInt();
int count=0;
while(n!=0) {
int rem=n%10;
//System.out.println(rem);
if(rem==sea) {
count++;
}
n=n/10;
//System.out.println(n);
}
System.out.println(count);
}

22.Numerology
package sda;

import java.util.*;
public class Numerology{
public static void main (String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter your Name");
String str1=sc.next();
String str=str1.toUpperCase();
int value=0,sum=0;
if(str.matches("[A-Z]+")){
for(int i=0;i<str.length();i++){
value=(int)(str.charAt(i));
sum+=value;

}
if(sum%2==0 && sum%3==0) {
System.out.println(sum+"\n"+str1+" is a Numerology
name");

}
else{
System.out.println(sum+" is not a Numerology name");
return;
}

}
else {
System.out.println(str1+" is an invalid name");
}
}
}

23.Find Odd number of Studentpackage sda;


import java.util.*;
public class OddCombine {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the set of students:");
int no=sc.nextInt();
int count=0;
if(no>0) {
int arr[]=new int[no];
for(int i=0;i<no;i++) {
arr[i]=sc.nextInt();
if(arr[i]<0) {

System.out.println(arr[i]+" Invalid roll


number");
return;
}
}
for(int i=0;i<no;i++) {
if(arr[i]%2!=0) {
System.out.print(arr[i]);
}else {
count++;
}
}
if(count==no) {
System.out.println(no+" numbers are not odd");
}
}else {
System.out.println(no+" ia an invalid size");
}
}

24.Customer Offer

package sda;
import java.util.*;
public class OfferCustomer {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Invalid string");
int no=sc.nextInt();
//sc.nextLine();
String str[]=new String[no];
// String str1[]=new
if(no>3) {
System.out.println("Customer count is too low");
return;
} if(no>0) {
System.out.println("Invalid input");
return;
}if(no<50){
System.out.println("Customer count is too high");
return;
}for(int i=0;i<3;i++) {
str[i]=sc.nextLine();
}
System.out.println("Enter plan id to be searched:");
String pid=sc.next();
for(int i=0;i<no;i++) {
String arr[]=str[i].split(":");
if(pid.equals(arr[1])){
System.out.println(arr[3]+" "+arr[2]);

}
}

}
}

25.Prime Number
package sda;
/*import java.util.*;
public class PrimeNo {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int no1=sc.nextInt();
int no2=sc.nextInt();
//int f=0;
if(no1<0 || no2<0) {
System.out.println("Negative integer can not be
prime");
}else if(no1>no2) {
System.out.println("Invalid input");
}else if (no1==0 && no2==1) {
System.out.println("There are no prime number in the
range 0 to 1");
}
else {
for(int i=no1;i<=no2;i++) {
int f=0;
for(int j=1;j<=i;j++) {
if(i%j==0) {
f++;
}
}if(f==2) {
System.out.println(i);
}
}

}
sc.close();
}

}*/
import java.util.*;
public class PrimeNo {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int a=sc.nextInt();
int b=sc.nextInt();
boolean flag=false;
if(a>b)
{
System.out.println("Invalid Input");
return;
}
else if(a<0 || b<0)
{
System.out.println("Negative integers cannot be
prime");
return;
}
else if( a<=b && a>0 && b>0)
{
for(int i=a;i<=b;i++)
{
int count=0;
for(int j=1;j<=i;j++)
{
if(i%j==0)
count++;
}
if(count==2)
{
System.out.print(i+" ");
flag=true;
}
}
}
if(flag==false)
{
System.out.println("There are no prime numbers in the
range "+a+" to "+b);
return;
}
}
}

26.Product od prime number

package sda;

import java.util.*;
public class PrimeProduct {
public static void main(String args[]) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter no of element in array");
int no=sc.nextInt();
if(no>0) {
System.out.println("Array element");
int pd=1,f=0,f1=0;
int arr[]=new int[no];
for(int i=0;i<no;i++) {
arr[i]=sc.nextInt();
if(arr[i]>0) {
for(int j=2;j<arr[i]/2;j++) {
if(arr[i]%j==0)
{
f1=1;
}
}if(f1==0) {
System.out.println(arr[i]);
pd=arr[i]*pd;
f++;
}

}else {
System.out.println(arr[i]+" Invalid array
element");
}
}if(f!=0) {
System.out.println(pd);
}else {
System.out.print("No element found in ");
for(int k=0;k<no;k++)
System.out.print(arr[k]);
}
}else {
System.out.println(no+ " Invalid array size");
}
}

private static void checkPrime(int i) {


// TODO Auto-generated method stub

27.Public Distribution
package sda;
import java.util.*;
public class PublicDistrubution {
public static void main(String args[]) {
Scanner sc=new Scanner(System.in);
String str=sc.nextLine();
if(str.length()<2 || str.length()>5) {
System.out.println("invalid input");
return;
}
int amount,total=0;

if(str.matches("[ORWKS]+")) {
for(int i=0;i<str.length();i++) {
if(str.charAt(i)=='O') {
amount=12*2;
total=total+amount;
}else if(str.charAt(i)=='K') {
amount=18*2;
total=total+amount;
}else if(str.charAt(i)=='W') {
amount=22*2;
total=total+amount;
}else if(str.charAt(i)=='R') {
amount=15*2;
total=total+amount;
}else if(str.charAt(i)=='S') {
amount=21*2;
total=total+amount;
}

}
System.out.println(total);
}else {
System.out.println("Invalid input");
}
}
}

28.Reverse String
package sda;
import java.util.*;
public class ReserveString {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the string");
String str=sc.nextLine();
String str1[]=str.split(" ");
int len=str1.length;
String rev = "";
//System.out.println(len);
int f=0;
char ch=str1[0].toUpperCase().charAt(0);
if(len>=3 ) {
for(int i=0;i<len;i++)
if(str1[i].matches("[a-zA-Z]+")) {

if(ch==str1[i].toUpperCase().charAt(0)) {
f++;

}
}else {
System.out.println("Invalid word");
return;
}
if(f==len) {
String s1=str1[len-1];
int l1=s1.length();

for(int i=l1-1;i>=0;i--) {
rev=rev+s1.charAt(i);
}
System.out.println(rev+str1[0]);

}else {
String s1=str1[0];
for(int i=s1.length()-1;i>=0;i--) {
rev=rev+s1.charAt(i);
}
System.out.println(rev+str1[len-1]);
}

}else {
System.out.println("Invalid Sentence");

}
}
}
29.Reverse Prime number
package sda;
import java.util.*;
public class ReversePrime {
public static void main(String args[]) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number of values");
int no=sc.nextInt();
if(no>0) {
int c=0;
int arr[]=new int[no];
System.out.println("Enter the numbers");
for(int i=0;i<no;i++) {
arr[i]=sc.nextInt();
}
for(int i=0;i<no;i++) {
int f=0,f2=0;
//System.out.println(arr[i]);
if(arr[i]>9) {
for(int j=2;j<arr[i]/2;j++) {
if(arr[i]%j==0) {
f=1;
}
}if(f==0) {
//f1=1;
// System.out.println(arr[i]);
int sum=0;
int prime=arr[i];
while(prime!=0)
{
int rem=prime%10;
sum=rem+sum*10;
prime/=10;
}
//System.out.println(sum);
for(int k=2;k<sum/2;k++) {
if(sum%k==0) {
f2=1;
}
}if(f2==0) {
System.out.println(arr[i]);

}
}else {
c++;
}

}else {
System.out.println(arr[i]+" is not valid");
return;
}
}if(c==no) {
System.out.println(no+" is not contain any
reverse prime");
return;
}
}else {
System.out.println(no+" is not valid");
}
}
}

30.Reverse Palindrome
package sda;
import java.util.*;
public class RevPalin {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the string");
String str=sc.nextLine();
String str1[]=str.split(" ");
String rev[]=Arrays.copyOf(str1, str1.length);
for(int i=0;i<str1.length;i++) {
StringBuilder sb=new StringBuilder(rev[i]);
sb.reverse();
rev[i]=sb.toString();
System.out.print(rev[i]+" ");
}
for(int i=0;i<str1.length;i++)
if(rev[i].equals(str1[i]) && str1[i].length()>1) {
System.out.println(rev[i]);
}

31.
Same String
Input:Entertaiment
Substring: en
Output:2
package sda;
import java.util.*;

public class SameString {


public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the String");
String str=sc.nextLine();
System.out.println("Enter subString");
String sub_str1=sc.nextLine();
int count=0;
if(str.matches("[a-zA-Z]+")) {

for(int i=0;i<str.length()-1;i++) {
String str1=str.substring(i,i+sub_str1.length());
System.out.println(str1);
if(sub_str1.equals(str1)) {
count++;
}
}
if(count!=0) {
System.out.println(sub_str1+" found in given string is
"+count);

}
else {
System.out.println("No matching found");

}else {
System.out.println("Invalid string");

32.Print Second Last Number in Array

package sda;
import java.util.*;
public class SecondLast {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the no of element in array");
int n=sc.nextInt();
System.out.println("Enter the elements in array");
int a[]=new int[n];
for(int i=0;i<n;i++) {
a[i]=sc.nextInt();
}
Arrays.sort(a);
System.out.println(a[n-2]);

}
}

33.Secreate Code

package sda;
import java.util.*;
public class SecreateCode {
public static void main(String args[]) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the name of the child");
String str=sc.nextLine();
int len=str.length();
if(len>=4) {
if(str.matches("[a-zA-Z]+")) {
System.out.println("Enter the birthdate of the
child");
int no=sc.nextInt();
if(no>=1 && no<=31) {

System.out.println(str.substring(0,4)+"@"+no);
}else {
System.out.println("Secreat code can not be
genrated");
return;
}
}else {
System.out.println("Secreat code can not be
genrated");
return;
}
}else {
System.out.println("Secreat code can not be genrated");
return;
}
}
}

34.
Compare Sum and Product
Output:35,168

package sda;
import java.util.*;
public class SumCompareProduct {
public static void main(String args[]) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter no of size of First Arrya:");
int no1=sc.nextInt();
System.out.println("Enter no of size of second Arrya:");
int no2=sc.nextInt();
int arr[]=new int[no1];
int arr1[]=new int[no2];

int pa[]=new int[no1];


int sa[]=new int[no2];

int sum1=1,rem=0,sum2=0,count=0;
if(no1>0 && no2>0) {
if(no1==no2) {
System.out.println("enter the element in first
array");
for(int i=0;i<no1;i++ ) {
arr[i]=sc.nextInt();
}
for(int i=0;i<no1;i++) {
int a1[]=new int[no1];
a1[i]=arr[i];
while(a1[i]!=0) {
rem=a1[i]%10;
sum1=rem*sum1;
a1[i]=a1[i]/10;
}

pa[i]=sum1;
sum1=1;
System.out.println(pa[i]);
}
System.out.println("enter the element in second
arrays");
for(int j=0;j<no2;j++) {
arr1[j]=sc.nextInt();
}
for(int j=0;j<no2;j++) {
int a2[]=new int[no2];
a2[j]=arr1[j];

while(a2[j]!=0) {
rem=a2[j]%10;
sum2=rem+sum2;
//sa[j]=sum2;
a2[j]=a2[j]/10;
}

sa[j]=sum2;
sum2=0;
System.out.println(sa[j]);
}
for(int k=0;k<no1;k++) {
if(pa[k]==sa[k]) {

System.out.println(arr[k]+","+arr1[k]);
count++;
}

}if(count==0) {
System.out.println("No match Found");

}else {
System.out.println("Array size is
diffrent");
}

}else {
System.out.println("Invalid array size");
}
}

}
36.Toy shop

package sda;
import java.util.*;
public class ToyShop {
public static void main(String args[]) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number of months");
int month=sc.nextInt();
if(month>0) {
System.out.println("Enter the number of toys purchased
monthly");
int toys[]=new int[month];
for(int i=0;i<month;i++) {
toys[i]=sc.nextInt();
if(toys[i]<10) {
System.out.println(toys[i]+" is an invalid
number of toy");
return;
}
}
int max=toys[0];
for(int i=1;i<month;i++) {
if(max<=toys[i]) {
max=toys[i];
}
}
for(int i=0;i<month;i++) {
if(toys[i]==max) {
System.out.println("month "+(i+1));
}

}
}else {
System.out.println("Invalid month");
}

37.Unique Char string


Input:life is inherantely perfect
Output: life is ihrtly prfct
package sda;
import java.util.*;
public class UniqueCharString {
public static void main(String args[]) {
Scanner sc=new Scanner(System.in);
String str=sc.nextLine();
String word[]=str.split(" ");
if(str.matches("[a-zA-Z ]+")) {
for(int i=0;i<word.length;i++) {
String unique=word[i];
StringBuilder sb=new StringBuilder(unique);
for(int j=0;j<sb.length();j++) {
for(int k=j+1;k<sb.length();k++) {
if(sb.charAt(j)==sb.charAt(k)) {
sb.deleteCharAt(k);
sb.deleteCharAt(j);
}
}
}System.out.print(sb+" ");
}
}else {
System.out.println(str+" Invalid Sentence");
}
}
}
Longest substring

Input : abczgdpqrstubg
Output: pqrstu
*/
import java.util.*;
public class Main
{
public static void main (String[] args)
{
Scanner sc=new Scanner(System.in);
String s=sc.next();
int firstindex=0,lastindex=0,length=0;
for(int i=0;i<s.length();i++)
{
int asci=s.charAt(i);
int count=1;
for(int j=i+1;j<s.length();j++)
{
if(s.charAt(j)==++asci)
{
count++;
continue;
}
else
{
if(count>length)
{
firstindex=i;
lastindex=j;
length=count;
break;
}
}
}
}
System.out.println(s.substring(firstindex,lastindex));
}
}

Non Unique char Elimination from string


public class NonUniqueElimination {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
String name=sc.nextLine(),abc="";
int count=0;
for(int i=0;i<name.length();i++)
{
for(int j=1;j<name.length()-1;j++)
{
if(name.charAt(i)==name.charAt(j))
{
name=name.replace(String.valueOf(name.charAt(j)),"");
count+=1;
}
}
}
if(count==0) {
System.out.println("All are unique character");
return;
}
else {
System.out.println(name);
}
}
Sum of integers at even or odd places

need to specify size (say 5) and then take 5 integer numbers as Input. If the number of
digits in the number is odd then we need to add all odd places digits and if number of
digits is even then we need to add all even place digits. In the end sum of all these
individual sum needs to be displayed as result.

Eg enter size :5
Enter numbers
123(1+3=4)
2536(5+6=11)
2(2)
57(7)
76542(7+5+2=14)
Output: 38 (4+11+2+7+14)

No of substring from a given string

Given a string and a substring, find the number of occurances of the substring in the
given string.
Check that the string can contain only alphabets.
Consider both string and substring in lower case.
Eg:
Enter the string
Entertainment
Enter substring
en
Output : 2
Unknown

input: psvy & 4


(find the difference between p&s i.e 2 and print next 4 letters)
Output: behk

calculate Price*Duration after the deduction of discounts in a Bike renting Company

*Name should be only in alphabets.. If not Print Invalid


*discount eligible only when the Duration is 5 or more
*Discount table will be given for each card (like Visa,Rupay,Mastercard)
*You have to apply discount for based on the option they used.. (This data is as 1,2,3
where option 1 is visa card option 2 is Rupay)
*If Card option is given as 4,5,6,,... OR 0,-1,-2,,,.. Print "Try again" and go back to get
card option until it's a valid one..

best runner from the given inputs

Input will be given as(Name,seconds)


Jorge, 9.78
Alex, 9.65

Order identification

U need to find weather the array elements are in ascending order r not
Note:array size between 2 and 10(inclusive)
Input1:
Enter the array size:3
Enter the elements
53
52
51
Output:
53 52 51 are not in ascending order

Input2:
Enter the array size:5
Enter the elements
32
65
71
78
82
Output:
32 65 71 78 82 are in ascending order

Product of case count

you need to count uppercase letters and lower case letters in a given string
Multiply the counts and display
Note: string shouldn't contain any digits, special characters
Length shouldn't be greater than 10
Input:
YouRName
Output:
Product value is 15
Explanation
Uppercase letters=3
Lowercase letters=5
Display 3*5=15

import java.util.*;
public class Program{

public static void main(String[] args){


Scanner sc = new Scanner(System.in);
int countj=0,countk=0,i;
System.out.println("Enter string:");
String str=sc.next();
char str1[]=new char[str.length()];
for( i=0;i<str.length();i++) {
if(str.charAt(i)<=122&&str.charAt(i)>=97) {
countj++;
}
else if(str.charAt(i)<=90&&str.charAt(i)>=65) {
countk++;
}
}
System.out.println(countj+" "+countk);
int product=countj*countk;

System.out.println(product);

}}

Unknown

Here, size of the array should be taken as input, and it should be between 1 and 10
(inclusive)
If it is not in 1 and 10, print it as "invalid"
Now, by the comparing the values at the same indices of both the arrays, if both
values are even, then print the sum of the two values, otherwise print "0".
Before performing operation, make sure if no even element is present in both the
arrays, then print it as "There are no even elements in both the arrays", otherwise
perform the above operation.
For example, see the following inputs and outputs:
1. Sample input:
Enter the size of array: 3
Enter the elements in first array:
2
3
4
Enter the elements in second array:
1
5
8
Sample output:
0
0
12

2. Enter the size of array: 3


Enter the elements in first array:
5
3
1
Enter the elements in second array:
1
5
9
Sample output:
There are no even elements in both the arrays

3.Sample input:
Enter the size of array: 1
Enter the elements in first array:
5
Enter the elements in second array:
1
Sample output:There are no even elements in both the arrays

Unkown

Here, a list of grocery items are present as follows:


Rice - 3kg, 5 Rs/kg
Wheat - 2kg, 10Rs/kg
Oil - 4litres, 20Rs/litre
Kerosene - 5litres, 15Rs/litre

Now each of the items is abbreviated by R,W,O and K respectively

Sample input:
ORW
Sample output: the
115

Offer to customers
Toll fee for region code
Take input string of numbers. Extract last four numbers from the string. Calculate the
discount price of the product based on those four numbers.

We need to input the product code as a string


The length of that string shd be of 6-8
If not print invalid
And we need to extract last 4 characters from that string, that will be the MRP of the
product
If the MRP is between 0 to 10, then offer is 0₹
If MRP between 11 to 50, offer is 5₹
If MRP between 51 to 500, offer is 15
If MRP between 501 to 5000, offer is 105
If MRP is above 500, offer is 1005

We need to print the MRP as well as the price after the offer is applied

Sample input 1
20220050
Output 1
MRP : ₹50
Offer price : ₹45

Sample input 2
350004
Output 2
MRP: ₹4
Offer price :₹4

Sample input 3:
202200050
Output 3:
Invalid input
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String n = sc.nextLine();
if (5 < n.length() && n.length() < 9) {
String s = n.substring(n.length() - 4);
int price = Integer.parseInt(s);
if (0 < price && price < 10) {
System.out.println("MRP: Rs " + price);
System.out.println("Offer Price: Rs " + price);
} else if (10 < price && price < 51) {
System.out.println("MRP: Rs " + price);
System.out.println("Offer Price: Rs " + (price - 5));
} else if (50 < price && price < 501) {
System.out.println("MRP: Rs " + price);
System.out.println("Offer Price: Rs " + (price - 15));
} else if (500 < price && price < 5001) {
System.out.println("MRP: Rs " + price);
System.out.println("Offer Price: Rs " + (price - 105));
} else if (5000 < price) {
System.out.println("MRP: Rs " + price);
System.out.println("Offer Price: Rs " + (price - 1005));
}
} else {
System.out.println("Invalid Input");
}
}

Reverse and Concatenate

She sells seashells


Same first letter for all words so reverse the last word and concatenate first word
Output: sllehsaesShe

If first letter is not same then reverse first word and concatenate with last word

Male female version code


import java.util.*;
import java.util.regex.Pattern;
public class Main{
public static void main(String args[]){

Scanner sc = new Scanner(System.in);

String str = sc.next();

int count=0;
int count1=0;

if(Pattern.matches("[mfMF]+",str)){

for(int i=0;i<str.length();i++){
if(str.charAt(i)=='M' || str.charAt(i)=='m'){
count++;
}
else if( str.charAt(i)=='F' || str.charAt(i)=='f'){
count1++;
}
}
System.out.println(count+" Male");
System.out.println(count1+" Female");
}
else{
System.out.println("Not a valid input");
return;
}
}
}
LCM

Tony comes to hotel every 4(i) days and potts every 6(j) days when will they meet? if
i or j <0 print invalid, don't use system.exit (To find LCM)

Cake
Input : 4725strawberry181
Extract the weight , flavour , order id and output the cake price according to per kg price given
initially , and print all the cake details.
Output :
4.73 kg
Strawberry
181
Price:

import java.util.*;
public class cake_order {
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
String s=sc.next();
if(!s.matches("^[a-zA-z0-9]*$"))
{
System.out.println("Invalid string");
return;
}
else
{
String str=s.substring(0,4);
for(int i=0;i<str.length();i++)
{
if(!Character.isDigit(str.charAt(i)))
{
System.out.println("Invalid string");
return;
}

}
int num=Integer.parseInt(str);
if(num<1000)
{
System.out.println("Invalid weight");
return;
}
int l=s.length();
int li=l-3;
String s1=s.substring(li,l);
for(int i=li;i<l;i++)
{
if(!Character.isDigit(s.charAt(i)))
{
System.out.println("Invalid orderno");
return;
}
}
int k=Integer.parseInt(s1);
if(k<100)
{
System.out.println("Invalid Order no");
return;
}
double I=Double.parseDouble(str)/1000;
String form=String.format("%.2f", I);
System.out.println("Cake weight is "+form);
String falv="";
for(int i=4;i<li;i++)
{
falv+=s.charAt(i);
}
System.out.println("Cake flavour is "+falv);
System.out.println("Order no is "+s1);
double price=450*I;
String f=String.format("%.2f",price);
System.out.println("Price is "+f);
}
}
}
Products equals sum
Fun count

Input array of string


if there is 5 input
barbie
barbie
doll
doll
bike

output
barbie=2
doll=2
bike=1
Speed Calculation

The normal_speed 30km/h was given


Take two input hours and distance
Find speed= distance/hours
if speed > normalspeed
then
Actual speed=speed-normal_speed
print actual speed
else
print continue on speed

Add with index


Next Mixing Letters
Mega mart customer identification
Theater seat details
Compose Rhythm(Prime numbers btw two no’s)
Rating Score
Unknown
JAVA

1. LCM OF DAY INTERVAL/LUNCH TOGETHER/DINNER TOGETHER

INPUT: Enter the day interval of Tony : 4


Enter the day interval of Potts: 6

OUTPUT: Tony and Potts will have dinner together on 12th day.

import java.util.Scanner;
public class lcm {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the day interval of Sam:");
int n1 = sc.nextInt();
System.out.println("Enter the day interval of Riya:");
int n2 = sc.nextInt();
if(n1<=0 || n2<=0)
{
System.out.println("Given interval is not valid");
return;
}
int lcm;
lcm = (n1 > n2) ? n1 : n2;
while(true) {
if( lcm % n1 == 0 && lcm % n2 == 0 ) {
System.out.printf("Sam and Riya will have their dinner on day "+lcm);
break;
}
++lcm;
}
}
}

ALTERNATE METHOD

import java.util.Scanner;
public class Lunchlcm {
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the day interval of Tony");
int n1=sc.nextInt();
System.out.println("Enter the day interval of Potts");
int n2=sc.nextInt();
if(n1<=0 && n2<=0)
{
System.out.println("Given interval is not valid");
return;
}
int a=n1;
int b=n2;
while(n2>0)
{
if (n1 > n2)
{
n1 = n1 - n2;
} else
{
n2 = n2 - n1;
}
}
int gcd = n1;
int lcm = (a * b) / gcd;

System.out.println("Tony and Potts will have lunch together on " + lcm + " day");
}
}

*********************************************************************************************
*********************************************************************************************
**
2.SCORE OF REPEATING WORDS/ WORD REPETITION

INPUT: Enter the String: GOOD


Enter the sentence: GOOD FOOD GOOD LIFE

OUTPUT: Score is 2

import java.util.*;
class PrintMessage
{
public static void main (String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the string");
String s=sc.next();
int count=0;
int sum=2;
for(int i=0;i<s.length();i++)
{
if(Character.isDigit(s.charAt(i)) || Character.isLetter(s.charAt(i)) || s.charAt(i)==' ')
{
continue;
}
else
{
System.out.println(s+" is not valid String");
return;
}
}
System.out.println("Enter the sentence");
sc.nextLine();
String sentence=sc.nextLine();
String[] w=sentence.split(" ");
for(int i=0;i<w.length;i++)
{
if(w[i].equalsIgnoreCase(s))
{
count++;
if(count>2)
{
sum=sum*2;
}
}
}
if(count>2)
{
System.out.println("Score is "+sum);
}
else
{
System.out.println("Score is"+count);
}
}
}

*ALTERNATE METHOD

import java.util.Scanner;
public class CountWords {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String word, sentence;ed
int count = 0;
System.out.println("Enter a word:");
word = in.nextLine();
System.out.println("Enter a sentence");
sentence = in.nextLine();

if (!(word.matches("[a-z]+"))) {
System.out.println("Invalid Input");
return;
}
String words[] = sentence.toLowerCase().split(" ");
for (int i = 0; i < words.length; i++) {
if (word.equals(words[i])) {
count++;
}
}
System.out.println("Score is:" + ((int) Math.pow(2, count - 1)));
}
}
*********************************************************************************************
*********************************************************************************************
***

3)BATTERY CAPACITY

INPUT: Enter battery capacity :1230


Enter charging current value: 400

OUTPUT: 3.69 Hours

import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter battery capacity:");
double capacity = sc.nextDouble();
if(!(capacity>=1000 && capacity<=10000)) {
System.out.println("Invalid battery capacity");
return;
}
System.out.println("Enter charging current value:");
double current = sc.nextDouble();
if(!(current>=300 && current<=2100)) {
System.out.println("Invalid output current");
return;
}
double time=0.0f;
time = (capacity/current)*1.2;
System.out.println(String.format("%.2f",time)+" Hours");
}

*********************************************************************************************
*********************************************************************************************
***
4) STUDENTS WHOSE ROLLNO ARE ODD

INPUT: Entr the set of students :5


Enter the roll number :1
3
4
5
6

OUTPUT: 135

import java.util.*;
public class Main
{
public static void main(String[] args) {
System.out.println("Enter the set of students");
Scanner s=new Scanner(System.in);
int setn=s.nextInt();
if(setn<=0)
{
System.out.println(setn+" is an invalid size");
return;
}
System.out.println("Enter the roll number");
int[] rolls=new int[setn];
int oddflag=0;
for(int i=0;i<setn;i++)
{
rolls[i]=s.nextInt();
if(rolls[i]<0)
{
System.out.println(rolls[i]+" is an invalid roll number");
return;
}
if(rolls[i]%2!=0)
{
oddflag=1;
}
}
if(oddflag==0)
{
System.out.println("The "+setn+" numbers are not odd");
return;
}
String str="";
for(int i=0;i<setn;i++)
{
if(rolls[i]%2!=0)
{
str=str+rolls[i];
}
}
for(int n=0;n<str.length();n++)
{
System.out.println(str.charAt(n)+" ");
}
}
}
*********************************************************************************************
*********************************************************************************************
**

5) CALCULATING BILL AMOUNT

INPUT : Enter your name : Sam


Enter the time duration: 13
List of payment options
1)Visa card
2)Rupay card
3)Master card
Choose an option : 2

OUTPUT: Dear Sam your bill amount is 1294.80

import java.util.*;
public class Main
{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter your name");
String s=sc.nextLine();double sal=0;double disc=0;
for(int i=0;i<s.length();++i)
{
if(!Character.isLetter(s.charAt(i)))
{
System.out.println("Invalid Name");
return;
}
}
System.out.println("Enter the time duration");
int n=sc.nextInt();int n1;
if(n<=0 || n>24)
{
System.out.println("Invalid duration");
return;
}
System.out.println("List of payment options");
System.out.println("1)Visa card");
System.out.println("2)Rupay card");
System.out.println("3)Master card");
System.out.println("Chosse an option");
while(true)
{
n1=sc.nextInt();
if(n1<0||n1>3)
{
System.out.println("Try again");
}
else
{
break;
}
}
if( n1==1)
{
if(n>=5)
{
sal=120*n;
disc=(sal*0.25);
sal=sal-disc;
}
else
{
sal=n*120;
}
}
if(n1==2)
{
if(n>=5)
{
sal=120*n;
disc=(sal*0.17);
sal=(120*n)-disc;
}
else
{
sal=n*120;
}
}
if(n1==3)
{
sal=n*120;
}
System.out.print("Dear "+s+" your bill amount is ");
System.out.printf("%.2f", sal);
}
}

*********************************************************************************************
*********************************************************************************************
***
6) ODD POSITION CHAR WILL BE IN UPPERCASE & EVEN WILL BE LOWERCASE-

INPUT : school

OUTPUT : sChOol

import java.util.Scanner;
public class UPLC{
public static void main(String []args){
Scanner sc = new Scanner(System.in);
String str = sc.next();
int strlen = str.length();
for(int i = 0 ; i < str.length(); i++){
char ch = str.charAt(i);
if(!(ch >= 'a' && ch <='z' || ch >= 'A' && ch <='Z' )){
System.out.println(str+ " is an invalid input");
return;
}
}

if(strlen >= 5 && strlen <= 20){


StringBuffer updateString = new StringBuffer();
char[] charArr = str.toCharArray();
for(int i = 0 ; i < charArr.length; i++){
char ch = charArr[i];
if(i % 2 != 0){
ch = Character.toUpperCase(ch);
}
updateString.append(ch);
}
System.out.println(updateString.toString());
}
else {
System.out.println(str+ " is an invalid Length");
}
}
}

*********************************************************************************************
*********************************************************************************************
****
7) RATING SCORE

INPUT: ENTER JESSON SCORE


1
2
3
4
8
ENTER JAMES SCORE
0
2
6
5
6

OUTPUT: JESSON SCORE : 2


JAMES SCORE : 2

import java.util.Scanner;
public class Ratingscore {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter Jesson Score");
int[] a1 = new int[5];
int[] a2 = new int[5];
int f = 0;
int t = 0;
int sum = 0;
int sum1 = 0;
for (int i = 0; i < 5; i++) {
a1[i] = sc.nextInt();
if (a1[i] < 0) {
f = 1;
t = a1[i];
break;
}
}
if (f == 1) {
System.out.println(t + " is invalid");
} else {
System.out.println("Enter James Score");
for (int j = 0; j < 5; j++) {
a2[j] = sc.nextInt();
if (a2[j] < 0) {
f = 1;
t = a2[j];
break;
}
}
if (f == 1) {
System.out.println(t + " is invalid");
} else {
for (int k = 0; k < 5; k++) {
if (a1[k] > a2[k]) {
sum++;
}
if (a1[k] < a2[k]) {
sum1++;
}
}
System.out.println("Jesson Score");
System.out.println(sum);
System.out.println("James Score");
System.out.println(sum1);
}
}
}
}

**ALTERNATE METHOD:

import java.util.Scanner;
public class minmax {
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
int jesson=0,james=0,c=0;
int a[]=new int[5];
int b[]=new int[5];
System.out.println("Enter Jesson Score");
for(int i=0;i<a.length;i++)
{
a[i]=sc.nextInt();
if(a[i]<0)
{
System.out.println("Invalid");
Runtime.getRuntime().halt(0);
}
}
System.out.println("Enter James Score");
for(int i=0;i<b.length;i++)
{
b[i]=sc.nextInt();
if(b[i]<0)
{
System.out.println("Invalid");
Runtime.getRuntime().halt(0);
}
}
if(a.length==b.length)
{
for(int i=0;i<a.length;i++)
{
if(a[i]>b[i])
{
jesson++;
}
else if(a[i]<b[i])
{
james++;
}
else if(a[i]==b[i])
{
c++;
}
}
System.out.println("Jesson Score: "+jesson);
System.out.println("James Score: "+james);
}
else{
System.out.println("Length not same");
}
}
}

*********************************************************************************************
*******************************************************************************

8.COUNT OF UPPERCASE AND COUNT OF LOWERCASE & OUTPUT WILL BE IN THE FORM OF
(UP-LC)

INPUT : HosTEL

OUTPUT: 4-2=2

import java.util.Scanner;

public class ContNext {


public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the string");
String str=sc.nextLine();
int uc=0,lc=0;
if(str.matches("[A-Za-z ]+")&&str.length()<10) {
for(int i=0;i<str.length();i++)
if(Character.isUpperCase(str.charAt(i))) {
uc++;
}
else if(Character.isLowerCase(str.charAt(i))){
lc++;
}
System.out.println(uc-lc);
}
}
}
*********************************************************************************************
*******************************************************************************
9) PRODUCT of COUNT of UPPERcase

andLOWERcaseletters

INPUT: ABsdEr

OUTPUT: 6 (3*3)

import java.util.Scanner;
public class minmax {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the String");
String s = sc.nextLine();
int upper = 0;
int lower = 0;
int i;
if (s.matches("[a-zA-Z]+")) {
for (i = 0; i < s.length(); i++) {
char c = s.charAt(i);
if (c >= 'A' && c <= 'Z') {
upper++;
}
if (c >= 'a' && c <= 'z') {
lower++;
}
}
System.out.println(upper * lower);
}
else
{
System.out.println("Invalid String");
}

}
}

*********************************************************************************************
******************************************************************************
10.Count of UPPERcase and LOWERcase and their difference

Enter the String: ColLEgE


Count of uppercase is : 4
Count of lowercase is : 3
Hence the ans is : 1

import java.util.Scanner;
public class MyClass {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the String ");
String str = sc.next();
int strlen = str.length();
for(int i =0; i < str.length() ; i++)
{ char ch = str.charAt(i);
if(!(ch >='a' && ch <= 'z' || ch >= 'A' && ch <= 'Z')){
System.out.println(str + " is an invalid String");
return;
}
}

if(strlen > 0 && strlen <= 10){


int upper = 0, lower = 0, ans = 0;

for(int i = 0; i < str.length(); i++)


{
char ch = str.charAt(i);
if (ch >= 'A' && ch <= 'Z')
upper++;
else if(ch >= 'a' && ch <= 'z')
lower++;
}
ans = upper - lower;
System.out.println("count of uppercase is :"+ upper);
System.out.println("count of lowercase is :"+ lower);
System.out.println("Hence the ans is :"+ ans);
}
else {
System.out.println(str + " is an invalid String");
}
}
}
*********************************************************************************************
*******************************************************************************
11.PUBLIC DISTRIBUTION

INPUT : OKR

OUTPUT : 90

import java.util.*;
public class Main
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
String str = in.nextLine();
int l=str.length();
if(l>5 || l<2)
{
System.out.println("Invalid Input");
}
else
{
int sum=0,flag=0;
for(int i=0;i<l;i++)
{
char c=str.charAt(i);
if(c=='O')
{
sum=sum+24;
}
else if(c=='K')
{
sum=sum+36;
}
else if(c=='S')
{
sum=sum+42;
}
else if(c=='R')
{
sum=sum+30;
}
else if(c=='W')
{
sum=sum+44;
}
else
{
flag=1;
}
}
if(flag==1)
{
System.out.println("Invalid Input");
}
else
{
System.out.println(sum);
}
}
}
}
*********************************************************************************************
******************************************************************************

12.LOTTERY TICKETS

INPUT: Enter the Starting range


23467
Enter the Ending range
23477

OUTPUT: 23469
23472

import java.util.*;
public class Main {
public static void main(String args[])
{
int i,c,n,sum,count;
sum=0;count=0;n=0;c=0;i=0;
Scanner sc = new Scanner(System.in);
System.out.println("Enter the Starting range");
int a = sc.nextInt();
String str = Integer.toString(a);
if(str.length()!=5)
{
System.out.println(str + " is an invalid input");
System.exit(0);
}

System.out.println("Enter the Ending range");


int b = sc.nextInt();
String str1 = Integer.toString(b);
if(str1.length()!=5)
{
System.out.println(str1 + "is an invalid input");
System.exit(0);
}

if(a>b)
{
System.out.println(a+" and "+b+" are invalid serial numbers");
System.exit(0);

}
for(i=a;i<=b;i++)
{
n=i;
while(n!=0)
{
c=n%10;
sum=sum+c;
n=n/10;
}
if((sum%3==0)&&((sum/3)%2==0))
{
System.out.println(i + " ");
count++;
}
sum=0;
}
if(count==0)
{
System.out.println("Eligible tickets are not available from "+a+" to "+b);
System.exit(0);
}
}
}

*********************************************************************************************
******************************************************************************
13.COFFEE STALL NUMEROLOGY

INPUT : Enter the Staff Name


Coffee Bar

OUTPUT : Coffee Bar satisfies the numerology logic

import java.util.*;
public class Main{
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the Staff Name");
String name = sc.nextLine();
int count=0;
for(int i=0;i<name.length();i++){
if(Character.isAlphabetic(name.charAt(i)) || name.charAt(i)==' '){
count++;
}
}
if(count==name.length()){
String str = name.replace(" ","");
int sum=0;
for(int i=0;i<str.length();i++){
sum += i;
}
if(sum%2==0){
System.out.println(name+" satisfies the numerology logic");
}else{
System.out.println(name+" does not satisfy the numerology logic");
}
}else{
System.out.println("Invalid Input");
}
}
}

*ALTERNATE METHOD USING -matches for same question

import java.util.*;
public class Main{
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the Staff Name");
String name = sc.nextLine();
if(name.matches("[a-zA-Z ]+")){
String str = name.replace(" ","");
int sum=0;
for(int i=0;i<str.length();i++){
sum += i;
}
if(sum%2==0){
System.out.println(name+" satisfies the numerology logic");
}else{
System.out.println(name+" does not satisfy the numerology logic");
}
}else{
System.out.println("Invalid Input");
}
}
}

*ALTERNATE METHOD

import java.util.Scanner;
public class CoffeeHouse {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the Stall Name");
String name = sc.nextLine();
if (name.matches("^[A-Za-z ]*$")) {
int sum = 0;
String fName = name.replaceAll(" ", "");
for (int i = 0; i < fName.length(); i++)
sum = sum + i;
if (sum % 2 == 0) {
System.out.println(name + " satisfies the numerology logic");
} else {
System.out.println(name + " not satisfies the numerology logic");
}
} else
System.out.println("Invalid Input");
}
}

*********************************************************************************************
******************************************************************************

14.ANAGRAM OR TWO WORDS OF SAME LETTER

INPUT : cat
act

OUTPUT: Same

import java.util.Arrays;
import java.util.Scanner;
public class minmax {
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter sentence 1");
String s1=sc.next();
s1=s1.toLowerCase();
System.out.println("Enter sentence 2");
String s2=sc.next();
s2=s2.toLowerCase();
if(s1.length()!=s2.length())
{
System.out.println("Invalid");
}
if(s1.matches("^[a-zA-Z]*")){
char c1[] = s1.toLowerCase().toCharArray();
char c2[] = s2.toLowerCase().toCharArray();
Arrays.sort(c1);
Arrays.sort(c2);
if (Arrays.equals(c1, c2)) {
System.out.println(s1 + " and " + s2 + " contain the same characters");
} else {
System.out.println(s1 + " and " + s2 + " contain the different characters");
}
}
else
{
System.out.println("Invalid");
}
}
}

ALTERNATE METHOD:

import java.util.*;
public class Main{
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
String first=sc.next();
String secound=sc.next();
String word1=Main.checker(first);
String word2=Main.checker(secound);
if(word1.equals(word2)){
System.out.println("Same");
}else{
System.out.println("Different");
}
}
public static String checker(String word){
char arr[]=word.toCharArray();
Arrays.sort(arr);
int index=0;
for(int i=0;i<arr.length;i++){
int j;
for(j=0;j<i;j++){
if(arr[j]==arr[i]){
break;
}
}
if(i==j){
arr[index++]=arr[i];
}
}
char arr1[]=Arrays.copyOf(arr,index);
String newword= new String(arr1);
return newword;
}
}

ALTERNATE METHOD

import java.util.*;
public class arraysquare {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int f1=0,f2=0;
String s1=sc.nextLine();
char c1[]=s1.toCharArray();
String s2=sc.nextLine();
char c2[]=s2.toCharArray();
for(int i=0;i<c1.length;i++)
{
f1=0;
for(int j=0;j<c2.length;j++)
{
if(c1[i]==c2[j])
{
f1=1;
break;
}
}
if(f1==0)
{
break;
}
}
for(int i=0;i<c2.length;i++)
{
f2=0;
for(int j=0;j<c1.length;j++)
{
if(c2[i]==c1[j])
{
f2=1;
break;
}
}
if(f2==0)
{
break;
}
}
if(f1==1 && f2==1)
{
System.out.println("Same Char");
}
else{
System.out.println("Different char");
}
}
}

*********************************************************************************************
*****************************************************************************
15.SUMMATION OF EVEN NUMBERS IN THE ARRAY

INPUT : Enter array size


4
Enter array elements in 1st array
2
4
6
8
Enter array elements in 2nd array
1
2
5
2

OTPUT: 0
6
0
10

import java.util.*;
public class Main
{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter array size");
int n=sc.nextInt();
if(n>=10 || n<1)
{
System.out.println(n+" is an invalid input");
Runtime.getRuntime().halt(0);
}
int arr1[]=new int[n];
int arr2[]=new int[n];
int result[]=new int[n];
System.out.println("Enter array elements in 1st array");
for(int i=0;i<n;i++)
{
arr1[i]=sc.nextInt();
}
System.out.println("Enter array elements in 2nd array");
for(int i=0;i<n;i++)
{
arr2[i]=sc.nextInt();
}
//PROGRAM LOGIC
int count=0;
for(int i=0;i<n;i++)
{
if((arr1[i]%2==0 || arr1[i]==0) && (arr2[i]%2==0 || arr2[i]==0))
{
result[i]=arr1[i]+arr2[i];
count++;
}
else
{
result[i]=0;
}
}
if(count==0)
{
System.out.println("No even number is present in an Array");
}
for(int i=0;i<n;i++)
{
System.out.println(result[i]);
}
}
}

*********************************************************************************************
******************************************************************************
16.RUNNERS COMPETITION

INPUT :Enter the number of runners


5

Enter the runner details


Robert,9.38
Richard,9.35
Christiano,9.35
Williams,9.36
Vinix,9.35

OUTPUT: Richard
Christiano
Vinix

import java.util.*;
public class Main{
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
sc.useDelimiter("\n");
System.out.println("Enter the number of runners");
int n = sc.nextInt();
if(n<=0 || n>10){
System.out.println(n+" is an invalid number of runners");
Runtime.getRuntime().halt(0);
}
String temp = "";
String name[] = new String[n];
float time[] = new float[n];
System.out.println("Enter the runner details");
for(int i=0;i<n;i++){
temp = sc.next();
String temparr[] = temp.split(",");
name[i] = temparr[0];
time[i] = Float.parseFloat(temparr[1]);
if(time[i]>12 || time[i]<8){
System.out.println(time[i]+" is an invalid input");
Runtime.getRuntime().halt(0);
}
}
int maxcount = 0;
float maxrep = 0;
for(int i=0;i<n;i++){
int count = 0;
for(int j=i+1;j<n;j++){
if(time[i]==time[j]){
count++;
}
}
if(count>=maxcount){
maxcount = count;
maxrep = time[i];
}
}
if(maxcount==n){
System.out.println(n+" runners have same timing");
}
else if(maxcount==0){
System.out.println("No runners with same time.");
}
else{
for(int i=0;i<n;i++){
if(maxrep == time[i]){
System.out.println(name[i]);
}
}
}
}
}
*********************************************************************************************
******************************************************************************

17.REEDME

INPUT : Enter the customer name


Abi
Enter the category
History
Enter the quantity of books ordered
2900

OUTPUT : Total cost is 334080.0


import java.util.*;
public class Main{
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the customer name");
String name = sc.nextLine();
System.out.println("Enter the category");
String category = sc.nextLine();
category = category.toLowerCase();

if(!category.equals("adventure") && !category.equals("comics") && !category.equals("history") && !categ


ory.equals("thriller")){
System.out.println(category+" is invalid category");
Runtime.getRuntime().halt(0);
}
System.out.println("Enter the quantity of books ordered");
int quantity = sc.nextInt();
if(quantity <= 0){
System.out.println(quantity+" is an invalid quantity");
Runtime.getRuntime().halt(0);
}
int discount = 0;
int price = 0;
if(category.equals("adventure")){
price = 150;
if(quantity>=1700)
discount = 5;
}
else if(category.equals("comics")){
price = 230;
if(quantity>=1950)
discount = 5;
}
else if(category.equals("history")){
price = 120;
if(quantity>=2600)
discount = 4;
}
else if(category.equals("thriller") && quantity>=1700){
price = 190;
if(quantity>=6300)
discount = 3;
}
float totalcost = (price*quantity) - (price*quantity*discount/100);
System.out.println("Total cost is "+totalcost);
}
}

*********************************************************************************************
******************************************************************************
18)HARSHAD NUMBER (Sum of digit completely divide that

number) For example: 18= 1+8=9 and in 18/9 remainder is 0


INPUT: Enter array size: 5
Enter array elements : 18 14 12 24 13

OUTPUT: 18 12 24

import java.util.Scanner;
public class Harshad {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the number of values");
int n = sc.nextInt();
int i;
System.out.println("Enter the numbers");
int[] a = new int[n];
if (n > 0)
{
int flag = 0;
int k = 0;
for (i = 0; i < n; i++)
{
k = sc.nextInt();
if (k > 9)
a[i] = k;
else
{
flag = 1;
break;
}
}
if (flag != 1)
{
int c = 0;
for (i = 0; i < n; i++)
{
int x = a[i];
int sum = 0;
do {
int r = x % 10;
sum = sum + r;
x = x / 10;
}
while (x != 0);
if (a[i] % sum == 0)
{
c++;
System.out.println(a[i]);
}
}
if (c == 0)
System.out.println("The " + n + " values are not harshad number");
}
else
System.out.println("Provided " + k + " is not valid");
} else
System.out.println(n + " is an invalid input");
}
}

ALTERNATE METHOD:

import java.util.Scanner;
class Main
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number of values");
int n=sc.nextInt();
System.out.println("Enter the numbers");
int a[]=new int[n];
if(n>0)
{
int flag=0;
int k=0;
for(int i=0;i<n;i++)
{
k=sc.nextInt();
if(k>9) a[i]=k; else
{
flag=1;
break;
}
}
if(flag!=1)
{
int c=0;
for(int i=0;i<n;i++)
{
int x=a[i];
int sum=0;
do
{
int r=x%10; sum=sum+r; x=x/10;
}while(x!=0);
if(a[i]%sum==0)
{ c++;
System.out.println(a[i]);
}
}
if(c==0)
System.out.println("The "+n+" values are not harshad number");
}else
System.out.println("Provided "+k+" is not valid");
}else
System.out.println(n+" is an invalid input");
}
}
*********************************************************************************************
*********************************************************************************************
*******
19) VIDEO GAME PLAYER (PS1)

INPUT : Enter the amount


18000
Enter the Video Game Player Type
PS4

OUTPUT: You can buy PS4

public class PS {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the amount");
int amount = sc.nextInt();
if (amount >= 3000) {
System.out.println("Enter the Video Game Player Type");
String type = sc.next();
if (type.matches("[P][S][1-5]")) {
if (type.equals("PS1")) {
if (amount >= 5000) {
System.out.println("You can buy PS1");
} else {
System.out.println("You need more money to buy a PS1");
}
} else if (type.equals("PS2")) {
if (amount >= 7800) {
System.out.println("You can buy PS2");
} else {
System.out.println("You need more money to buy a PS2");
}
} else if (type.equals("PS3")) {
if (amount >= 9500) {
System.out.println("You can buy PS3");
} else {
System.out.println("You need more money to buy a PS3");
}
} else if (type.equals("PS4")) {
if (amount >= 12000) {
System.out.println("You can buy PS4");
} else {
System.out.println("You need more money to buy a PS4");
}
} else if (type.equals("PS5")) {
if (amount >= 15000) {
System.out.println("You can buy PS5");
} else {
System.out.println("You need more money to buy a PS5");
}
}
} else {
System.out.println(type + " is Invalid Type");
}
} else {
System.out.println(amount + " is too less");
}
}
}

*********************************************************************************************
*********************************************************************************************
****
20) ALTERNATE SUM DIFFERENCE

INPUT :Enter number


6
Enter values
12
13
6
8
9
7
(((( logic: (12-7=a
13-9=b
6-8=c
a+b+c=ans)))))

OUTPUT 2
3
4
5
5-2=3
4-3=1
So 3+1= 4
*/

import java.util.*;
public class AltDiff {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int sum=0;
int n=sc.nextInt();
int a[]=new int[n];
for(int i=0;i<n;i++)
{
a[i]=sc.nextInt();
}
for(int i=0;i<n/2;i++)
{
sum+=Math.abs(a[i]-a[n-i-1]);
}
System.out.println(sum);
}
}
*********************************************************************************************
*********************************************************************************************
*****
21.CHARACTER
ADD

INPUT : Enter : 3
Enter the sentences:
ks436
Agh73
7222

OUTPUT: 222
240
0

import java.util.*;
public class arraysquare{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int sum=0;
System.out.println("Enter:");
int n=sc.nextInt();
if(n<=0)
{
System.out.println("The number of sentences "+n+" is invalid");
return;
}
System.out.println("Enter the sentences:");
String str[]=new String[n];
for(int i=0;i<n;i++)
{
str[i]=sc.next();
}
for(int i=0;i<str.length;i++)
{
String s=str[i].replaceAll("[0-9]","");
for(int j=0;j<s.length();j++)
{
char c=s.charAt(j);
int ascii=c;
sum+=ascii;
}
System.out.println(sum);
sum=0;
}

}
}

*********************************************************************************************
******************************************************************************************
22.MIDDLE LETTER/Reverse first half of the string if string length is ODD

Input:
if length of string is even, the reverse the string:
Ex: Food
Output:
dooF

Input:
If length of the string is odd,then find the middle char and then ,reverse the string till mid char and print remain char
acters as it is.
Ex: Samsung
Output:
maSsung

package FinalAss;
import java.util.*;
public class MidLett {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
String str=sc.nextLine();//rahul
int len=str.length();
if(len%2==0)
{
StringBuilder sb=new StringBuilder(str);
sb.reverse();
System.out.println(sb.toString());
}
else if(len%2!=0)
{
System.out.println("Length of string is " +len);
int mid=len/2;
mid++;
System.out.println("Substring of string is "+mid);
String substr=str.substring(0,mid-1);
String remainSub=str.substring(mid-1,len);
StringBuilder sb=new StringBuilder(substr);
sb.reverse();
System.out.println(sb.toString()+remainSub);

}
}
}

ALTERNATE METHOD:::

import java.util.Scanner;
import java.util.regex.Pattern;
public class minmax {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
String str=sc.nextLine();//rahul
if(!Pattern.matches("[A-Za-z]+",str))
{
System.out.println(str+" is not a valid string");
return;
}
else if(str.length()<2)
{
System.out.println("Size of string "+str.length()+" is too small");
return;
}
int len=str.length();
if(len%2==0)
{
StringBuilder sb=new StringBuilder(str);
sb.reverse();
System.out.println(sb.toString());
}
else if(len%2!=0)
{
int mid=len/2;
String substr=str.substring(0,mid);
String remainSub=str.substring(mid,len);
StringBuilder sb=new StringBuilder(substr);
sb.reverse();
System.out.println(sb.toString()+remainSub);

}
}
}

*********************************************************************************************
*********************************************************************************************
*****

23 .ONLINE SHOPPING

input:
enter the product
laptop
Actual price
45000
exchange?
yes
bill amount:
27000.00

import java.util.*;
public class arraysquare {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the Product:");
String prod=sc.nextLine();
int ed=0,pd=0;
if(prod.equals("Mobile"))
{
ed=15;
pd=15;
}
else if(prod.equals("Laptop"))
{
ed=20;
pd=20;
}
else if(prod.equals("Headset"))
{
ed=0;
pd=10;
}
else if(prod.equals("Charger"))
{
ed=0;
pd=5;
}
else{
System.out.println("Not available");
return;
}
System.out.println("Enter the actual Price: ");
int price=sc.nextInt();
if(price<100)
{
System.out.println("Invalid Price");
return;
}
System.out.println("Do u want to Exchange?");
String exc=sc.next();
if(exc.equals("Yes") || exc.equals("yes"))
{
double ap=price-(price*pd)/100;
double ev=(price*ed)/100;
double total=ap-ev;
System.out.printf("Total=%.2f",total);
}
else if(exc.equals("No") || exc.equals("no"))
{
double total=price-(price*pd)/100;
System.out.printf("Total=%.2f",total);
}
else
{
System.out.println("Invalid Option");
}
}
}

*********************************************************************************************
********************************************************************************************
24 .OPERATOR FOUND

input:
45
23

22
output
45-23=22

import java.util.*;
public class arraysquare {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter n1 and n2:");
int n1=sc.nextInt();
if(n1>0)
{
int n2=sc.nextInt();
if(n2>0)
{
System.out.println("Enter n3:");
int n3=sc.nextInt();
if(n3>0)
{
if(n1+n2==n3)
{
System.out.println(n1+"+"+n2+"="+n3);
}
else if(n1-n2==n3)
{
System.out.println(n1+"-"+n2+"="+n3);
}
else if(n1*n2==n3)
{
System.out.println(n1+"*"+n2+"="+n3);
}
else if(n1/n2==n3)
{
System.out.println(n1+"/"+n2+"="+n3);
}
else
{
System.out.println(n3+" is an invalid answer");
}
}
else{
System.out.println("Invalid");
}
}
else{
System.out.println("Invalid");
}
}
else{
System.out.println("Invalid");
}

}
}

*********************************************************************************************
*********************************************************************************************
****

25 .PRODUCT EQUAL SUM

INPUT : Enter the array size


4
Enter the elements of the first array
12
35
56
34
Enter the elements of the second array
261
195
112
813
OUTPUT: 35,195
34,813

import java.util.*;
public class arraysquare
{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the array size");
int n=sc.nextInt();
if(n<=0)
{
System.out.println("Invalid array size");
return;
}
int a[]=new int[n];
System.out.println("Enter the elements of the first array");
for(int i=0;i<n;i++)
{
a[i]=sc.nextInt();
}
System.out.println("Enter the elements of the second array");
int b[]=new int[n];
for(int i=0;i<n;i++)
{
b[i]=sc.nextInt();
}
int x[]=new int[n];
int y[]=new int[n];
for(int i=0;i<n;i++)
{
int c=a[i];
int prod=1;
while(c!=0)
{
prod*=(c%10);
c/=10;
}
x[i]=prod;
prod=0;
}
for(int i=0;i<n;i++)
{
int s=b[i];
int sum=0;
while(s!=0)
{
sum+=(s%10);
s/=10;
}
y[i]=sum;
sum=0;
}
for(int i=0;i<n;i++)
{
if(x[i]==y[i])
{
System.out.println(a[i]+","+b[i]);
}
}
}
}

*********************************************************************************************
*********************************************************************************************
*

26. UNIQUE CHAR

input:
LIfe is inherently risky

output:
life is ihrtly risky

package FinalAss;
import java.util.*;
public class nonuniquetwo {
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
String sentence = sc.nextLine();
String[] words = sentence.split(" ");
for(String word : words)
{
System.out.print(getUnique(word) + " ");
}
sc.close();
}
public static String getUnique(String str)
{
StringBuffer sb = new StringBuffer();
for(int i = 0; i<str.length(); i++)
{
if(countFrequency(str.charAt(i), str) == 1)
{
sb.append(str.charAt(i));
}
}
String result = sb.toString();
return result;
}
public static int countFrequency(char c, String str)
{
int count = 0 ;
for(int i = 0; i<str.length(); i++)
{
if(str.charAt(i) == c)
{
count++;
}
}
return count;
}
}

*********************************************************************************************
*********************************************************************************************
*
27. BOX SIZE

INPUT : Enter the box size


6
Enter the numbers
5
55
3
59
42
8
OUTPUT: 32 is even its a valid box

import java.util.Scanner;
public class minmax {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the box size");
int a=sc.nextInt();
if(a<=0)
{
System.out.println(a+" is an invalid box size");
return;
}
int b[]=new int[a];
int c=0,sum=0,temp=0;
System.out.println("Enter the numbers");
for(int i=0;i<a;i++)
{
b[i]=sc.nextInt();
if(b[i]<=0)
{
System.out.println(b[i]+" is an invalid input");
return;
}
}
for(int i=0;i<a;i++)
{
c=b[i]%10;
sum+=c;
c=0;
}
if(sum%2==0)
{
System.out.println(sum+" is even its a valid box");
return;
}
else
{
System.out.println(sum+" is odd its an invalid box");
return;
}

}
}
****ALTERNATE METHOD***********

Box consists of n numbers and n>0


Enter the numbers and numbers should be greater than 0 and add all the last digits of the numbers.If the sum is
even print valid box else invalid box

Input:
Enter size:5
Enter numbers:
2
34
456
67
123

22 is even it's a valid box

Explanation:
22=(2+4+6+7+3)
Similarly for invalid box also

public class BoxGame {

public static void main(String[] args) {


Scanner sc = new Scanner(System.in);
System.out.println("Enter the box size");
int size = sc.nextInt();
int n=0;
int sum=0;
if(size<=0) {
System.out.println(size+" is an invalid box size");
return;
} else {
System.out.println("Enter the numbers");
int [] arr = new int [size];
for(int i=0;i<size;i++) {
arr[i] = sc.nextInt();
}
for(int i=0;i<size;i++) {
if(arr[i]<=0) {
System.out.println(arr[i]+" is an invalid input");
return;
}
}
for(int i=0;i<size;i++) {
n = arr[i]%10;
sum = sum+n;
}
if(sum%2==0) {
System.out.println(sum+" is even its a valid box");
}else {
System.out.println(sum+" is odd its an invalid box");
}
}

}
*********************************************************************************************
*********************************************************************************************
28. ORDER IDENTIFICATION:(check where elements are in ascending

order) INPUT : Enter the array size : 5


Enter the elements: 32
44
55
66
77

OUTPUT : 32 44 55 66 77 are in ascending order

import java.util.Arrays;
import java.util.Scanner;

public class orderidentification {


public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the array size");
int a=sc.nextInt();
if(a<2 || a>10)
{
System.out.println(a+" is not a valid array size");
return;
}
int b[]=new int[a];
int count=0;
System.out.println("Enter the elements");
for(int i=0;i<a;i++)
{
b[i]=sc.nextInt();
}
int d[]= Arrays.copyOf(b,b.length);
Arrays.sort(d);

if(Arrays.equals(b,d))
{
count++;
}
if(count>0)
{
for(int i=0;i<b.length;i++)
{
System.out.print(b[i]+" ");

}
System.out.print("are in ascending order");
return;
}
else
{
for(int i=0;i<a;i++)
{
System.out.print(b[i]+" ");
}
System.out.print("are not in ascending order");
return;
}
}
***ALTERNATE METHOD***

public class ascendingDesceding {


public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter array size: ");
int n = sc.nextInt();
int[] arr = new int[n];
int[] temp = new int[n];
if (n < 2 || n > 10) {
System.out.println("Invalid size");
return;
}
for (int i = 0; i < n; i++) {
arr[i] = sc.nextInt();
temp[i]=arr[i]; //store the array elements in temp array for comaparison later
}
Arrays.sort(arr); //sort the original array
int count=0;
for(int i=0;i<n;i++) {
if(arr[i]==temp[i]){ //checking if elements of sorted array is equal to
temp array
count++;
} else {
count=0;
break;
}}
if(count!=0) {
System.out.println("All elements are in ascending order");
} else {
System.out.println("Elements are not in ascending order");
}}}

********************************************************************************************
********************************************************************************************
********************************
29) DATE ,MONTH AND

YEAR INPUT:13081995

OUTPUT: date: 13
month: 08
year: 1998

import java.util.Scanner;
public class minmax {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
String str=sc.nextLine();
int n=str.length();
for(int i=0;i<str.length() ;i++)
{
if(!(str.charAt(i)>='0' && str.charAt(i)<='9'))
{
System.out.println("Invalid input");
return;
}
if(n!=8)
{
System.out.println("Enter valid date");
return;
}
}
String date=str.substring(0,2);
String mon=str.substring(2,4);
String year=str.substring(4,8);

System.out.println("date:"+date);
System.out.println("Month:"+mon);
System.out.print("Year:"+year);

}
}

*********************************************************************************************
*********************************************************************************************
*
30) MEGA MART CUSTOMER IDENTIFICATION(String and SUBSTRING)

import java.util.*;
public class arraysquare{
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the customer id");
String cid = sc.next();
String shop = cid.substring(0,4);
//System.out.println("shop");
if(!shop.equals("Mega")){
System.out.println("Invalid Shop Name");
Runtime.getRuntime().halt(0);
}
String type = cid.substring(4,cid.length()-3);
//System.out.println(type);
if(!type.equals("Silver") && !type.equals("Gold") && !type.equals("Platinum")){
System.out.println("Invalid Customer Type");
Runtime.getRuntime().halt(0);
}
int mid = Integer.parseInt(cid.substring(cid.length()-3,cid.length()));
//System.out.println(mid);
if(mid<=99 || mid>=1000){
System.out.println("Invalid Member id");
Runtime.getRuntime().halt(0);
}
System.out.println("Welcome Mega Mart "+type+" Customer");

}
}

*********************************************************************************************
***********************************
31) MALE AND FEMALE COUNT

INPUT: MmFMff
OUTPUT: 3 MALE
3 FEMALE

import java.util.Scanner;
import java.util.regex.*;
public class minmax {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
String s=sc.nextLine();
int count1=0;
int count2=0;
if(Pattern.matches("[MmFf ]+",s)){
for (int i = 0; i < s.length(); i++) {
if (s.charAt(i) == 'M' || s.charAt(i) == 'm') {
count1++;
} else if (s.charAt(i) == 'F' || s.charAt(i) == 'f') {
count2++;
}
}
System.out.println(count1 + " Male");
System.out.println(count2 + " Female");
}
else
{
System.out.println("Invalid Input");
}
}
}
*********************************************************************************************
*********************************************************************************************
***
32) RAINFALL

INPUT: Enter the length of the roof in meters: 4


Enter the breadth of the roof in meters: 3
Enter the rainfall level: 3

OUTPUT: 360.00 Litres

import java.util.Scanner;
public class minmax {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
System.out.println("Enter the length of the roof in meters");
double l=sc.nextDouble();
if(l<=0)
{
System.out.println("Invalid Length");
return;
}
System.out.println("Enter the breadth of the roof in meters");
double b=sc.nextDouble();
if(b<=0)
{
System.out.println("Invalid breadth");
return;
}
System.out.println("Enter the rainfall level");
double r=sc.nextDouble();
if(r<=0)
{
System.out.println("Invalid rainfall");
return;
}
double h;
h=(l*b) *(r*10);
System.out.println(String.format("%.2f",h)+"Litres");
}
}

*********************************************************************************************
*********
33) NUMEROLOGY NAME CHECKING

import java.util.*;
import java.util.regex.Pattern;

public class arraysquare{


public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the name");
String a=sc.next();
if(!Pattern.matches("[A-Za-z]+",a))
{
System.out.println(a+" is an Invalid name");
return;
}
int sum=0;
char b[]=a.toCharArray();
for(int i=0;i<b.length;i++)
{
if(b[i]=='A'||b[i]=='a')
{
sum+=1;
}
else if(b[i]=='B'||b[i]=='b')
{
sum+=2;
}
else if(b[i]=='C'||b[i]=='c')
{
sum+=3;
}
else if(b[i]=='D'||b[i]=='d')
{
sum+=4;
}
else if(b[i]=='E'||b[i]=='e')
{
sum+=5;
}
else if(b[i]=='F'||b[i]=='f')
{
sum+=6;
}
else if(b[i]=='G'||b[i]=='g')
{
sum+=7;
}
else if(b[i]=='H'||b[i]=='h')
{
sum+=8;
}
else if(b[i]=='I'||b[i]=='i')
{
sum+=9;
}
else if(b[i]=='J'||b[i]=='j')
{
sum+=10;
}
else if(b[i]=='K'||b[i]=='k')
{
sum+=11;
}
else if(b[i]=='L'||b[i]=='l')
{
sum+=12;
}
else if(b[i]=='M'||b[i]=='m')
{
sum+=13;
}
if(b[i]=='N'||b[i]=='n')
{
sum+=14;
}
if(b[i]=='O'||b[i]=='o')
{
sum+=15;
}
if(b[i]=='P'||b[i]=='p')
{
sum+=16;
}
if(b[i]=='Q'||b[i]=='q')
{
sum+=17;
}
if(b[i]=='R'||b[i]=='r')
{
sum+=18;
}
if(b[i]=='S'||b[i]=='s')
{
sum+=19;
}
if(b[i]=='T'||b[i]=='t')
{
sum+=20;
}
if(b[i]=='U'||b[i]=='u')
{
sum+=21;
}
if(b[i]=='V'||b[i]=='v')
{
sum+=22;
}
if(b[i]=='W'||b[i]=='w')
{
sum+=23;
}
if(b[i]=='X'||b[i]=='x')
{
sum+=24;
}
if(b[i]=='Y'||b[i]=='y')
{
sum+=25;
}
if(b[i]=='Z'||b[i]=='z')
{
sum+=26;
}
}
System.out.println(sum);
if(sum%3==0 && sum%2==0)
{
System.out.println(a+" is a numerology name");
}
else
{
System.out.println(a+" is not a numerology name");
}
}
}

*******************************************************************************

34)OMR

import java.util.Scanner;
public class arraysquare{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int i;
System.out.println("Enter the No of questions");
int a=sc.nextInt();
if(a<0)
{
System.out.println("Invalid Number");
return;
}
int count=0;
int mark=0;
char b[]=new char[a];
System.out.println("Enter the answer key");
for (i=0;i<a;i++) {
b[i] = sc.next().charAt(0);

if ((b[i] >= 'a' && b[i] <= 'e')||(b[i] > 'E')) {


System.out.println("Invalid Answers");
return;
}
}
char c[]=new char[a];
System.out.println("Enter the student answers");
for (i=0;i<a;i++)
{
c[i]=sc.next().charAt(0);
if ((c[i] >= 'a' && c[i] <= 'e')||(b[i]>'E')) {
System.out.println("Invalid Answers");
return;
}
}

for(i=0;i<a;i++)
{
if(b[i]==c[i])
{
count++;
}
}
if(count>0)
System.out.println("Correct answers are "+count);
mark=(count*100)/a;
if(count<1)
System.out.println("All answers are wrong");
System.out.println("Mark is "+mark);

}
}

**********************************************************************************************
***************************************************

35)MULTIPLY WITH POSITION

INPUT:
Enter the array size
5

Enter the elements


12
3
7
9
4

Sample Output:
12
6
21
36
20

Logic:
12*1=12
3*2=6
7*3=21
9*4=36
4*5=20
import java.util.*;
public class Main
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the array size:");
int n=sc.nextInt();
int res=0;
if(n<1 || n>10)
{
System.out.println("Invalid Array Size");
return;
}
int a[]=new int[n];
for(int i=0;i<n;i++)
{
a[i]=sc.nextInt();
}

for(int i=0;i<n;i++)
{
res=a[i]*(i+1);
System.out.println(res);
}

}
}

**********************************************************************************************
******************************************************************
36) CAR PARKING

Sample Input:
Enter the car number
ap 37 1498

Sample Output
Park the car in 3rd floor

import java.util.*;

public class CarPrking {


public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the car number");
String num = sc.nextLine();
if (num.length() != 10) {
System.out.println("Invlid State Code");
return;
}
String floor;
String code = num.substring(0, 2);
if (code.equals("TN")) {
floor = "ground";
} else if (code.equals("KA")) {
floor = "1st";
} else if (code.equals("KL")) {
floor = "2st";
} else if (code.equals("AP")) {
floor = "3st";
} else {
System.out.println("Invlid State Code");
return;
}
System.out.println("Park the car in " + floor + " floor");
}
}

ALTERNATE METHOD:
37) DIGIT COUNT

Sample Input:

Enter the number


56164

Enter the digit


6

Sample output
6 appears in 56164 is 2

Explanation:
Digit 6 appears 2 times in the number 56164

package accenture;
import java.util.*;

public class digitcount {

public static void main(String[] args) {


Scanner sc=new Scanner(System.in);
int count=0;
System.out.println("Enter the number:");
int n=sc.nextInt();
String str=String.valueOf(n);
if(n>0)
{
System.out.println("Enter the digit:");
char d=sc.next().charAt(0);
char ch[]=str.toCharArray();
for(int i=0;i<ch.length;i++)
{

if(ch[i]==d)
{
count++;
}
}
if(count>1)
{
System.out.println(d+" appears "+n+" is "+count);
}
}

}
38) WORD FINDING (repeated words)

Sample input:
Enter the number of words
5

Enter the words in set1:


good
bad
hello
Nothing
North

Enter the words in set2:


Bad
world
word
north
hello

package practice;
import java.util.*;
public class RepeatedWords {

public static void main(String[] args) {


// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
System.out.println("Enter the number of words");
int n = sc.nextInt();
if(n<=0){
System.out.println(n+" is less than the desired limit");
return;
}

String set1[] = new String[n];


String set2[] = new String[n];
System.out.println("Enter the words in set1:");
for(int i = 0;i<n;i++){
set1[i] = sc.next().toLowerCase();
}
System.out.println("Enter the words in set2:");
for(int i = 0;i<n;i++){
set2[i] = sc.next().toLowerCase();
}
String res[] = new String[n];
int k = 0;
for(int i = 0;i<n;i++){
int flag = 0;
for(int j = 0;j<n;j++){
if(set1[i].equals(set2[j])){
flag = 1;
break;
}
}
if(flag != 1){
res[k++] = set1[i];
}
}
/*for(int i = 0;i<n;i++){
if(set1[i] == set2[i]){
continue;
}
else{
res[k++] = set1[i];
}
}*/
System.out.println("The uncommon words are:");
for(int i = 0;i<k;i++){
System.out.println(res[i]);
}

}
**********************************************************************************************
******************************************************
39) SUM OF INTEGERS AT EVEN OR ODD PLACES

Enter size: 5
Enter numbers:
123(1+3=4)
2536(5+6=11)
2(2)
57(7)
76542(7+5+2=14)

Output:
38(4+11+2+7+14)

import java.util.*;
public class oddevenindex {
public static void main(String[] args)
{
Scanner sc = new Scanner (System.in);
System.out.println("Enter the size of the array: ");
int n = Integer.parseInt(sc.nextLine());
String[] arr = new String[n];
int[] fin = new int[n];
System.out.println("Enter the elements of the array: ");
for(int i=0;i<n;i++)
{
arr[i] = sc.nextLine();
}
int sum = 0;
int total =0;
if(n%2!=0)
{
for(int i=0;i<arr.length;i++) {
String num = arr[i];
char[] digi = num.toCharArray();
sum = 0;
if (digi.length % 2 == 0) {
for (int j = 1; j < digi.length; j += 2) {
char x = digi[j];
sum = sum + Integer.parseInt(String.valueOf(x));
}
fin[i] = sum;
}
else
{
for (int j = 0; j < digi.length; j += 2) {
char x = digi[j];
sum = sum + Integer.parseInt(String.valueOf(x));
}
fin[i] = sum;

}
}
for(int x: fin)
total +=x;
}
else{
for(int i=0;i<arr.length;i++) {
String num = arr[i];
char[] digi = num.toCharArray();
sum = 0;
if (digi.length % 2 == 0) {
for (int j = 1; j < digi.length; j += 2) {
char x = digi[j];
sum = sum + Integer.parseInt(String.valueOf(x));
}
fin[i] = sum;
}
else
{
for (int j = 0; j < digi.length; j += 2) {
char x = digi[j];
sum = sum + Integer.parseInt(String.valueOf(x));
}
fin[i] = sum;

}
}
for(int x: fin)
total +=x;
}

System.out.println("Output: "+total);

}
}
*****ALTERNATE METHOD*****

package practice;
import java.util.*;
public class SumOfEvenOrOdd {

public static void main(String[] args) {


// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
System.out.println("Enter the size");
int n = sc.nextInt();
if(n<=0){
System.out.println("Invalid size");
return;
}
System.out.println("Enter the elements:");
int sum = 0;
String str[] = new String[n];
for(int i=0;i<n;i++){
str[i] = sc.next();
}
for(int i = 0;i<n;i++){
String s = str[i];
if(s.length()%2 == 0){
for(int j = 1;j<s.length();j+=2){
sum+=Integer.parseInt(s.substring(j,j+1));
}
}else{
for(int j = 0;j<s.length();j+=2){
sum+=Integer.parseInt(s.substring(j,j+1));
}
}
}
System.out.println(sum);
}

}
**********************************************************************************************
**********************************************************************
40) SUM OF EVEN ELEMENTS

Here, size of the array should be taken as input, and it should be between 1 and 10 (inclusive)
If it is not in 1 and 10, print it as "invalid"
Now, by the comparing the values at the same indices of both the arrays, if both values are even, then print the sum
of the two values, otherwise print "0".
Before performing operation, make sure if no even element is present in both the arrays, then print it as "There are no
even elements in both the arrays", otherwise perform the above operation.

For example, see the following inputs and outputs:

1. Sample input:
Enter the size of array: 3
Enter the elements in first array:
2
3
4
Enter the elements in second array:
1
5
8
Sample output:
0
0
12

2. Enter the size of array: 3


Enter the elements in first array:
5
3
1
Enter the elements in second array:
1
5
9
Sample output:
There are no even elements in both the arrays

3.Sample input:
Enter the size of array: 1
Enter the elements in first array:
5
Enter the elements in second array:
1
Sample output:
There are no even elements in both the arrays

package practice;
import java.util.*;
public class SumOfEvenElements {

public static void main(String[] args) {


// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
System.out.println("Enter the size of the array:");
int n = sc.nextInt();
if(n<=0 || n>10){
System.out.println("Invalid");
return;
}
System.out.println("Enter the elements in the first array:");
int arr1[] = new int[n];
for(int i = 0;i<n;i++)
arr1[i] = sc.nextInt();
System.out.println("Enter the elements in the second array:");
int arr2[] = new int[n];
for(int i = 0;i<n;i++)
arr2[i] = sc.nextInt();
int count = 0;
for(int i = 0;i<n;i++){
if(arr1[i]%2 !=0 && arr2[i]%2 != 0){
count++;
}
}
if(count == n){
System.out.println("There are no even elements in both arrays:");
return;
}else{
for(int i = 0;i<n;i++){
if(arr1[i]%2 == 0 && arr2[i]%2 == 0){
System.out.println(arr1[i]+arr2[i]);
}else{
System.out.println("0");
}
}
}
}
}
**********************************************************************************************
*********************************************************************
41) COUNT OF OCCURRENCES OF SUBSTRING IN A STRING

Sample input:
Enter the string
Entertainment

Enter substring
en

Sample output: 2

package accenture;
import java.util.*;
import java.util.regex.*;
public class countofoccurencesofsubstringinastring {

public static void main(String[] args) {


Scanner sc=new Scanner(System.in);
int count=0;
System.out.println("Enter the string:");
String str=sc.next();
if(Pattern.matches("[a-z]+", str))
{
System.out.println("Enter pattern:");
String pat=sc.next();
if(Pattern.matches("[a-z]+", pat))
{
Pattern p=Pattern.compile(pat);
Matcher m=p.matcher(str);
while(m.find())
{
count++;
}
System.out.println("Count is: "+count);
}
else
{
System.out.println("Invalid Pattern");
}
}
else
{
System.out.println("Invalid String");
}

}
**********************************************************************************************
******************************************************************
42) LARGEST SORTED SUBSTRING FROM INPUT STRING

Find longest sorted substring from input string..


Input : abczgdpqrstubg
Output: pqrstu
*/
import java.util.*;
public class Main
{
public static void main (String[] args)
{
Scanner sc=new Scanner(System.in);
String s=sc.next();
int firstindex=0,lastindex=0,length=0;
for(int i=0;i<s.length();i++)
{
int asci=s.charAt(i);
int count=1;
for(int j=i+1;j<s.length();j++)
{
if(s.charAt(j)==++asci)
{
count++;
continue;
}
else
{
if(count>length)
{
firstindex=i;
lastindex=j;
length=count;
break;
}
}
}
}
System.out.println(s.substring(firstindex,lastindex));
}
}
**********************************************************************************************
********************************************************************
43) NON-UNIQUE ELIMINATION

package com.company;

import java.util.Scanner;

public class NonUniqueElimination {


public static void main(String[] args){
Scanner sc=new Scanner(System.in);
String name=sc.nextLine(),abc="";
int count=0;
for(int i=0;i<name.length();i++)
{
for(int j=1;j<name.length()-1;j++)
{
if(name.charAt(i)==name.charAt(j))
{
name=name.replace(String.valueOf(name.charAt(j)),"");
count+=1;
}
}
}
if(count==0) {
System.out.println("All are unique character");
return;
}
else {
System.out.println(name);
}
}
**********************************************************************************************
**********************************************************************************************
**

44) THEATER SEAT DETAILS

Sample input 1:
A2S3D06D13

Sample output 2:
Seat Number
D13
D14
D15
D16
D17

Sample input 2:
A2S3D02C01

Sample Output2:
Seat Number
C1
C2

import java.util.*;
import java.util.regex.Pattern;
public class Main{
public static void main(String args[]){
Scanner sc = new Scanner(System.in);

String str = sc.next();


if(str.length()!=10){
System.out.println("Invalid Input");
return;
}

if(Pattern.matches("[0-9]+",str.substring(5,7)) && Integer.parseInt(str.substring(5,7))>=1


&& Integer.parseInt(str.substring(5,7))<=10){
int seatnumber = Integer.parseInt(str.substring(5,7));
String eightletter = str.substring(7,8);
if(Pattern.matches("[A-Za-z]",eightletter) && Pattern.matches("[0-9]+",str.substring(8,10))){
int n = Integer.parseInt(str.substring(8,10));
for(int i=0;i<seatnumber;i++){
System.out.println(eightletter + (n++));
}
}
else{
System.out.println("Invalid Seat Number");
return;
}
}
else{
System.out.println("Invalid Count");
return;
}
}
}
**********************************************************************************************
***************************************************************************
45) CALCULATE OFFER PRICE (DISCOUNT PRICE)

import java.util.Scanner;

public class DiscountPrice {


public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
String code=sc.nextLine();
int len=code.length();
if(len<6 || len>8)
{
System.out.println("Invalid Input");
return;
}
String mrps=code.substring(4);
int mrp=Integer.parseInt(mrps);
System.out.println("MRP Price :"+mrp);
if(mrp>=1 && mrp<=10)
{
System.out.println("Offer Price: Rs"+mrp);
}
else if(mrp>=11 && mrp<=50)
{
System.out.println("Offer Price: Rs"+(mrp-5));
}
else if(mrp>=51 && mrp<=500)
{
System.out.println("Offer Price: Rs"+(mrp-15));
}
else if(mrp>= 501 && mrp<=5000)
{
System.out.println("Offer Price: Rs"+(mrp-105));
}
else if(mrp>=5001 && mrp<=9999)
{
System.out.println("Offer Price: Rs"+(mrp-1005));
}
}
}
**********************************************************************************************
*******************************************************************************
46) THREE’S

Sample input:
Enter the string
Long live

import java.util.*;
import java.lang.*;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("Enter the String");
String str =in.nextLine();
for(int i=0;i<str.length();i++)
{
if((Character.isLetter(str.charAt(i)) || Character.isWhitespace(str.charAt(i))))
continue;
else{
System.out.println(str+" is not a valid string");
return;
}
}
int sum=0;
for(int i=0;i<str.length();i++){
if((i+1)%3==0){
sum+=(int)str.charAt(i);
}
}
System.out.println("Sum is "+sum);
}
}
JAVA END
*********************************************************************************************
*********************************************************************************************
********

RDBMS IMPORTANT CODES(NOT TESTED)

1.)Select concat(concat(customer_name,'has taken a


policy on'),date_of_policy) as Enrollment_details
from customer JOIN Policy using (customer_id)
order by customer_name,date_of_policy;

2.)select plolicy_id,policy_name,rate_of_interest, bonus_percentage


from policy
where minimum_primeium_amount = 1200
order by policy_d;

3.)select fine_range,fine_amount
CASE
When fine_range=L1
then 5+fine_amount
when fine_range=L2
then 10+fine_amount
When fine_range=M1
then 15+fine_amount
when fine_range=M2
then 20+fine_amount
When fine_range=H1
then 25+fine_amount
when fine_range=H2
then 30+fine_amount
END as NEW_FINE_AMOUNT

4.)select leave_type,allocated_days
CASE
when leave_type='CASUAL'
then allocated_days+2
when leave_type='SICK'
then allocated_days+5
when leave_type='MATERNITY'
then allocated_days+90
when leave_type='MARRIAGE'
then allocated_days+3
when leave_type='STUDY'
then allocated_days-2
END as NEW_ALLOCATED_TYPES
from table_name
order by leave_type;

5.) select emp_id,emp_name,department_id,department_name


from Department JOIN Employee using (department_id)
JOIN Leave+Avail_details using (Emp_id)
JOIN Leave using (Leave_type)
where Allocated_days = 0
order by emp_id;
*********************************************************************************************
**

1.) Account Info - "HDVL002"


select account_type, count(account_id) as TOTAL_ACCOUNTS
from Acount_Info where IFC_Code = 'HDVL002'
group by account_type order by account_type;

2.)select customer_id,customer_name,phone_no,order_date
from Customer_info JOIN Orders using (customer_id)
where order_amount > 500
order by customer_id,order_date;

3.) select distinct customer_id,customer_name,phone_no,loan_amount as


total_loan_amount from customers JOIN loans_taken using
(customer_id)
order by customer_id;

4.) select distinct boat_id,seat_capacity,count(ride_id) as ride_count


From Boat_details JOIN Ride_details using (boat_id)
order by boat_id;

5.) select customer_id,customer_name,contact_no,mail_id


from Coustomer_details where Gender = 'M'
order by customer_id;
6.) select customer_name,total_amount_paid
from Customer_master JOIN Booking_details using (customer_id)
where total_amount_paid < (select max(total_amount_paid) from booking_details
where total_amount_paid < (select max(total_amount_paid) from booking_details))
order by customer_name;

7.) select book_code,book_title, author,rack_num


from book_details where category = 'JAVA'
order by book_code;

8.) select customer_name,policy_enrollment as Enrollment_details


from customer JOIN policy_enrolmment using (customer_id)
order by customer_name,date_of_enrollment;

9.)DECODE QUESTION
select fine_range, fine_amount,
decode(fine_range, 'L1',fine_amount+5,
'L2',fine_amount+10,
'M1',fine_amount+10,
'M2',fine_amount+10,
'H1',fine_amount+10,
'H2',fine_amount+10)new_fine_amount
from fine_details;

10.)select customer_name||" has taken policy on"|| date_of_enrollment as


enrollment_details form customer
join policyenrollent using (customer_id)
order by customr_name,date_of_enrollment;

11.)select policy_id,policy_name,rate_of_interest,bonus_percentage
from policy where mimum_premium_amount = 1200
order by policy_id;

12.) select customer_id,customer_name, street,phone_no,email


from Customers JOIN loan_taken using (customer_id)
where loan_amount > = 500000 and loan_amonunt <1500000
order by customer_id;

13.)select distinct boat_id, boat_name,boat_type


from boat_details JOIN ride_details using (boat_id)
where DOT LIKE '%-AUG-%' and Shift = 'evening'
order by boat_id;

14.) select policy_id,policy_name,rate_of_interest


from policy where miniimum_ppremium_amount < 3000 AND bonus_percent > 85
order by policy_id;

RDBMS ANSWERS

1.1) Write a query to display boat_type and number of boats running under each type. Give an alias name as 'NO_OF
_BOATS'.
Note: Boat_type can be 'DELUXE' or 'SUPER DELUXE'.

select boat_type,count(Boat_id) as NO_OF_BOATS


from boat_details
group by Boat_type;

1.2) select boat_name,boat_type from boat_details


where seat_capacity between 100 and 200
order by boat_name desc;

2.1) select vehicle_type,count(vehicle_id)


from vehicle_details
group by vehicle_type
order by vehicle_type;

2.2) select driver_id,driver_name,phone_no,Driver_rating


from driver_details where driver_rating between 3 and 5
order by driver_rating desc;

3.1) select coursename from course


c join registration r on
c.courseid=r.courseid
having count(studid)>=2
group by coursename
order by coursename;

3.2) select s.studid,sum(fees) as TOTALFEES


from student s join registration r
on s.studid=r.studid join course c
on r.courseid=c.courseid
group by s.studid
order by s.studid;

3.3) select studid,count(CourseID) as NOOFCOURSES


from registration
group by Studid
order by NOOFCOURSES desc,Studid;

3.4) select student.stuid,firstname from student


join registration on registration.stuid=student.stuid
where lower(to_char(doj,'MON'))='jan';

3.5) select courseid,coursename from


course where duration between 10 and 15;

3.6) select courseid,registration.stuid from registration


join student on registration.stuid=student.stuid
where lower(to_char(doj,'MON'))=lower(to_char(dob,'MON'));
1

1. Gender determination ……………………………………….. 2


2. LCM lunch/dinner together …………………………………2-3
3. Product equals sum ………………………………………………3-5
4. Count of occurences of substring in a given string… ..5-6
5. Fun count……………………………………………………………….. 6
6. Speed Estimation…………………………………………………… 7
7. Prime number………………………………………………………. 7-8
8. Theatre seat ………………………………………………………… 8-9
9. Customer details …………………………………………………. 10-11
10. Team win/loose ………………………………………………… 11
11. Holiday fun ……………………………………………………….. 11-12
12. Reverse-prime …………………………………………………… 12-13
13. Even number addition in arrays…………………………. 14
14. Groceries bill …………………………………………………….. 15
15. Cake order …………………………………………………………. 16-17
2

Gender Determination :

import java.util.*;
public class Main {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
String s=sc.next();
int count=0,count1=0;
if(!(s.matches("[mfMF]+")))
{
System.out.println("Invalid Input");
return;
}
else
for(int i=0;i<s.length();i++)
{
if(s.charAt(i)=='m' ||s.charAt(i)=='M')
count++;
else
count1++;
}
System.out.println(count+" "+"Male");
System.out.println(count1+" "+"Female");
}}
LCM OF DAY INTERVAL/LUNCH/DINNER TOGETHER :

import java.util.*;
public class Main {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
System.out.println("Enter the day interval of person 1:");
int a=sc.nextInt();
System.out.println("Enter the day interval of person 2:");
int b=sc.nextInt();
if(a<=0 || b<=0)
{
System.out.println("Given interval is not valid");
return;
3

}
int lcm;
lcm=(a>b)?a:b;
while(true){
if(lcm%a==0 && lcm%b==0){
System.out.println("person 1 and person 2 will have
their dinner on day "+lcm);
break;
}
lcm++;
}
}}

PRODUCT EQUALS SUM

import java.util.*;

public class Main{

public static void main(String args[]){

Scanner sc=new Scanner(System.in);

System.out.println("Enter the array size:");

int n=sc.nextInt();

int count=0;

if(n<1 || n>10){

System.out.print("Invalid array size");

System.exit(0);

else{

int[] a1=new int[n];

int[] a2=new int[n];

System.out.println("Enter the elements of the first array");


4

for(int i=0;i<n;i++){

int b=sc.nextInt();

if(b>10 && b<999)

a1[i]=b;

else{

System.out.print("Invalid input");

System.exit(0);

}}

System.out.println("Enter the elements of the second


array");

for(int i=0;i<n;i++){

int c=sc.nextInt();

if(c>10 && c<999)

a2[i]=c;

else{

System.out.print("Invalid input");

System.exit(0);

}}

for(int i=0;i<n;i++){

int mul=1,r=0,x=a1[i];

while(x>0){

r=x%10;

mul*=r;
5

x=x/10;

for(int j=0;j<n;j++){

int sum=0,p=0,y=a2[j];

while(y>0){

p=y%10;

sum+=p;

y=y/10;

if(mul==sum){

count++;

System.out.print(a1[i]+","+a2[j]);

System.out.println(" ");

}}}

if(count==0){

System.out.print("No pair found");

System.exit(0);

}}}}

Count of Occurrences of Substring in a String

import java.util.*;
public class Main {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
String s1=sc.next();
String s2=sc.next();
int index=0;
6

int count=0;
while((index=s1.indexOf(s2,index))!=-1){
index=index+1;
count+=1;
}
System.out.println(count);
}
}

Fun Count

import java.util.*;
public class Main {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
if(n<=0){
System.out.println("Invalid Input");
return;
}
if(n>15){
System.out.println("Number exceeds the limit");
return;
}
Map<String,Integer> a=new HashMap<>();
for(int i=0;i<n;i++){
String s=sc.next().toLowerCase();
if(a.containsKey(s))
a.put(s,1+a.get(s));
else
a.put(s,1);
}
Map<String,Integer> tm=new TreeMap<>(a);
for(Map.Entry<String,Integer>data:tm.entrySet()){
System.out.println(data.getKey()+"= "+data.getValue());
}
}
}
7

SPEED ESTIMATION :
import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
System.out.println("Enter the distance in kilometer");
int km=sc.nextInt();
if(km<0) {
System.out.println("Invalid Input");
return;
}
System.out.println("Enter the time to reach in hours");
int hours=sc.nextInt();
if(hours<0){
System.out.println("Invalid Input");
return;
}
int speed=km/hours;
if(speed<30){
System.out.println("You drive a car at normal speed");
return;
}
int inc=speed-30;
System.out.println("You want to increase a speed "+inc+"
km/hr from a normal speed");
}}

Prime Number

import java.util.Scanner;

public class Main{

public static void main(String[] args){

Scanner sc=new Scanner(System.in);

int a = sc.nextInt();

int b = sc.nextInt();

int count=0;
8

if(a<0 || b<0){

System.out.println("Negative integers cannot be prime");

return;

for(int i=a;i<=b;i++){

count = 0;

for(int j=2;j<=i;j++){

if(i % j == 0)

count = count+1;

if(count == 1)

System.out.print(i+" ");

if(count!=1)

System.out.println("There are no prime numbers in the range


"+a+" to "+b);

Theatre

import java.util.*;
public class Main {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
String s=sc.next();
if(s.length()==6)
{
9

String a=s.substring(0,1);
if(a.matches("[NEWS]+"))
{
String b=s.substring(1,2);
if(b.matches("[ABCDE]+"))
{
String c=s.substring(2,3);
if(c.matches("[1-4]+"))
{
String d=s.substring(3,6);
int num=Integer.parseInt(d);
if(num>0 && num<500)
{
System.out.println("Name "+a);
System.out.println("Block "+b);
System.out.println("Floor number "+c);
System.out.println("Seat number
"+num);
}
else
System.out.println("Invalid Seat number");
}
else
System.out.println("Invalid Floor number");
}
else
System.out.println("Invalid Block");
}
else
System.out.println("Invalid Name");
}
else
System.out.println("Invalid size");
}}
10

Customer details

import java.util.Scanner;

public class Main{


public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number of customers:");
int cust=sc.nextInt();
if(cust<0)
{
System.out.println("Invalid Input");
return;
}
if(cust<3)
{
System.out.println("Customer count is too low");
return;
}
if(cust>50)
{
System.out.println("Customer count is too high");
return;
}
System.out.println("Enter the customer details:");
String[] arr=new String[cust];
for (int i=0;i<cust;i++)
{
arr[i]=sc.next();
}
System.out.println("Enter the plan to be searched");
String plan=sc.next();
for (int i=0;i<cust;i++)
{
String[] custdetails=arr[i].split(":");
if(plan.equals(custdetails[1]))
{
System.out.println(custdetails[2]+" "+custdetails[3]);
11

}
}
}
}

Team Win/Loose
import java.util.*;
public class Main {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
String str=sc.next();
int count=0;
if(str.length()<3) {
System.out.println("Invalid input");
return;
}
if(str.matches("[htHT]+")) {
String s=str.toLowerCase();
for(int i=0;i<s.length()-2;i++){
if(s.charAt(i)!=s.charAt(i+1) &&
s.charAt(i)==s.charAt(i+2))
count++;
}
if(count==s.length()-2)
System.out.println("Team will win");
else
System.out.println("Team may loose");
}
else {
System.out.println("Invalid Input");
return;
}
}}

Holiday Fun

import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
12

int sum=0,sum1=0;
int n=sc.nextInt();
if(n>0){
String[] a=new String[n];
for(int i=0;i<n;i++){
a[i]=sc.next();
}
for(int i=0;i<n;i++){
int len=a[i].length();
if(len%2==0)
{
for(int j=1;j<len;j++){

sum=sum+Integer.parseInt(String.valueOf(a[i].charAt(j)));
j++;
}}
else
{
for(int k=0;k<len;k++){

sum1=sum1+Integer.parseInt(String.valueOf(a[i].charAt(k)));
k++;
}}
}
System.out.println(sum+sum1);
}
else
System.out.println("Invalid size");
}}

Reverse Prime

import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
int count=0,c=0,f=0,r=0,prime=0;
int n=sc.nextInt();
if(n>0) {
int[] a=new int[n];
13

for(int i=0;i<n;i++) {
int num=sc.nextInt();
if(num>9)
a[i]=num;
else {
System.out.println("Provided "+num+" is not valid");
return;
}}
for(int i=0;i<n;i++) {
count=0;
for(int j=2;j<a[i];j++)
{
if(a[i]%j==0)
count++;
}
if(count==0) {
prime++;
f=a[i];
r=0;
while(a[i]!=0) {
r=r*10;
r=r+a[i]%10;
a[i] =a[i]/10;
}
for(int k=2;k<r;k++) {
if(r%k==0)
c++;
}
if(c==0)
System.out.println(f);
}}}
else {
System.out.println(n+" is less than a limit");
return;
}
if(prime==0)
System.out.println(n+" values are not prime numbers");
}}
14

Even number addition in arrays

import java.util.*;
public class Main {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
int count=0;
System.out.println("Enter the size of array ");
int n=sc.nextInt();
int[] sum=new int[n];
if(n>=1 && n<=10)
{
int[] a=new int[n];
System.out.println("Enter the elements of the first array ");
for(int i=0;i<n;i++)
a[i]=sc.nextInt();
int[] b=new int[n];
System.out.println("Enter the elements of second array ");
for(int i=0;i<n;i++)
b[i]=sc.nextInt();
for(int i=0;i<n;i++)
{
if(a[i]%2==0 && b[i]%2==0)
{
count++;
sum[i]=a[i]+b[i];
}
else
sum[i]=0;
}
if(count==0)
System.out.println("There are no even elements");
else
for(int result:sum)
System.out.println(result);
}
else
System.out.println("Invalid");
}}
15

Groceries Bill

import java.util.*;
public class Main {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
String s=sc.next();
int a=0,b=0,c=0,d=0,count=0;
if(s.matches("[ORWKorwk]+")) {
for(int i=0;i<s.length();i++) {
for(int j=0;j<s.length();j++) {
if(s.charAt(i)==s.charAt(j))
count++;
}}
if(count==s.length()) {
for(int k=0;k<s.length();k++)
{
if(s.charAt(k)=='O')
a=4*20;
else if(s.charAt(k)=='R')
b=3*5;
else if(s.charAt(k)=='W')
c=2*10;
else
d=5*15;
}
System.out.println(a+b+c+d);
}
else
System.out.println("Duplicates are not allowed");
}
else
System.out.println("Invalid");
}}
16

Cake Order

import java.util.*;

public class CakeProgram {

public static void main(String[] args) {


Scanner sc=new Scanner(System.in);
System.out.println("Enter the Customer instructions: ");
String cd=sc.nextLine();

if (cd.matches("[a-zA-Z0-9]*")) {
String w=cd.substring(0, 4);

if(!w.matches("[0-9]*")){
System.out.println("Invalid weight");
return;
}

float wg=Integer.parseInt(w);
if (wg>999) {
float fwg=wg/1000;
double weight= (Math.round(fwg * 100.0) / 100.0);

String o=cd.substring(cd.length()-3);
if (!o.matches("[0-9]*")) {
System.out.println("Invalid order number");
return;
}
int on=Integer.parseInt(o);
if(on>99) {
String flavour=cd.substring(4,cd.length()-3);

System.out.println("Weight of Cake in Kgs:


"+String.format("%.2f", weight));
System.out.println("Order No: "+on);
System.out.println("Flavour Name: "+flavour);

double cakePrice=450*weight;
17

System.out.printf("Cake Price is: %.2f


Rupees",cakePrice);
}
else {
System.out.println("Invalid order number");
}
}
else {
System.out.println("Invalid weight");
}
}
else {
System.out.println("Invalid Input");
}
}

}
JAVA

1. LCM OF DAY INTERVAL/LUNCH TOGETHER/DINNER TOGETHER

INPUT: Enter the day interval of Tony : 4


Enter the day interval of Potts: 6

OUTPUT: Tony and Potts will have dinner together on 12th day.

import java.util.Scanner;
public class lcm {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the day interval of Sam:");
int n1 = sc.nextInt();
System.out.println("Enter the day interval of Riya:");
int n2 = sc.nextInt();
if(n1<=0 || n2<=0)
{
System.out.println("Given interval is not valid");
return;
}
int lcm;
lcm = (n1 > n2) ? n1 : n2;
while(true) {
if( lcm % n1 == 0 && lcm % n2 == 0 ) {
System.out.printf("Sam and Riya will have their dinner on day "+lcm);
break;
}
++lcm;
}
}
}

ALTERNATE METHOD

import java.util.Scanner;
public class Lunchlcm {
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the day interval of Tony");
int n1=sc.nextInt();
System.out.println("Enter the day interval of Potts");
int n2=sc.nextInt();
if(n1<=0 && n2<=0)
{
System.out.println("Given interval is not valid");
return;
}
int a=n1;
int b=n2;
while(n2>0)
{
if (n1 > n2)
{
n1 = n1 - n2;
} else
{
n2 = n2 - n1;
}
}
int gcd = n1;
int lcm = (a * b) / gcd;

System.out.println("Tony and Potts will have lunch together on " + lcm + " day");
}
}

*********************************************************************************************
*********************************************************************************************
**
2.SCORE OF REPEATING WORDS/ WORD REPETITION

INPUT: Enter the String: GOOD


Enter the sentence: GOOD FOOD GOOD LIFE

OUTPUT: Score is 2

import java.util.*;
class PrintMessage
{
public static void main (String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the string");
String s=sc.next();
int count=0;
int sum=2;
for(int i=0;i<s.length();i++)
{
if(Character.isDigit(s.charAt(i)) || Character.isLetter(s.charAt(i)) || s.charAt(i)==' ')
{
continue;
}
else
{
System.out.println(s+" is not valid String");
return;
}
}
System.out.println("Enter the sentence");
sc.nextLine();
String sentence=sc.nextLine();
String[] w=sentence.split(" ");
for(int i=0;i<w.length;i++)
{
if(w[i].equalsIgnoreCase(s))
{
count++;
if(count>2)
{
sum=sum*2;
}
}
}
if(count>2)
{
System.out.println("Score is "+sum);
}
else
{
System.out.println("Score is"+count);
}
}
}

*ALTERNATE METHOD

import java.util.Scanner;
public class CountWords {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String word, sentence;ed
int count = 0;
System.out.println("Enter a word:");
word = in.nextLine();
System.out.println("Enter a sentence");
sentence = in.nextLine();

if (!(word.matches("[a-z]+"))) {
System.out.println("Invalid Input");
return;
}
String words[] = sentence.toLowerCase().split(" ");
for (int i = 0; i < words.length; i++) {
if (word.equals(words[i])) {
count++;
}
}
System.out.println("Score is:" + ((int) Math.pow(2, count - 1)));
}
}
*********************************************************************************************
*********************************************************************************************
***

3)BATTERY CAPACITY

INPUT: Enter battery capacity :1230


Enter charging current value: 400

OUTPUT: 3.69 Hours

import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter battery capacity:");
double capacity = sc.nextDouble();
if(!(capacity>=1000 && capacity<=10000)) {
System.out.println("Invalid battery capacity");
return;
}
System.out.println("Enter charging current value:");
double current = sc.nextDouble();
if(!(current>=300 && current<=2100)) {
System.out.println("Invalid output current");
return;
}
double time=0.0f;
time = (capacity/current)*1.2;
System.out.println(String.format("%.2f",time)+" Hours");
}

*********************************************************************************************
*********************************************************************************************
***
4) COMBINE NUMBERS / STUDENTS WHOSE ROLLNO ARE ODD

INPUT: Entr the set of students :5


Enter the roll number :1
3
4
5
6

OUTPUT: 135

import java.util.*;
public class Main
{
public static void main(String[] args) {
System.out.println("Enter the set of students");
Scanner s=new Scanner(System.in);
int setn=s.nextInt();
if(setn<=0)
{
System.out.println(setn+" is an invalid size");
return;
}
System.out.println("Enter the roll number");
int[] rolls=new int[setn];
int oddflag=0;
for(int i=0;i<setn;i++)
{
rolls[i]=s.nextInt();
if(rolls[i]<0)
{
System.out.println(rolls[i]+" is an invalid roll number");
return;
}
if(rolls[i]%2!=0)
{
oddflag=1;
}
}
if(oddflag==0)
{
System.out.println("The "+setn+" numbers are not odd");
return;
}
String str="";
for(int i=0;i<setn;i++)
{
if(rolls[i]%2!=0)
{
str=str+rolls[i];
}
}
for(int n=0;n<str.length();n++)
{
System.out.println(str.charAt(n)+" ");
}
}
}
*********************************************************************************************
*********************************************************************************************
**

5) BIKE RENT / CALCULATING BILL AMOUNT

INPUT : Enter your name : Sam


Enter the time duration: 13
List of payment options
1)Visa card
2)Rupay card
3)Master card
Choose an option : 2

OUTPUT: Dear Sam your bill amount is 1294.80

import java.util.*;
public class Main
{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter your name");
String s=sc.nextLine();double sal=0;double disc=0;
for(int i=0;i<s.length();++i)
{
if(!Character.isLetter(s.charAt(i)))
{
System.out.println("Invalid Name");
return;
}
}
System.out.println("Enter the time duration");
int n=sc.nextInt();int n1;
if(n<=0 || n>24)
{
System.out.println("Invalid duration");
return;
}
System.out.println("List of payment options");
System.out.println("1)Visa card");
System.out.println("2)Rupay card");
System.out.println("3)Master card");
System.out.println("Chosse an option");
while(true)
{
n1=sc.nextInt();
if(n1<0||n1>3)
{
System.out.println("Try again");
}
else
{
break;
}
}
if( n1==1)
{
if(n>=5)
{
sal=120*n;
disc=(sal*0.25);
sal=sal-disc;
}
else
{
sal=n*120;
}
}
if(n1==2)
{
if(n>=5)
{
sal=120*n;
disc=(sal*0.17);
sal=(120*n)-disc;
}
else
{
sal=n*120;
}
}
if(n1==3)
{
sal=n*120;
}
System.out.print("Dear "+s+" your bill amount is ");
System.out.printf("%.2f", sal);
}
}

*********************************************************************************************
*********************************************************************************************
***
6) ODD POSITION CHAR WILL BE IN UPPERCASE & EVEN WILL BE LOWERCASE-

INPUT : school

OUTPUT : sChOol

import java.util.Scanner;
public class UPLC{
public static void main(String []args){
Scanner sc = new Scanner(System.in);
String str = sc.next();
int strlen = str.length();
for(int i = 0 ; i < str.length(); i++){
char ch = str.charAt(i);
if(!(ch >= 'a' && ch <='z' || ch >= 'A' && ch <='Z' )){
System.out.println(str+ " is an invalid input");
return;
}
}

if(strlen >= 5 && strlen <= 20){


StringBuffer updateString = new StringBuffer();
char[] charArr = str.toCharArray();
for(int i = 0 ; i < charArr.length; i++){
char ch = charArr[i];
if(i % 2 != 0){
ch = Character.toUpperCase(ch);
}
updateString.append(ch);
}
System.out.println(updateString.toString());
}
else {
System.out.println(str+ " is an invalid Length");
}
}
}

*********************************************************************************************
*********************************************************************************************
****
7) RATING SCORE

INPUT: ENTER JESSON SCORE


1
2
3
4
8
ENTER JAMES SCORE
0
2
6
5
6

OUTPUT: JESSON SCORE : 2


JAMES SCORE : 2

import java.util.Scanner;
public class Ratingscore {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter Jesson Score");
int[] a1 = new int[5];
int[] a2 = new int[5];
int f = 0;
int t = 0;
int sum = 0;
int sum1 = 0;
for (int i = 0; i < 5; i++) {
a1[i] = sc.nextInt();
if (a1[i] < 0) {
f = 1;
t = a1[i];
break;
}
}
if (f == 1) {
System.out.println(t + " is invalid");
} else {
System.out.println("Enter James Score");
for (int j = 0; j < 5; j++) {
a2[j] = sc.nextInt();
if (a2[j] < 0) {
f = 1;
t = a2[j];
break;
}
}
if (f == 1) {
System.out.println(t + " is invalid");
} else {
for (int k = 0; k < 5; k++) {
if (a1[k] > a2[k]) {
sum++;
}
if (a1[k] < a2[k]) {
sum1++;
}
}
System.out.println("Jesson Score");
System.out.println(sum);
System.out.println("James Score");
System.out.println(sum1);
}
}
}
}

**ALTERNATE METHOD:

import java.util.Scanner;
public class minmax {
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
int jesson=0,james=0,c=0;
int a[]=new int[5];
int b[]=new int[5];
System.out.println("Enter Jesson Score");
for(int i=0;i<a.length;i++)
{
a[i]=sc.nextInt();
if(a[i]<0)
{
System.out.println("Invalid");
Runtime.getRuntime().halt(0);
}
}
System.out.println("Enter James Score");
for(int i=0;i<b.length;i++)
{
b[i]=sc.nextInt();
if(b[i]<0)
{
System.out.println("Invalid");
Runtime.getRuntime().halt(0);
}
}
if(a.length==b.length)
{
for(int i=0;i<a.length;i++)
{
if(a[i]>b[i])
{
jesson++;
}
else if(a[i]<b[i])
{
james++;
}
else if(a[i]==b[i])
{
c++;
}
}
System.out.println("Jesson Score: "+jesson);
System.out.println("James Score: "+james);
}
else{
System.out.println("Length not same");
}
}
}

*********************************************************************************************
*******************************************************************************

8.COUNT OF UPPERCASE AND COUNT OF LOWERCASE & OUTPUT WILL BE IN THE FORM OF
(UP-LC)

INPUT : HosTEL

OUTPUT: 4-2=2

import java.util.Scanner;

public class ContNext {


public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the string");
String str=sc.nextLine();
int uc=0,lc=0;
if(str.matches("[A-Za-z ]+")&&str.length()<10) {
for(int i=0;i<str.length();i++)
if(Character.isUpperCase(str.charAt(i))) {
uc++;
}
else if(Character.isLowerCase(str.charAt(i))){
lc++;
}
System.out.println(uc-lc);
}
}
}
*********************************************************************************************
*******************************************************************************
9) PRODUCT of COUNT of UPPERcase

andLOWERcaseletters

INPUT: ABsdEr

OUTPUT: 6 (3*3)

import java.util.Scanner;
public class minmax {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the String");
String s = sc.nextLine();
int upper = 0;
int lower = 0;
int i;
if (s.matches("[a-zA-Z]+")) {
for (i = 0; i < s.length(); i++) {
char c = s.charAt(i);
if (c >= 'A' && c <= 'Z') {
upper++;
}
if (c >= 'a' && c <= 'z') {
lower++;
}
}
System.out.println(upper * lower);
}
else
{
System.out.println("Invalid String");
}

}
}

*********************************************************************************************
******************************************************************************
10.Count of UPPERcase and LOWERcase and their difference

Enter the String: ColLEgE


Count of uppercase is : 4
Count of lowercase is : 3
Hence the ans is : 1

import java.util.Scanner;
public class MyClass {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the String ");
String str = sc.next();
int strlen = str.length();
for(int i =0; i < str.length() ; i++)
{ char ch = str.charAt(i);
if(!(ch >='a' && ch <= 'z' || ch >= 'A' && ch <= 'Z')){
System.out.println(str + " is an invalid String");
return;
}
}

if(strlen > 0 && strlen <= 10){


int upper = 0, lower = 0, ans = 0;

for(int i = 0; i < str.length(); i++)


{
char ch = str.charAt(i);
if (ch >= 'A' && ch <= 'Z')
upper++;
else if(ch >= 'a' && ch <= 'z')
lower++;
}
ans = upper - lower;
System.out.println("count of uppercase is :"+ upper);
System.out.println("count of lowercase is :"+ lower);
System.out.println("Hence the ans is :"+ ans);
}
else {
System.out.println(str + " is an invalid String");
}
}
}
*********************************************************************************************
*******************************************************************************
11.PUBLIC DISTRIBUTION

INPUT : OKR

OUTPUT : 90

import java.util.*;
public class Main
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
String str = in.nextLine();
int l=str.length();
if(l>5 || l<2)
{
System.out.println("Invalid Input");
}
else
{
int sum=0,flag=0;
for(int i=0;i<l;i++)
{
char c=str.charAt(i);
if(c=='O')
{
sum=sum+24;
}
else if(c=='K')
{
sum=sum+36;
}
else if(c=='S')
{
sum=sum+42;
}
else if(c=='R')
{
sum=sum+30;
}
else if(c=='W')
{
sum=sum+44;
}
else
{
flag=1;
}
}
if(flag==1)
{
System.out.println("Invalid Input");
}
else
{
System.out.println(sum);
}
}
}
}
*********************************************************************************************
******************************************************************************

12.LOTTERY TICKETS

INPUT: Enter the Starting range


23467
Enter the Ending range
23477

OUTPUT: 23469
23472

import java.util.*;
public class Main {
public static void main(String args[])
{
int i,c,n,sum,count;
sum=0;count=0;n=0;c=0;i=0;
Scanner sc = new Scanner(System.in);
System.out.println("Enter the Starting range");
int a = sc.nextInt();
String str = Integer.toString(a);
if(str.length()!=5)
{
System.out.println(str + " is an invalid input");
System.exit(0);
}

System.out.println("Enter the Ending range");


int b = sc.nextInt();
String str1 = Integer.toString(b);
if(str1.length()!=5)
{
System.out.println(str1 + "is an invalid input");
System.exit(0);
}

if(a>b)
{
System.out.println(a+" and "+b+" are invalid serial numbers");
System.exit(0);

}
for(i=a;i<=b;i++)
{
n=i;
while(n!=0)
{
c=n%10;
sum=sum+c;
n=n/10;
}
if((sum%3==0)&&((sum/3)%2==0))
{
System.out.println(i + " ");
count++;
}
sum=0;
}
if(count==0)
{
System.out.println("Eligible tickets are not available from "+a+" to "+b);
System.exit(0);
}
}
}

*********************************************************************************************
******************************************************************************
13.COFFEE STALL NUMEROLOGY

INPUT : Enter the Staff Name


Coffee Bar

OUTPUT : Coffee Bar satisfies the numerology logic

import java.util.*;
public class Main{
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the Staff Name");
String name = sc.nextLine();
int count=0;
for(int i=0;i<name.length();i++){
if(Character.isAlphabetic(name.charAt(i)) || name.charAt(i)==' '){
count++;
}
}
if(count==name.length()){
String str = name.replace(" ","");
int sum=0;
for(int i=0;i<str.length();i++){
sum += i;
}
if(sum%2==0){
System.out.println(name+" satisfies the numerology logic");
}else{
System.out.println(name+" does not satisfy the numerology logic");
}
}else{
System.out.println("Invalid Input");
}
}
}

*ALTERNATE METHOD USING -matches for same question

import java.util.*;
public class Main{
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the Staff Name");
String name = sc.nextLine();
if(name.matches("[a-zA-Z ]+")){
String str = name.replace(" ","");
int sum=0;
for(int i=0;i<str.length();i++){
sum += i;
}
if(sum%2==0){
System.out.println(name+" satisfies the numerology logic");
}else{
System.out.println(name+" does not satisfy the numerology logic");
}
}else{
System.out.println("Invalid Input");
}
}
}

*ALTERNATE METHOD

import java.util.Scanner;
public class CoffeeHouse {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the Stall Name");
String name = sc.nextLine();
if (name.matches("^[A-Za-z ]*$")) {
int sum = 0;
String fName = name.replaceAll(" ", "");
for (int i = 0; i < fName.length(); i++)
sum = sum + i;
if (sum % 2 == 0) {
System.out.println(name + " satisfies the numerology logic");
} else {
System.out.println(name + " not satisfies the numerology logic");
}
} else
System.out.println("Invalid Input");
}
}

*********************************************************************************************
******************************************************************************

14.ANAGRAM OR TWO WORDS OF SAME LETTER

INPUT : cat
act

OUTPUT: Same

import java.util.Arrays;
import java.util.Scanner;
public class minmax {
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter sentence 1");
String s1=sc.next();
s1=s1.toLowerCase();
System.out.println("Enter sentence 2");
String s2=sc.next();
s2=s2.toLowerCase();
if(s1.length()!=s2.length())
{
System.out.println("Invalid");
}
if(s1.matches("^[a-zA-Z]*")){
char c1[] = s1.toLowerCase().toCharArray();
char c2[] = s2.toLowerCase().toCharArray();
Arrays.sort(c1);
Arrays.sort(c2);
if (Arrays.equals(c1, c2)) {
System.out.println(s1 + " and " + s2 + " contain the same characters");
} else {
System.out.println(s1 + " and " + s2 + " contain the different characters");
}
}
else
{
System.out.println("Invalid");
}
}
}

ALTERNATE METHOD:

import java.util.*;
public class Main{
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
String first=sc.next();
String secound=sc.next();
String word1=Main.checker(first);
String word2=Main.checker(secound);
if(word1.equals(word2)){
System.out.println("Same");
}else{
System.out.println("Different");
}
}
public static String checker(String word){
char arr[]=word.toCharArray();
Arrays.sort(arr);
int index=0;
for(int i=0;i<arr.length;i++){
int j;
for(j=0;j<i;j++){
if(arr[j]==arr[i]){
break;
}
}
if(i==j){
arr[index++]=arr[i];
}
}
char arr1[]=Arrays.copyOf(arr,index);
String newword= new String(arr1);
return newword;
}
}

ALTERNATE METHOD

import java.util.*;
public class arraysquare {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int f1=0,f2=0;
String s1=sc.nextLine();
char c1[]=s1.toCharArray();
String s2=sc.nextLine();
char c2[]=s2.toCharArray();
for(int i=0;i<c1.length;i++)
{
f1=0;
for(int j=0;j<c2.length;j++)
{
if(c1[i]==c2[j])
{
f1=1;
break;
}
}
if(f1==0)
{
break;
}
}
for(int i=0;i<c2.length;i++)
{
f2=0;
for(int j=0;j<c1.length;j++)
{
if(c2[i]==c1[j])
{
f2=1;
break;
}
}
if(f2==0)
{
break;
}
}
if(f1==1 && f2==1)
{
System.out.println("Same Char");
}
else{
System.out.println("Different char");
}
}
}

*********************************************************************************************
*****************************************************************************
15.SUMMATION OF EVEN NUMBERS IN THE ARRAY

INPUT : Enter array size


4
Enter array elements in 1st array
2
4
6
8
Enter array elements in 2nd array
1
2
5
2

OTPUT: 0
6
0
10

import java.util.*;
public class Main
{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter array size");
int n=sc.nextInt();
if(n>=10 || n<1)
{
System.out.println(n+" is an invalid input");
Runtime.getRuntime().halt(0);
}
int arr1[]=new int[n];
int arr2[]=new int[n];
int result[]=new int[n];
System.out.println("Enter array elements in 1st array");
for(int i=0;i<n;i++)
{
arr1[i]=sc.nextInt();
}
System.out.println("Enter array elements in 2nd array");
for(int i=0;i<n;i++)
{
arr2[i]=sc.nextInt();
}
//PROGRAM LOGIC
int count=0;
for(int i=0;i<n;i++)
{
if((arr1[i]%2==0 || arr1[i]==0) && (arr2[i]%2==0 || arr2[i]==0))
{
result[i]=arr1[i]+arr2[i];
count++;
}
else
{
result[i]=0;
}
}
if(count==0)
{
System.out.println("No even number is present in an Array");
}
for(int i=0;i<n;i++)
{
System.out.println(result[i]);
}
}
}

*********************************************************************************************
******************************************************************************
16.RUNNERS COMPETITION

INPUT :Enter the number of runners


5

Enter the runner details


Robert,9.38
Richard,9.35
Christiano,9.35
Williams,9.36
Vinix,9.35

OUTPUT: Richard
Christiano
Vinix

import java.util.*;
public class Main{
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
sc.useDelimiter("\n");
System.out.println("Enter the number of runners");
int n = sc.nextInt();
if(n<=0 || n>10){
System.out.println(n+" is an invalid number of runners");
Runtime.getRuntime().halt(0);
}
String temp = "";
String name[] = new String[n];
float time[] = new float[n];
System.out.println("Enter the runner details");
for(int i=0;i<n;i++){
temp = sc.next();
String temparr[] = temp.split(",");
name[i] = temparr[0];
time[i] = Float.parseFloat(temparr[1]);
if(time[i]>12 || time[i]<8){
System.out.println(time[i]+" is an invalid input");
Runtime.getRuntime().halt(0);
}
}
int maxcount = 0;
float maxrep = 0;
for(int i=0;i<n;i++){
int count = 0;
for(int j=i+1;j<n;j++){
if(time[i]==time[j]){
count++;
}
}
if(count>=maxcount){
maxcount = count;
maxrep = time[i];
}
}
if(maxcount==n){
System.out.println(n+" runners have same timing");
}
else if(maxcount==0){
System.out.println("No runners with same time.");
}
else{
for(int i=0;i<n;i++){
if(maxrep == time[i]){
System.out.println(name[i]);
}
}
}
}
}

****ALTERNATE METHOD****

public static void main(String[] args) {


// TODO code application logic here
Scanner sc=new Scanner(System.in);
System.out.println("Enter the no of students");
int n=sc.nextInt();
if(n>10)
{
System.out.println(n+" is an invalid nuber of runners");
return;
}
String input;
String name[]=new String[n]; //name array
Double time[]=new Double[n]; //another time array
System.out.println("Enter the details");
for(int i=0;i<n;i++)
{
input=sc.next();
String[] a=input.split(","); // a[0] stores name a[1] stores time
name[i]=a[0]; //string->string
time[i]=Double.parseDouble(a[1]); //double<-string
if(time[i]<8 || time[i]>12)
{
System.out.println(time[i]+" is an invalid input");
return;
}

}
boolean flag = true;

double min=time[0];
int index=0;

for(int i=0;i<n;i++)
{
if(time[i]<min)
{
min=time[i];
//index=i;
}

if(min!=time[i])
{
flag=false;
System.out.println(name[i-1]);
}

}
if (flag) System.out.println(n+" runners have same timing");
}

}
*********************************************************************************************
******************************************************************************
17.REEDME

INPUT : Enter the customer name


Abi
Enter the category
History
Enter the quantity of books ordered
2900

OUTPUT : Total cost is 334080.0


import java.util.*;
public class Main{
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the customer name");
String name = sc.nextLine();
System.out.println("Enter the category");
String category = sc.nextLine();
category = category.toLowerCase();

if(!category.equals("adventure") && !category.equals("comics") && !category.equals("history") && !categ


ory.equals("thriller")){
System.out.println(category+" is invalid category");
Runtime.getRuntime().halt(0);
}
System.out.println("Enter the quantity of books ordered");
int quantity = sc.nextInt();
if(quantity <= 0){
System.out.println(quantity+" is an invalid quantity");
Runtime.getRuntime().halt(0);
}
int discount = 0;
int price = 0;
if(category.equals("adventure")){
price = 150;
if(quantity>=1700)
discount = 5;
}
else if(category.equals("comics")){
price = 230;
if(quantity>=1950)
discount = 5;
}
else if(category.equals("history")){
price = 120;
if(quantity>=2600)
discount = 4;
}
else if(category.equals("thriller") && quantity>=1700){
price = 190;
if(quantity>=6300)
discount = 3;
}
float totalcost = (price*quantity) - (price*quantity*discount/100);
System.out.println("Total cost is "+totalcost);
}
}

*********************************************************************************************
******************************************************************************
18)HARSHAD NUMBER (Sum of digit completely divide that

number) For example: 18= 1+8=9 and in 18/9 remainder is 0

INPUT: Enter array size: 5


Enter array elements : 18 14 12 24 13

OUTPUT: 18 12 24

import java.util.Scanner;
public class Harshad {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the number of values");
int n = sc.nextInt();
int i;
System.out.println("Enter the numbers");
int[] a = new int[n];
if (n > 0)
{
int flag = 0;
int k = 0;
for (i = 0; i < n; i++)
{
k = sc.nextInt();
if (k > 9)
a[i] = k;
else
{
flag = 1;
break;
}
}
if (flag != 1)
{
int c = 0;
for (i = 0; i < n; i++)
{
int x = a[i];
int sum = 0;
do {
int r = x % 10;
sum = sum + r;
x = x / 10;
}
while (x != 0);
if (a[i] % sum == 0)
{
c++;
System.out.println(a[i]);
}
}
if (c == 0)
System.out.println("The " + n + " values are not harshad number");
}
else
System.out.println("Provided " + k + " is not valid");
} else
System.out.println(n + " is an invalid input");
}
}
****ALTERNATE METHOD******

import java.util.Scanner;
class Main
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number of values");
int n=sc.nextInt();
System.out.println("Enter the numbers");
int a[]=new int[n];
if(n>0)
{
int flag=0;
int k=0;
for(int i=0;i<n;i++)
{
k=sc.nextInt();
if(k>9) a[i]=k; else
{
flag=1;
break;
}
}
if(flag!=1)
{
int c=0;
for(int i=0;i<n;i++)
{
int x=a[i];
int sum=0;
do
{
int r=x%10; sum=sum+r; x=x/10;
}while(x!=0);
if(a[i]%sum==0)
{ c++;
System.out.println(a[i]);
}
}
if(c==0)
System.out.println("The "+n+" values are not harshad number");
}else
System.out.println("Provided "+k+" is not valid");
}else
System.out.println(n+" is an invalid input");
}
}
*********************************************************************************************
*********************************************************************************************
*******
19) VIDEO GAME PLAYER (PS1)

INPUT : Enter the amount


18000
Enter the Video Game Player Type
PS4

OUTPUT: You can buy PS4

public class PS {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the amount");
int amount = sc.nextInt();
if (amount >= 3000) {
System.out.println("Enter the Video Game Player Type");
String type = sc.next();
if (type.matches("[P][S][1-5]")) {
if (type.equals("PS1")) {
if (amount >= 5000) {
System.out.println("You can buy PS1");
} else {
System.out.println("You need more money to buy a PS1");
}
} else if (type.equals("PS2")) {
if (amount >= 7800) {
System.out.println("You can buy PS2");
} else {
System.out.println("You need more money to buy a PS2");
}
} else if (type.equals("PS3")) {
if (amount >= 9500) {
System.out.println("You can buy PS3");
} else {
System.out.println("You need more money to buy a PS3");
}
} else if (type.equals("PS4")) {
if (amount >= 12000) {
System.out.println("You can buy PS4");
} else {
System.out.println("You need more money to buy a PS4");
}
} else if (type.equals("PS5")) {
if (amount >= 15000) {
System.out.println("You can buy PS5");
} else {
System.out.println("You need more money to buy a PS5");
}
}
} else {
System.out.println(type + " is Invalid Type");
}
} else {
System.out.println(amount + " is too less");
}
}
}

*********************************************************************************************
*********************************************************************************************
****
20) ABSOLUTE DIFFERENCE / ALTERNATE SUM DIFFERENCE

INPUT :Enter number


6
Enter values
12
13
6
8
9
7
(((( logic: (12-7=a
13-9=b
6-8=c
a+b+c=ans)))))

OUTPUT 2
3
4
5
5-2=3
4-3=1
So 3+1= 4
*/

import java.util.*;
public class AltDiff {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int sum=0;
int n=sc.nextInt();
int a[]=new int[n];
for(int i=0;i<n;i++)
{
a[i]=sc.nextInt();
}
for(int i=0;i<n/2;i++)
{
sum+=Math.abs(a[i]-a[n-i-1]);
}
System.out.println(sum);
}
}
*********************************************************************************************
*********************************************************************************************
*****
21.CHARACTER
ADDITION

INPUT : Enter : 3
Enter the sentences:
ks436
Agh73
7222

OUTPUT: 222
240
0

import java.util.*;
public class arraysquare{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int sum=0;
System.out.println("Enter:");
int n=sc.nextInt();
if(n<=0)
{
System.out.println("The number of sentences "+n+" is invalid");
return;
}
System.out.println("Enter the sentences:");
String str[]=new String[n];
for(int i=0;i<n;i++)
{
str[i]=sc.next();
}
for(int i=0;i<str.length;i++)
{
String s=str[i].replaceAll("[0-9]","");
for(int j=0;j<s.length();j++)
{
char c=s.charAt(j);
int ascii=c;
sum+=ascii;
}
System.out.println(sum);
sum=0;
}

}
}

*********************************************************************************************
******************************************************************************************
22. REVERSE FIRST HALF/MIDDLE LETTER of the string if string length is ODD

Input:
if length of string is even, the reverse the string:
Ex: Food
Output:
dooF

Input:
If length of the string is odd,then find the middle char and then ,reverse the string till mid char and print remain char
acters as it is.
Ex: Samsung
Output:
maSsung

package FinalAss;
import java.util.*;
public class MidLett {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
String str=sc.nextLine();//rahul
int len=str.length();
if(len%2==0)
{
StringBuilder sb=new StringBuilder(str);
sb.reverse();
System.out.println(sb.toString());
}
else if(len%2!=0)
{
System.out.println("Length of string is " +len);
int mid=len/2;
mid++;
System.out.println("Substring of string is "+mid);
String substr=str.substring(0,mid-1);
String remainSub=str.substring(mid-1,len);
StringBuilder sb=new StringBuilder(substr);
sb.reverse();
System.out.println(sb.toString()+remainSub);

}
}
}

ALTERNATE METHOD:::

import java.util.Scanner;
import java.util.regex.Pattern;
public class minmax {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
String str=sc.nextLine();//rahul
if(!Pattern.matches("[A-Za-z]+",str))
{
System.out.println(str+" is not a valid string");
return;
}
else if(str.length()<2)
{
System.out.println("Size of string "+str.length()+" is too small");
return;
}
int len=str.length();
if(len%2==0)
{
StringBuilder sb=new StringBuilder(str);
sb.reverse();
System.out.println(sb.toString());
}
else if(len%2!=0)
{
int mid=len/2;
String substr=str.substring(0,mid);
String remainSub=str.substring(mid,len);
StringBuilder sb=new StringBuilder(substr);
sb.reverse();
System.out.println(sb.toString()+remainSub);

}
}
}

*********************************************************************************************
*********************************************************************************************
*****

23 .ONLINE SHOPPING

input:
enter the product
laptop
Actual price
45000
exchange?
yes
bill amount:
27000.00

import java.util.*;
public class arraysquare {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the Product:");
String prod=sc.nextLine();
int ed=0,pd=0;
if(prod.equals("Mobile"))
{
ed=15;
pd=15;
}
else if(prod.equals("Laptop"))
{
ed=20;
pd=20;
}
else if(prod.equals("Headset"))
{
ed=0;
pd=10;
}
else if(prod.equals("Charger"))
{
ed=0;
pd=5;
}
else{
System.out.println("Not available");
return;
}
System.out.println("Enter the actual Price: ");
int price=sc.nextInt();
if(price<100)
{
System.out.println("Invalid Price");
return;
}
System.out.println("Do u want to Exchange?");
String exc=sc.next();
if(exc.equals("Yes") || exc.equals("yes"))
{
double ap=price-(price*pd)/100;
double ev=(price*ed)/100;
double total=ap-ev;
System.out.printf("Total=%.2f",total);
}
else if(exc.equals("No") || exc.equals("no"))
{
double total=price-(price*pd)/100;
System.out.printf("Total=%.2f",total);
}
else
{
System.out.println("Invalid Option");
}
}
}

*********************************************************************************************
********************************************************************************************
24 .OPERATOR FOUND

input:
45
23

22
output
45-23=22

import java.util.*;
public class arraysquare {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter n1 and n2:");
int n1=sc.nextInt();
if(n1>0)
{
int n2=sc.nextInt();
if(n2>0)
{
System.out.println("Enter n3:");
int n3=sc.nextInt();
if(n3>0)
{
if(n1+n2==n3)
{
System.out.println(n1+"+"+n2+"="+n3);
}
else if(n1-n2==n3)
{
System.out.println(n1+"-"+n2+"="+n3);
}
else if(n1*n2==n3)
{
System.out.println(n1+"*"+n2+"="+n3);
}
else if(n1/n2==n3)
{
System.out.println(n1+"/"+n2+"="+n3);
}
else
{
System.out.println(n3+" is an invalid answer");
}
}
else{
System.out.println("Invalid");
}
}
else{
System.out.println("Invalid");
}
}
else{
System.out.println("Invalid");
}

}
}

***ALNERNATE METHOD****

import java.util.*;
public class Main{
public static void main(String args[]){
Scanner sc = new Scanner(System.in);

System.out.println("Enter the n1 and n2");


int n1 = sc.nextInt();
if(n1<=0){
System.out.println(n1+" is an invalid number");
return;
}
int n2 = sc.nextInt();
if(n2<0){
System.out.println(n2+" is an invalid number");
return;
}
boolean b = false;
System.out.println("Function answer n3");
int n3 = sc.nextInt();

if((n1+n2)==n3){
System.out.println(n1+"+"+n2+"="+n3);
b=true;
}
if((n1-n2)==n3){
System.out.println(n1+"-"+n2+"="+n3);
b=true;
}
if((n1*n2)==n3){
System.out.println(n1+"*"+n2+"="+n3);
b=true;
}
if((n1/n2)==n3){
System.out.println(n1+"/"+n2+"="+n3);
b=true;
}
if(b== false){
System.out.println(n3+" is an invalid number");
}
}
}

*********************************************************************************************
*********************************************************************************************
****

25 .PRODUCT EQUAL SUM

INPUT : Enter the array size


4
Enter the elements of the first array
12
35
56
34
Enter the elements of the second array
261
195
112
813
OUTPUT: 35,195
34,813

import java.util.*;
public class arraysquare
{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the array size");
int n=sc.nextInt();
if(n<=0)
{
System.out.println("Invalid array size");
return;
}
int a[]=new int[n];
System.out.println("Enter the elements of the first array");
for(int i=0;i<n;i++)
{
a[i]=sc.nextInt();
}
System.out.println("Enter the elements of the second array");
int b[]=new int[n];
for(int i=0;i<n;i++)
{
b[i]=sc.nextInt();
}
int x[]=new int[n];
int y[]=new int[n];
for(int i=0;i<n;i++)
{
int c=a[i];
int prod=1;
while(c!=0)
{
prod*=(c%10);
c/=10;
}
x[i]=prod;
prod=0;
}
for(int i=0;i<n;i++)
{
int s=b[i];
int sum=0;
while(s!=0)
{
sum+=(s%10);
s/=10;
}
y[i]=sum;
sum=0;
}
for(int i=0;i<n;i++)
{
if(x[i]==y[i])
{
System.out.println(a[i]+","+b[i]);
}
}
}
}

*********************************************************************************************
*********************************************************************************************
*

26. UNIQUE CHAR

input:
LIfe is inherently risky

output:
life is ihrtly risky

package FinalAss;
import java.util.*;
public class nonuniquetwo {
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
String sentence = sc.nextLine();
String[] words = sentence.split(" ");
for(String word : words)
{
System.out.print(getUnique(word) + " ");
}
sc.close();
}
public static String getUnique(String str)
{
StringBuffer sb = new StringBuffer();
for(int i = 0; i<str.length(); i++)
{
if(countFrequency(str.charAt(i), str) == 1)
{
sb.append(str.charAt(i));
}
}
String result = sb.toString();
return result;
}
public static int countFrequency(char c, String str)
{
int count = 0 ;
for(int i = 0; i<str.length(); i++)
{
if(str.charAt(i) == c)
{
count++;
}
}
return count;
}
}

***ALTERNATE METHOD*****

import java.util.*;
public class Main
{
public static void main(String[] args)
{
System.out.println("Enter the String");
Scanner sc=new Scanner(System. in);
String str=sc.nextLine();
String output="";
String[] word=str.split(" ");
for(int i=0;i<word.length;i++)
{
for(int j=0;j<word[i].length();j++)
{
int count=0;
char c=word[i].charAt(j);
for(int k=0;k<word[i].length();k++)
{
if(c==word[i].charAt(k))
count++;
}
if(count==1)
{
output+=Character.toLowerCase(c);
}
}
output+=" ";
}
System.out.println(output);
}
}

*********************************************************************************************
*********************************************************************************************
*
27. BOX SIZE

INPUT : Enter the box size


6
Enter the numbers
5
55
3
59
42
8
OUTPUT: 32 is even its a valid box

import java.util.Scanner;
public class minmax {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the box size");
int a=sc.nextInt();
if(a<=0)
{
System.out.println(a+" is an invalid box size");
return;
}
int b[]=new int[a];
int c=0,sum=0,temp=0;
System.out.println("Enter the numbers");
for(int i=0;i<a;i++)
{
b[i]=sc.nextInt();
if(b[i]<=0)
{
System.out.println(b[i]+" is an invalid input");
return;
}
}
for(int i=0;i<a;i++)
{
c=b[i]%10;
sum+=c;
c=0;
}
if(sum%2==0)
{
System.out.println(sum+" is even its a valid box");
return;
}
else
{
System.out.println(sum+" is odd its an invalid box");
return;
}

}
}
****ALTERNATE METHOD***********

Box consists of n numbers and n>0


Enter the numbers and numbers should be greater than 0 and add all the last digits of the numbers.If the sum is
even print valid box else invalid box

Input:
Enter size:5
Enter numbers:
2
34
456
67
123

22 is even it's a valid box

Explanation:
22=(2+4+6+7+3)
Similarly for invalid box also

public class BoxGame {

public static void main(String[] args) {


Scanner sc = new Scanner(System.in);
System.out.println("Enter the box size");
int size = sc.nextInt();
int n=0;
int sum=0;
if(size<=0) {
System.out.println(size+" is an invalid box size");
return;
} else {
System.out.println("Enter the numbers");
int [] arr = new int [size];
for(int i=0;i<size;i++) {
arr[i] = sc.nextInt();
}
for(int i=0;i<size;i++) {
if(arr[i]<=0) {
System.out.println(arr[i]+" is an invalid input");
return;
}
}
for(int i=0;i<size;i++) {
n = arr[i]%10;
sum = sum+n;
}
if(sum%2==0) {
System.out.println(sum+" is even its a valid box");
}else {
System.out.println(sum+" is odd its an invalid box");
}
}

}
********************************************************************************************
****************************************************
28. ORDER IDENTIFICATION:(check where elements are in ascending

order) INPUT : Enter the array size : 5


Enter the elements: 32
44
55
66
77

OUTPUT : 32 44 55 66 77 are in ascending order

import java.util.Arrays;
import java.util.Scanner;

public class orderidentification {


public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the array size");
int a=sc.nextInt();
if(a<2 || a>10)
{
System.out.println(a+" is not a valid array size");
return;
}
int b[]=new int[a];
int count=0;
System.out.println("Enter the elements");
for(int i=0;i<a;i++)
{
b[i]=sc.nextInt();
}
int d[]= Arrays.copyOf(b,b.length);
Arrays.sort(d);

if(Arrays.equals(b,d))
{
count++;
}
if(count>0)
{
for(int i=0;i<b.length;i++)
{
System.out.print(b[i]+" ");

}
System.out.print("are in ascending order");
return;
}
else
{
for(int i=0;i<a;i++)
{
System.out.print(b[i]+" ");
}
System.out.print("are not in ascending order");
return;
}
}
***ALTERNATE METHOD***

public class ascendingDesceding {


public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter array size: ");
int n = sc.nextInt();
int[] arr = new int[n];
int[] temp = new int[n];
if (n < 2 || n > 10) {
System.out.println("Invalid size");
return;
}
for (int i = 0; i < n; i++) {
arr[i] = sc.nextInt();
temp[i]=arr[i]; //store the array elements in temp array for comaparison later
}
Arrays.sort(arr); //sort the original array
int count=0;
for(int i=0;i<n;i++) {
if(arr[i]==temp[i]){ //checking if elements of sorted array is equal to
temp array
count++;
} else {
count=0;
break;
}}
if(count!=0) {
System.out.println("All elements are in ascending order");
} else {
System.out.println("Elements are not in ascending order");
}}}

********************************************************************************************
********************************************************************************************
********************************
29) DATE ,MONTH AND

YEAR INPUT:13081995

OUTPUT: date: 13
month: 08
year: 1998

import java.util.Scanner;
public class minmax {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
String str=sc.nextLine();
int n=str.length();
for(int i=0;i<str.length() ;i++)
{
if(!(str.charAt(i)>='0' && str.charAt(i)<='9'))
{
System.out.println("Invalid input");
return;
}
if(n!=8)
{
System.out.println("Enter valid date");
return;
}
}
String date=str.substring(0,2);
String mon=str.substring(2,4);
String year=str.substring(4,8);

System.out.println("date:"+date);
System.out.println("Month:"+mon);
System.out.print("Year:"+year);

}
}

*********************************************************************************************
*********************************************************************************************
*
30) MEGA MART CUSTOMER IDENTIFICATION(String and SUBSTRING)

import java.util.*;
public class arraysquare{
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the customer id");
String cid = sc.next();
String shop = cid.substring(0,4);
//System.out.println("shop");
if(!shop.equals("Mega")){
System.out.println("Invalid Shop Name");
Runtime.getRuntime().halt(0);
}
String type = cid.substring(4,cid.length()-3);
//System.out.println(type);
if(!type.equals("Silver") && !type.equals("Gold") && !type.equals("Platinum")){
System.out.println("Invalid Customer Type");
Runtime.getRuntime().halt(0);
}
int mid = Integer.parseInt(cid.substring(cid.length()-3,cid.length()));
//System.out.println(mid);
if(mid<=99 || mid>=1000){
System.out.println("Invalid Member id");
Runtime.getRuntime().halt(0);
}
System.out.println("Welcome Mega Mart "+type+" Customer");

}
}

*********************************************************************************************
***********************************
31) MALE AND FEMALE COUNT

INPUT: MmFMff
OUTPUT: 3 MALE
3 FEMALE

import java.util.Scanner;
import java.util.regex.*;
public class minmax {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
String s=sc.nextLine();
int count1=0;
int count2=0;
if(Pattern.matches("[MmFf ]+",s)){
for (int i = 0; i < s.length(); i++) {
if (s.charAt(i) == 'M' || s.charAt(i) == 'm') {
count1++;
} else if (s.charAt(i) == 'F' || s.charAt(i) == 'f') {
count2++;
}
}
System.out.println(count1 + " Male");
System.out.println(count2 + " Female");
}
else
{
System.out.println("Invalid Input");
}
}
}
*********************************************************************************************
*********************************************************************************************
***
32) RAINFALL

INPUT: Enter the length of the roof in meters: 4


Enter the breadth of the roof in meters: 3
Enter the rainfall level: 3

OUTPUT: 360.00 Litres

import java.util.Scanner;
public class minmax {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
System.out.println("Enter the length of the roof in meters");
double l=sc.nextDouble();
if(l<=0)
{
System.out.println("Invalid Length");
return;
}
System.out.println("Enter the breadth of the roof in meters");
double b=sc.nextDouble();
if(b<=0)
{
System.out.println("Invalid breadth");
return;
}
System.out.println("Enter the rainfall level");
double r=sc.nextDouble();
if(r<=0)
{
System.out.println("Invalid rainfall");
return;
}
double h;
h=(l*b) *(r*10);
System.out.println(String.format("%.2f",h)+"Litres");
}
}

*********************************************************************************************
*********
33) NUMEROLOGY NAME CHECKING

import java.util.*;
import java.util.regex.Pattern;

public class arraysquare{


public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the name");
String a=sc.next();
if(!Pattern.matches("[A-Za-z]+",a))
{
System.out.println(a+" is an Invalid name");
return;
}
int sum=0;
char b[]=a.toCharArray();
for(int i=0;i<b.length;i++)
{
if(b[i]=='A'||b[i]=='a')
{
sum+=1;
}
else if(b[i]=='B'||b[i]=='b')
{
sum+=2;
}
else if(b[i]=='C'||b[i]=='c')
{
sum+=3;
}
else if(b[i]=='D'||b[i]=='d')
{
sum+=4;
}
else if(b[i]=='E'||b[i]=='e')
{
sum+=5;
}
else if(b[i]=='F'||b[i]=='f')
{
sum+=6;
}
else if(b[i]=='G'||b[i]=='g')
{
sum+=7;
}
else if(b[i]=='H'||b[i]=='h')
{
sum+=8;
}
else if(b[i]=='I'||b[i]=='i')
{
sum+=9;
}
else if(b[i]=='J'||b[i]=='j')
{
sum+=10;
}
else if(b[i]=='K'||b[i]=='k')
{
sum+=11;
}
else if(b[i]=='L'||b[i]=='l')
{
sum+=12;
}
else if(b[i]=='M'||b[i]=='m')
{
sum+=13;
}
if(b[i]=='N'||b[i]=='n')
{
sum+=14;
}
if(b[i]=='O'||b[i]=='o')
{
sum+=15;
}
if(b[i]=='P'||b[i]=='p')
{
sum+=16;
}
if(b[i]=='Q'||b[i]=='q')
{
sum+=17;
}
if(b[i]=='R'||b[i]=='r')
{
sum+=18;
}
if(b[i]=='S'||b[i]=='s')
{
sum+=19;
}
if(b[i]=='T'||b[i]=='t')
{
sum+=20;
}
if(b[i]=='U'||b[i]=='u')
{
sum+=21;
}
if(b[i]=='V'||b[i]=='v')
{
sum+=22;
}
if(b[i]=='W'||b[i]=='w')
{
sum+=23;
}
if(b[i]=='X'||b[i]=='x')
{
sum+=24;
}
if(b[i]=='Y'||b[i]=='y')
{
sum+=25;
}
if(b[i]=='Z'||b[i]=='z')
{
sum+=26;
}
}
System.out.println(sum);
if(sum%3==0 && sum%2==0)
{
System.out.println(a+" is a numerology name");
}
else
{
System.out.println(a+" is not a numerology name");
}
}
}

*******************************************************************************

34)OMR

import java.util.Scanner;
public class arraysquare{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int i;
System.out.println("Enter the No of questions");
int a=sc.nextInt();
if(a<0)
{
System.out.println("Invalid Number");
return;
}
int count=0;
int mark=0;
char b[]=new char[a];
System.out.println("Enter the answer key");
for (i=0;i<a;i++) {
b[i] = sc.next().charAt(0);

if ((b[i] >= 'a' && b[i] <= 'e')||(b[i] > 'E')) {


System.out.println("Invalid Answers");
return;
}
}
char c[]=new char[a];
System.out.println("Enter the student answers");
for (i=0;i<a;i++)
{
c[i]=sc.next().charAt(0);
if ((c[i] >= 'a' && c[i] <= 'e')||(b[i]>'E')) {
System.out.println("Invalid Answers");
return;
}
}

for(i=0;i<a;i++)
{
if(b[i]==c[i])
{
count++;
}
}
if(count>0)
System.out.println("Correct answers are "+count);
mark=(count*100)/a;
if(count<1)
System.out.println("All answers are wrong");
System.out.println("Mark is "+mark);

}
}

****ALTERNATE METHOD****

import java.util.*;
public class OMREvaluation {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the No of questions");
int no = sc.nextInt();
if (no <= 0) {
System.out.println("Invalid Number");
return;
} else {
char anskey[] = new char[no];
System.out.println("Enter the answer key");
for (int i = 0; i < no; i++) {
char x = sc.next().charAt(0);
if (x >= 'A' && x <= 'E')
anskey[i] = x;
else {
System.out.println("Invalid Answers");
return;
}
}
char studanskey[] = new char[no];
System.out.println("Enter the student answers");
for (int i = 0; i < no; i++) {
char y = sc.next().charAt(0);
if (y >= 'A' && y <= 'E')
studanskey[i] = y;
else {
System.out.println("Invalid Answers");
return;
}
}
int count = 0;
for (int i = 0; i < no; i++) {
if (anskey[i] == studanskey[i])
count++;
}
if (count == 0)
System.out.println("All answers are wrong \nMark is 0");
else {
System.out.println("Correct answers are " + count);
System.out.println("Mark is " + ((count * 100) / no));
}
}
}
}

**********************************************************************************************
***************************************************

35)MULTIPLY WITH POSITION

INPUT:
Enter the array size
5

Enter the elements


12
3
7
9
4

Sample Output:
12
6
21
36
20

Logic:
12*1=12
3*2=6
7*3=21
9*4=36
4*5=20

import java.util.*;
public class Main
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the array size:");
int n=sc.nextInt();
int res=0;
if(n<1 || n>10)
{
System.out.println("Invalid Array Size");
return;
}
int a[]=new int[n];
for(int i=0;i<n;i++)
{
a[i]=sc.nextInt();
}

for(int i=0;i<n;i++)
{
res=a[i]*(i+1);
System.out.println(res);
}

}
}

**********************************************************************************************
******************************************************************
36) CAR PARKING

Sample Input:
Enter the car number
ap 37 1498

Sample Output
Park the car in 3rd floor

import java.util.*;

public class CarPrking {


public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the car number");
String num = sc.nextLine();
if (num.length() != 10) {
System.out.println("Invlid State Code");
return;
}
String floor;
String code = num.substring(0, 2);
if (code.equals("TN")) {
floor = "ground";
} else if (code.equals("KA")) {
floor = "1st";
} else if (code.equals("KL")) {
floor = "2st";
} else if (code.equals("AP")) {
floor = "3st";
} else {
System.out.println("Invlid State Code");
return;
}
System.out.println("Park the car in " + floor + " floor");
}
}

ALTERNATE METHOD:

37) DIGIT COUNT

Sample Input:

Enter the number


56164

Enter the digit


6

Sample output
6 appears in 56164 is 2

Explanation:
Digit 6 appears 2 times in the number 56164

package accenture;
import java.util.*;

public class digitcount {

public static void main(String[] args) {


Scanner sc=new Scanner(System.in);
int count=0;
System.out.println("Enter the number:");
int n=sc.nextInt();
String str=String.valueOf(n);
if(n>0)
{
System.out.println("Enter the digit:");
char d=sc.next().charAt(0);
char ch[]=str.toCharArray();
for(int i=0;i<ch.length;i++)
{

if(ch[i]==d)
{
count++;
}
}
if(count>1)
{
System.out.println(d+" appears "+n+" is "+count);
}
}

38) WORD FINDING (repeated words)

Sample input:
Enter the number of words
5
Enter the words in set1:
good
bad
hello
Nothing
North

Enter the words in set2:


Bad
world
word
north
hello

package practice;
import java.util.*;
public class RepeatedWords {

public static void main(String[] args) {


// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
System.out.println("Enter the number of words");
int n = sc.nextInt();
if(n<=0){
System.out.println(n+" is less than the desired limit");
return;
}

String set1[] = new String[n];


String set2[] = new String[n];
System.out.println("Enter the words in set1:");
for(int i = 0;i<n;i++){
set1[i] = sc.next().toLowerCase();
}
System.out.println("Enter the words in set2:");
for(int i = 0;i<n;i++){
set2[i] = sc.next().toLowerCase();
}
String res[] = new String[n];
int k = 0;
for(int i = 0;i<n;i++){
int flag = 0;
for(int j = 0;j<n;j++){
if(set1[i].equals(set2[j])){
flag = 1;
break;
}
}
if(flag != 1){
res[k++] = set1[i];
}
}
/*for(int i = 0;i<n;i++){
if(set1[i] == set2[i]){
continue;
}
else{
res[k++] = set1[i];
}
}*/
System.out.println("The uncommon words are:");
for(int i = 0;i<k;i++){
System.out.println(res[i]);
}

}
**********************************************************************************************
******************************************************
39) SUM OF INTEGERS AT EVEN OR ODD PLACES

Enter size: 5
Enter numbers:
123(1+3=4)
2536(5+6=11)
2(2)
57(7)
76542(7+5+2=14)

Output:
38(4+11+2+7+14)

import java.util.*;
public class oddevenindex {
public static void main(String[] args)
{
Scanner sc = new Scanner (System.in);
System.out.println("Enter the size of the array: ");
int n = Integer.parseInt(sc.nextLine());
String[] arr = new String[n];
int[] fin = new int[n];
System.out.println("Enter the elements of the array: ");
for(int i=0;i<n;i++)
{
arr[i] = sc.nextLine();
}
int sum = 0;
int total =0;
if(n%2!=0)
{
for(int i=0;i<arr.length;i++) {
String num = arr[i];
char[] digi = num.toCharArray();
sum = 0;
if (digi.length % 2 == 0) {
for (int j = 1; j < digi.length; j += 2) {
char x = digi[j];
sum = sum + Integer.parseInt(String.valueOf(x));
}
fin[i] = sum;
}
else
{
for (int j = 0; j < digi.length; j += 2) {
char x = digi[j];
sum = sum + Integer.parseInt(String.valueOf(x));
}
fin[i] = sum;

}
}
for(int x: fin)
total +=x;
}
else{
for(int i=0;i<arr.length;i++) {
String num = arr[i];
char[] digi = num.toCharArray();
sum = 0;
if (digi.length % 2 == 0) {
for (int j = 1; j < digi.length; j += 2) {
char x = digi[j];
sum = sum + Integer.parseInt(String.valueOf(x));
}
fin[i] = sum;
}
else
{
for (int j = 0; j < digi.length; j += 2) {
char x = digi[j];
sum = sum + Integer.parseInt(String.valueOf(x));
}
fin[i] = sum;

}
}
for(int x: fin)
total +=x;
}

System.out.println("Output: "+total);

}
}

*****ALTERNATE METHOD*****

package practice;
import java.util.*;
public class SumOfEvenOrOdd {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
System.out.println("Enter the size");
int n = sc.nextInt();
if(n<=0){
System.out.println("Invalid size");
return;
}
System.out.println("Enter the elements:");
int sum = 0;
String str[] = new String[n];
for(int i=0;i<n;i++){
str[i] = sc.next();
}
for(int i = 0;i<n;i++){
String s = str[i];
if(s.length()%2 == 0){
for(int j = 1;j<s.length();j+=2){
sum+=Integer.parseInt(s.substring(j,j+1));
}
}else{
for(int j = 0;j<s.length();j+=2){
sum+=Integer.parseInt(s.substring(j,j+1));
}
}
}
System.out.println(sum);
}

}
**********************************************************************************************
**********************************************************************
40) SUM OF EVEN ELEMENTS

Here, size of the array should be taken as input, and it should be between 1 and 10 (inclusive)
If it is not in 1 and 10, print it as "invalid"
Now, by the comparing the values at the same indices of both the arrays, if both values are even, then print the sum
of the two values, otherwise print "0".
Before performing operation, make sure if no even element is present in both the arrays, then print it as "There are no
even elements in both the arrays", otherwise perform the above operation.

For example, see the following inputs and outputs:

1. Sample input:
Enter the size of array: 3
Enter the elements in first array:
2
3
4
Enter the elements in second array:
1
5
8
Sample output:
0
0
12

2. Enter the size of array: 3


Enter the elements in first array:
5
3
1
Enter the elements in second array:
1
5
9
Sample output:
There are no even elements in both the arrays

3.Sample input:
Enter the size of array: 1
Enter the elements in first array:
5
Enter the elements in second array:
1
Sample output:
There are no even elements in both the arrays

package practice;
import java.util.*;
public class SumOfEvenElements {

public static void main(String[] args) {


// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
System.out.println("Enter the size of the array:");
int n = sc.nextInt();
if(n<=0 || n>10){
System.out.println("Invalid");
return;
}
System.out.println("Enter the elements in the first array:");
int arr1[] = new int[n];
for(int i = 0;i<n;i++)
arr1[i] = sc.nextInt();
System.out.println("Enter the elements in the second array:");
int arr2[] = new int[n];
for(int i = 0;i<n;i++)
arr2[i] = sc.nextInt();
int count = 0;
for(int i = 0;i<n;i++){
if(arr1[i]%2 !=0 && arr2[i]%2 != 0){
count++;
}
}
if(count == n){
System.out.println("There are no even elements in both arrays:");
return;
}else{
for(int i = 0;i<n;i++){
if(arr1[i]%2 == 0 && arr2[i]%2 == 0){
System.out.println(arr1[i]+arr2[i]);
}else{
System.out.println("0");
}
}
}
}
}
**********************************************************************************************
*********************************************************************
41) COUNT OF OCCURRENCES OF SUBSTRING IN A STRING

Sample input:
Enter the string
Entertainment

Enter substring
en

Sample output: 2

package accenture;
import java.util.*;
import java.util.regex.*;
public class countofoccurencesofsubstringinastring {

public static void main(String[] args) {


Scanner sc=new Scanner(System.in);
int count=0;
System.out.println("Enter the string:");
String str=sc.next();
if(Pattern.matches("[a-z]+", str))
{
System.out.println("Enter pattern:");
String pat=sc.next();
if(Pattern.matches("[a-z]+", pat))
{
Pattern p=Pattern.compile(pat);
Matcher m=p.matcher(str);
while(m.find())
{
count++;
}
System.out.println("Count is: "+count);
}
else
{
System.out.println("Invalid Pattern");
}
}
else
{
System.out.println("Invalid String");
}

}
**********************************************************************************************
******************************************************************
42) LARGEST SORTED SUBSTRING FROM INPUT STRING

Find longest sorted substring from input string..


Input : abczgdpqrstubg
Output: pqrstu
*/
import java.util.*;
public class Main
{
public static void main (String[] args)
{
Scanner sc=new Scanner(System.in);
String s=sc.next();
int firstindex=0,lastindex=0,length=0;
for(int i=0;i<s.length();i++)
{
int asci=s.charAt(i);
int count=1;
for(int j=i+1;j<s.length();j++)
{
if(s.charAt(j)==++asci)
{
count++;
continue;
}
else
{
if(count>length)
{
firstindex=i;
lastindex=j;
length=count;
break;
}
}
}
}
System.out.println(s.substring(firstindex,lastindex));
}
}
**********************************************************************************************
********************************************************************
43) NON-UNIQUE ELIMINATION

package com.company;
import java.util.Scanner;

public class NonUniqueElimination {


public static void main(String[] args){
Scanner sc=new Scanner(System.in);
String name=sc.nextLine(),abc="";
int count=0;
for(int i=0;i<name.length();i++)
{
for(int j=1;j<name.length()-1;j++)
{
if(name.charAt(i)==name.charAt(j))
{
name=name.replace(String.valueOf(name.charAt(j)),"");
count+=1;
}
}
}
if(count==0) {
System.out.println("All are unique character");
return;
}
else {
System.out.println(name);
}
}
**********************************************************************************************
**********************************************************************************************
**

44) THEATER SEAT DETAILS

Sample input 1:
A2S3D06D13

Sample output 2:
Seat Number
D13
D14
D15
D16
D17

Sample input 2:
A2S3D02C01

Sample Output2:
Seat Number
C1
C2

import java.util.*;
import java.util.regex.Pattern;
public class Main{
public static void main(String args[]){
Scanner sc = new Scanner(System.in);

String str = sc.next();


if(str.length()!=10){
System.out.println("Invalid Input");
return;
}

if(Pattern.matches("[0-9]+",str.substring(5,7)) && Integer.parseInt(str.substring(5,7))>=1


&& Integer.parseInt(str.substring(5,7))<=10){
int seatnumber = Integer.parseInt(str.substring(5,7));
String eightletter = str.substring(7,8);
if(Pattern.matches("[A-Za-z]",eightletter) && Pattern.matches("[0-9]+",str.substring(8,10))){
int n = Integer.parseInt(str.substring(8,10));
for(int i=0;i<seatnumber;i++){
System.out.println(eightletter + (n++));
}
}
else{
System.out.println("Invalid Seat Number");
return;
}
}
else{
System.out.println("Invalid Count");
return;
}
}
}
**********************************************************************************************
***************************************************************************

45) CALCULATE OFFER PRICE (DISCOUNT PRICE)

import java.util.Scanner;

public class DiscountPrice {


public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
String code=sc.nextLine();
int len=code.length();
if(len<6 || len>8)
{
System.out.println("Invalid Input");
return;
}
String mrps=code.substring(4);
int mrp=Integer.parseInt(mrps);
System.out.println("MRP Price :"+mrp);
if(mrp>=1 && mrp<=10)
{
System.out.println("Offer Price: Rs"+mrp);
}
else if(mrp>=11 && mrp<=50)
{
System.out.println("Offer Price: Rs"+(mrp-5));
}
else if(mrp>=51 && mrp<=500)
{
System.out.println("Offer Price: Rs"+(mrp-15));
}
else if(mrp>= 501 && mrp<=5000)
{
System.out.println("Offer Price: Rs"+(mrp-105));
}
else if(mrp>=5001 && mrp<=9999)
{
System.out.println("Offer Price: Rs"+(mrp-1005));
}
}
}
**********************************************************************************************
*******************************************************************************

46) THREE’S

Sample input:
Enter the string
Long live

import java.util.*;
import java.lang.*;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("Enter the String");
String str =in.nextLine();
for(int i=0;i<str.length();i++)
{
if((Character.isLetter(str.charAt(i)) || Character.isWhitespace(str.charAt(i))))
continue;
else{
System.out.println(str+" is not a valid string");
return;
}
}
int sum=0;
for(int i=0;i<str.length();i++){
if((i+1)%3==0){
sum+=(int)str.charAt(i);
}
}
System.out.println("Sum is "+sum);
}
}
**********************************************************************************************
**********************************************************************************
47) EVEN POSITION CAPS (CAPITAL LETTERS)

import java.util.Scanner;
import java.util.regex.Pattern;

public class EvenPositionCaps {


public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Input string");
String s = sc.nextLine();
if (!Pattern.matches("[A-Za-z]+", s)) {
System.out.println(s + " is an invalid input");
return;
} else {
if (s.length() < 5 || s.length() > 20) {
System.out.println(s + " is an invalid length");
return;
}
String output = s.charAt(0) + "";
for (int i = 0; i < s.length() - 1; i++) {
if ((i) % 2 == 0)
output += Character.toString(s.charAt(i + 1)).toUpperCase();
else
output += s.charAt(i + 1);
}
System.out.println(output);
}
}
}

***ALTERNATE METHOD***

import java.util.*;
import java.util.regex.Pattern;
public class Main{
public static void main(String args[]){
Scanner sc = new Scanner(System.in);

System.out.println("Input string");
String str = sc.next();
if(Pattern.matches("[A-Za-z]+",str)){

if(str.length()<5 || str.length()>20){
System.out.println(str+" is an invalid length");
return;
}
String output = str.charAt(0)+"";
for(int i=0;i<str.length()-1;i++){
if(i%2==0){
output = output+ Character.toString(str.charAt(i+1)).toUpperCase();
}
else
output = output + str.charAt(i+1);
}
System.out.println(output);
}
else{
System.out.println(str+" is an invalid input");
return;
}
}
}
**********************************************************************************************
****************************************************************************************

48) FUN COUNT

public class FunCount {


public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number of toys:");
int n=sc.nextInt();
if(n<=0)
{
System.out.println("Invalid Input");
}
else if(n>15)
{
System.out.println("Number exceeds the limit");
}
else{
String[] a=new String[n];
System.out.println("Enter the toy list");
for(int i=0;i<n;i++)
{
a[i]=sc.next().toLowerCase();
}
Arrays.sort(a);
int count=0;
for(int i=0;i<n;i++)
{
count=1;
for(int j=i+1;j<n;j++)
{
if(a[i].equalsIgnoreCase(a[j]))
{
count++;
a[j]="0";
}
}
if((a[i])!="0")
{
System.out.println(a[i]+"="+count);
}

}
}
}
}
**********************************************************************************************
*******************************************************************************

49) SPEED ESTIMATION

import java.util.*;
public class Main{
public static void main(String args[]){
Scanner sc = new Scanner(System.in);

System.out.println("Enter the distance in kilometre");


int km = sc.nextInt();

if(km<=0){
System.out.println("Invalid Input");
return;
}

System.out.println("Enter the time to reach in hours");


int time = sc.nextInt();
if(time<=0){
System.out.println("Invalid Input");
return;
}

int sp = km/time;
if(sp>30){
int in_sp = sp-30;
System.out.println("You want to increase a speed "+in_sp+" km/hr from a normal speed");
}
else{
System.out.println("You drive a car at a normal speed");
}
}
}
***********************************************************************************************
*********************************************************************************
50) SUM OF SQUARES (RE-TEST)

Sample input
Enter the number of values
4
Enter the values
2
7
9
8

Sample output
130

Explanation
Odd numbers are 7,9 = 7*7 +9*9 = 49+81=130
import java.util.*;
public class Main
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number of values");
int n=sc.nextInt();
if(n<=0)
{
System.out.println(n+" is an invalid size");
return;
}
int a[]=new int[n];
int count=0;
int sum=0;
System.out.println("Enter the values");
for(int i=0;i<n;i++)
{
a[i]=sc.nextInt();
if(a[i]%2!=0)
count=count+1;
}
if(count<=0)
{
System.out.println("These "+n+" values are not a odd digit");
return;
}
else
{
for(int i=0;i<n;i++)
{
if(a[i]%2!=0)
{
sum=sum+a[i]*a[i];
}
}
System.out.println(sum);
}

}
}

JAVA END
*********************************************************************************************
*********************************************************************************************
********

RDBMS IMPORTANT CODES(NOT TESTED)


1.)Select concat(concat(customer_name,'has taken a
policy on'),date_of_policy) as Enrollment_details
from customer JOIN Policy using (customer_id)
order by customer_name,date_of_policy;

2.)select plolicy_id,policy_name,rate_of_interest, bonus_percentage


from policy
where minimum_primeium_amount = 1200
order by policy_d;

3.)select fine_range,fine_amount
CASE
When fine_range=L1
then 5+fine_amount
when fine_range=L2
then 10+fine_amount
When fine_range=M1
then 15+fine_amount
when fine_range=M2
then 20+fine_amount
When fine_range=H1
then 25+fine_amount
when fine_range=H2
then 30+fine_amount
END as NEW_FINE_AMOUNT

4.)select leave_type,allocated_days
CASE
when leave_type='CASUAL'
then allocated_days+2
when leave_type='SICK'
then allocated_days+5
when leave_type='MATERNITY'
then allocated_days+90
when leave_type='MARRIAGE'
then allocated_days+3
when leave_type='STUDY'
then allocated_days-2
END as NEW_ALLOCATED_TYPES
from table_name
order by leave_type;

5.) select emp_id,emp_name,department_id,department_name


from Department JOIN Employee using (department_id)
JOIN Leave+Avail_details using (Emp_id)
JOIN Leave using (Leave_type)
where Allocated_days = 0
order by emp_id;
*********************************************************************************************
**

1.) Account Info - "HDVL002"


select account_type, count(account_id) as TOTAL_ACCOUNTS
from Acount_Info where IFC_Code = 'HDVL002'
group by account_type order by account_type;

2.)select customer_id,customer_name,phone_no,order_date
from Customer_info JOIN Orders using (customer_id)
where order_amount > 500
order by customer_id,order_date;

3.) select distinct customer_id,customer_name,phone_no,loan_amount as


total_loan_amount from customers JOIN loans_taken using
(customer_id)
order by customer_id;

4.) select distinct boat_id,seat_capacity,count(ride_id) as ride_count


From Boat_details JOIN Ride_details using (boat_id)
order by boat_id;

5.) select customer_id,customer_name,contact_no,mail_id


from Coustomer_details where Gender = 'M'
order by customer_id;
6.) select customer_name,total_amount_paid
from Customer_master JOIN Booking_details using (customer_id)
where total_amount_paid < (select max(total_amount_paid) from booking_details
where total_amount_paid < (select max(total_amount_paid) from booking_details))
order by customer_name;

7.) select book_code,book_title, author,rack_num


from book_details where category = 'JAVA'
order by book_code;

8.) select customer_name,policy_enrollment as Enrollment_details


from customer JOIN policy_enrolmment using (customer_id)
order by customer_name,date_of_enrollment;

9.)DECODE QUESTION
select fine_range, fine_amount,
decode(fine_range, 'L1',fine_amount+5,
'L2',fine_amount+10,
'M1',fine_amount+10,
'M2',fine_amount+10,
'H1',fine_amount+10,
'H2',fine_amount+10)new_fine_amount
from fine_details;

10.)select customer_name||" has taken policy on"|| date_of_enrollment as


enrollment_details form customer
join policyenrollent using (customer_id)
order by customr_name,date_of_enrollment;

11.)select policy_id,policy_name,rate_of_interest,bonus_percentage
from policy where mimum_premium_amount = 1200
order by policy_id;

12.) select customer_id,customer_name, street,phone_no,email


from Customers JOIN loan_taken using (customer_id)
where loan_amount > = 500000 and loan_amonunt <1500000
order by customer_id;

13.)select distinct boat_id, boat_name,boat_type


from boat_details JOIN ride_details using (boat_id)
where DOT LIKE '%-AUG-%' and Shift = 'evening'
order by boat_id;

14.) select policy_id,policy_name,rate_of_interest


from policy where miniimum_ppremium_amount < 3000 AND bonus_percent > 85
order by policy_id;

RDBMS ANSWERS

1.1) Write a query to display boat_type and number of boats running under each type. Give an alias name as 'NO_OF
_BOATS'.
Note: Boat_type can be 'DELUXE' or 'SUPER DELUXE'.

select boat_type,count(Boat_id) as NO_OF_BOATS


from boat_details
group by Boat_type;

1.2) select boat_name,boat_type from boat_details


where seat_capacity between 100 and 200
order by boat_name desc;

2.1) select vehicle_type,count(vehicle_id)


from vehicle_details
group by vehicle_type
order by vehicle_type;

2.2) select driver_id,driver_name,phone_no,Driver_rating


from driver_details where driver_rating between 3 and 5
order by driver_rating desc;

3.1) select coursename from course


c join registration r on
c.courseid=r.courseid
having count(studid)>=2
group by coursename
order by coursename;

3.2) select s.studid,sum(fees) as TOTALFEES


from student s join registration r
on s.studid=r.studid join course c
on r.courseid=c.courseid
group by s.studid
order by s.studid;

3.3) select studid,count(CourseID) as NOOFCOURSES


from registration
group by Studid
order by NOOFCOURSES desc,Studid;

3.4) select student.stuid,firstname from student


join registration on registration.stuid=student.stuid
where lower(to_char(doj,'MON'))='jan';

3.5) select courseid,coursename from


course where duration between 10 and 15;

3.6) select courseid,registration.stuid from registration


join student on registration.stuid=student.stuid
where lower(to_char(doj,'MON'))=lower(to_char(dob,'MON'));

You might also like