Skip to main content

Repotation.com Programming Question in java || Logical Question in Written Test

All Programming Question in Written test 

Repotation.com

===============================================================================================================================================

 Q.1-
============
  Input: 9876565
 Expected Output is: 1
Hint:9+8+7+6+5+6+5=10 =1
 Input is Possitive Number Only.

Coading Part:

      //Q.1
import java.util.Scanner;

class ClassA {  

public static void main(String[] args) 

{

Scanner sc=new Scanner(System.in);

int n=sc.nextInt();

int sum=0,rem=0;

while(true){

sum=0;       

   while(n!=0){       

     rem=n%10;

sum=sum+rem;

n/=10;  

 }  

 if(sum<10){          

   System.out.println(sum); break;

  }

  n=sum;

}

}

}

======================================================================
Q.2-
===========
Input :"for{do{print}}"
Output: balanced
Input:"while{do}a=5}" 
Output:Unbalanced

Coading Part:


//Q.2
import java.util.*;
class ClassB 
{
public static void main(String[] args) 
{
Scanner sc=new Scanner(System.in);
String s=sc.next();
int count=0;
for(int i=0;i<s.length();i++){
          if(s.charAt(i)=='{' || s.charAt(i)=='}'){
           count++;
  }
}
if(count%2==0)
  
System.out.println("Balanced");
else
System.out.println("UnBalanced");
}
}

======================================================================

Q.3-
============
 Input:"Hello","world","it",1,2,3
output:("hello",1),("world",2),("it",9)
input:"x","y","z",3,5,7
output:("x",9),("y",25),("z",49)
Hint: Square of the last three in the input list

Coading Part:

  //Q.3

import java.util.*;
class  ClassD 
{
public static void main(String[] args) 
{
Scanner sc=new Scanner(System.in);
String s=sc.next();
String s1[]=s.split(",");
int a=s1.length/2;
for(int i=0;i<s1.length/2;i++){
int n=Integer.parseInt(s1[a]);
          System.out.print("("+s1[i]+","+n*n+")");
  a++;
  if(i<s1.length-1)){
            System.out.print(",");
  }
  
}
//System.out.println(Arrays.toString(s1));
}
}

========================================================================
Q.4-
=============
 Input:"/foo/bar"
Output:directry bar resides under foo  resides under.
input:"/blah/bar/name.txt"
Output: file name.txt resides under bar resides under blah resides under
input:/test
output:directory test resides under root

Hint: file has a three character extension.

Coading Part:
//Q.4
import java.util.*;
class ClassE 
{
public static void main(String[] args) 
{
Scanner sc=new Scanner(System.in);
String s=sc.next();
String s1[]=s.split("/");
        if(s1.length==2){
System.out.print("Directry ");
           for(int i=s1.length-1;i>0;i--){
            System.out.print(" "+s1[i]+" Reside Under Root");
}
}
else if(s1.length==4){
System.out.print("File");
          for(int i=s1.length-1;i>0;i--){
            System.out.print(" "+s1[i]+" Reside Under ");
}
}
else{
           System.out.print("Directory");
           for(int i=s1.length-1;i>0;i--){
            System.out.print(" "+s1[i]+" Reside Under ");
}
}
System.out.println();
}

}




======================================================================
Q.5-
=============
Plaintext:a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z
Chipertext:B,C,D,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,X,A

INput:"hello"
Output:IFMMP
input:LMNOP
output:klmno

Coading Part:

//Q.5
import java.util.*;
import java.io.*;
class ClassC 
{
public static void main(String[] args) 
{
Scanner sc=new Scanner(System.in);
char arr1[]=new char[26];
char arr2[]=new char[26];
int a=97;
for(int i=0;i<arr1.length;i++){
          arr1[i]=(char)a++;
}
//second Arrays
int b=66;
for(int i=0;i<arr1.length-1;i++){
          arr2[i]=(char)b++;
}
arr2[25]='A';

       String s=sc.next();
  /* if(s.isLowerCase()){
System.out.println(s);   
   }*/
   String s1="";
   //check given string is lower cse or uppercase
        char ch=s.charAt(0);
        if(Character.isLowerCase(ch)){
   
   for(int j=0;j<s.length();j++){
         for(int i=0;i<arr1.length;i++){
                if(s.charAt(j)==arr1[i]){
                   s1=s1+arr2[i];   
        }
   
         }
       }
    }
  else{
        
  for(int j=0;j<s.length();j++){
         for(int i=0;i<arr2.length;i++){
                if(s.charAt(j)==arr2[i]){
                   s1=s1+arr1[i];   
        }
   
         }
       }
  }
System.out.println(s1);
}
}

******************************************************************************
All the best enjoy this Question and prepared all this question in java.
Contact:9131169055
email ID:pk22cs@gmail.com
Any Other information than contact with me.





Comments

Popular posts from this blog

Generate Documentation for Spring Boot API with swagger and Open API 3

 ðŸ˜‚ How to Generate Documentation for Spring Boot API project Make sure your Project having a swagger or open API 3 Dependency then only you get proper Documentation for your Service. ---------------------------------------------------------------------------- Every method or API above you have to Write Like that then only you get proper Documentation If you do everything in your Application and Run your Application and go to browse and search. . http://localhost:8080/v3/api-docs/ if you want to learn more go with this one.  Open API-3   1. For Return List of Object then you have to use this API operation  @Operation(summary = "This will fetch List of Patient Detailas base on Hospital Name") @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "Successfully fetch All Patient Details from Database ", content = {  @Content(mediaType = "application/json" ,array = @ArraySchema(schema =@Schema(implementation =PatientDe...

Top 10 website for IT Job | Software developer job apply | Job platfrom to apply Job | Software Developer Job .

                        Top 10 website for IT Job If you want a job in an IT or software company then this blog for you. I will give you the top 10 websites where you can apply the job for the software industry. It is a very good website to apply for a job for a software company.

#FibonacciNumberSeries Write a program of Fibonacci Number Series|| Fib...

Fibonacci Number Series ============================================ 0 1 1 2 3 5 8 13............. a=0; b=1; i=2; printf(a,b); while(i<=n){ c=a+b; printf(c); a=b; b=c; i++; } =========================================================================== import java.util.Scanner; class Fibonacci { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int a=0,b=1,c; System.out.print(a+" "+b); for(int i=2;i