0% found this document useful (0 votes)
24 views

Helo

Uploaded by

7le7exieow
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views

Helo

Uploaded by

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

import java.io.

*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.function.*;
import java.util.regex.*;
import java.util.stream.*;
import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.toList;

class CipherDecipher{

public String swapCase(String str){


char [] ch =str.toCharArray();
for(int i=0;i<str.length();i++){
if(ch[i]<=90&&ch[i]>=65){
ch[i]+=32;
}
else if(ch[i]<=122&&ch[i]>=97)
ch[i]-=32;
}
return String.valueOf(ch);
}

public String asciiString(String str){


StringBuilder sb=new StringBuilder();
int n =str.length();
for (int i=0;i<n;i++){
if(i%2==1){
sb.append((int)str.charAt(i));

}
else
sb.append(str.charAt(i));

}
return sb.toString();
}

public String toChar(String str){


StringBuilder sb=new StringBuilder();
int n=str.length();
for (int i=0;i<n-1;i++){
char c=str.charAt(i);
if(Character.isDigit(c)){
int ch=c-'0';
while(i<n-2&&Character.isDigit(str.charAt(++i))){
ch*=10;
ch+=str.charAt(i)-'0';

}
c=(char)ch;
sb.append(c);
if(!Character.isDigit(str.charAt(i)))
sb.append(str.charAt(i));
continue;

}
sb.append(c);

}
return sb.toString();

public String ciphering(String normal){

normal=swapCase(normal);
normal=(new StringBuilder(normal)).reverse().toString();
normal=normal.replaceAll(" ","*");
normal=asciiString(normal);
normal=normal+"3";

return normal;
}

public String deciphering(String ciphered){


ciphered=toChar(ciphered);
ciphered=ciphered.replaceAll("\\*"," ");
ciphered=(new StringBuilder(ciphered)).reverse().toString();
ciphered=swapCase(ciphered);
return ciphered;

}
}

public class Solution {

public static void main(String[] args){


Scanner readInput = new Scanner(System.in);
String normal=readInput.nextLine();
String ciphered=readInput.nextLine();

CipherDecipher cipherOrDecipher = new CipherDecipher();


System.out.println(cipherOrDecipher.ciphering(normal));
System.out.println(cipherOrDecipher.deciphering(ciphered));

//////////////////////////////polymorphism//////////////////////////////
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
public static void main(String args[] ) throws Exception {
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
Scanner sc = new Scanner(System.in);
int m = sc.nextInt();
int n= sc.nextInt();
int p=m;
int q=n;
for(int i = m ; i <= n ; i++)
{
//logic for checking number is prime or not
int count = 0;
for(int j = 1 ; j <= i ; j++)
{
if(i % j == 0)
count = count+1;
}
if(count == 2)
System.out.print(i+" ");
}

int sum=0,r,i,n1;
System.out.println("");
for(i=m;i<=n;i++)
{
n1=i;
sum=0;
//checking for happy number
while(sum!=1 && sum!=4)
{
sum=0;
while(n1>0)
{
r=n1%10;
sum+=(r*r);
n1=n1/10;
}
n1=sum;
}
//printing the result
if(sum==1)
System.out.print(i+" ");
}

}
}

//////////////////////Multiple Inheritence////////////////////////
import java.util.Arrays;
import java.util.Scanner;
import java.util.*;

interface HockeyTeam{
public int calculateHockeyScore();
public int findHighestGoalByIndividualInHockey();
}
interface FootballTeam{
public int calculateFootballScore();
public int findHighestGoalByIndividualInFootball();
}
class Sport implements HockeyTeam,FootballTeam{
int []hockeyPlayers = new int[11];
int []FootballPlayers = new int[11];
//Scanner sc = new Scanner(System.in);
Sport(int[] paramHockeyPlayers,int[] paramFootballPlayers){
for(int i=0;i<hockeyPlayers.length;i++){
hockeyPlayers[i]=paramHockeyPlayers[i];
}
for(int k=0;k<FootballPlayers.length;k++){
FootballPlayers[k]=paramFootballPlayers[k];
}
}

public int calculateHockeyScore(){


int sum = 0;
//System.out.println("Enter the elements of the array one by one ");

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


//hockeyPlayers[i] = sc.nextInt();
sum = sum + hockeyPlayers[i];
}

return sum;
}
public int calculateFootballScore(){
int sum = 0;
//System.out.println("Enter the elements of the array one by one ");

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


//FootballPlayers[i] = sc.nextInt();
sum = sum + FootballPlayers[i];
}

return sum;
}

public int findHighestGoalByIndividualInHockey(){


int max = hockeyPlayers[0];
//Loop through the array
for (int i = 0; i < hockeyPlayers.length; i++) {
//Compare elements of array with max
if(hockeyPlayers[i] > max)
max = hockeyPlayers[i];
}
return max;
}

public int findHighestGoalByIndividualInFootball(){


int max = FootballPlayers[0];
//Loop through the array
for (int i = 0; i < FootballPlayers.length; i++) {
//Compare elements of array with max
if(FootballPlayers[i] > max)
max = FootballPlayers[i];
}
return max;
}
}
ublic class Solution{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
int[] hockeyPlayers = new int[11];
int[] footballPlayers = new int[11];

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


{
hockeyPlayers[i] = sc.nextInt();
}

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


{
footballPlayers[i] = sc.nextInt();
}

Sport s = new Sport(hockeyPlayers, footballPlayers);


try{
HockeyTeam.class.getMethod("calculateHockeyScore");
HockeyTeam.class.getMethod("findHighestGoalByIndividualInHockey");
FootballTeam.class.getMethod("calculateFootballScore");
FootballTeam.class.getMethod("findHighestGoalByIndividualInFootball");

if(s instanceof HockeyTeam && s instanceof FootballTeam)


{
System.out.println(s.calculateHockeyScore());
System.out.println(s.calculateFootballScore());
System.out.println(s.findHighestGoalByIndividualInHockey());
System.out.println(s.findHighestGoalByIndividualInFootball());
}
}
catch (NoSuchMethodException ex)
{
System.out.println("No such function is exits");
}
}
}

/////////////////////multi threading///////////////////////
import java.util.Scanner;

class Task1 extends Thread {


static int a = 0;
static int beg = 0;

public void run(){


for(int i=beg;i < a;i++)
Solution.threadArray[i] = i;
}
}

class Task2 extends Thread {


static int a = 0;
static int beg = 0;

public void run(){


for(int i=beg; i< beg + a;i++)
Solution.threadArray[i] = i;
}
}

class Task3 extends Thread{


static int a = 0;
static int beg = 0;
public void run(){
for(int i=beg;i< a + beg;i++)
Solution.threadArray[i] = i;
}
}

public class Solution


{
public static final int[] threadArray = new int[300];

public static volatile String i = 0+"";

public boolean test() throws InterruptedException


{
Task1 task1 = new Task1();
Task2 task2 = new Task2();
Task3 task3 = new Task3();
Thread task2Thread = new Thread(task2);
Thread task3Thread = new Thread(task3);
task1.start();
task2Thread.start();
task1.join();
task2Thread.join();
task3Thread.start();
int first = Task1.a+Task2.a;
int containsSecondThread = Task1.a;
String oneAndTwo = "";
String sizeOfTask1 = "";
for(int i=0;i<first;i++)
{
oneAndTwo += threadArray[i]+" ";
}
for(int i=0;i<containsSecondThread;i++)
{
sizeOfTask1 += threadArray[i]+" ";
}
int begOfTask3 = Task3.beg;
String checkingString = "";
for(int i=begOfTask3;i<threadArray.length;i++)
{
checkingString += i + " ";
}
String task3String = "";
for(int j = begOfTask3;j<threadArray.length;j++)
{
task3String += threadArray[j]+" ";
}
if((!oneAndTwo.contains(begOfTask3+"") &&
sizeOfTask1.contains(Task2.beg+"")) || task3String.equals(checkingString))
{
return true;
}
return false;
}

public static void main(String[] args) throws InterruptedException


{
Scanner sc= new Scanner(System.in);

Solution solution = new Solution();


int one = sc.nextInt();
Task1.a = one;
Task1.beg = 0;
int two = sc.nextInt();
Task2.a = two;
Task2.beg = one;
int three = sc.nextInt();
Task3.a = three;
Task3.beg = one+two;
System.out.print(solution.test());
}
}

You might also like