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...

#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

In a new programming language how can store multiple types of data in a single variable OR is it possible how can store multiple types of data in a single variable in programming langauge

In a new programming language how can store multiple types of data in a single variable  OR is it possible how can store multiple types of data in a single variable in a programming language Here In a new programming language how can store multiple types of  data in a single variable   help you make the new  concepts, you are learning a programming  Languages really very important: Ideally Yes. If you create an Array of objects. Then it's possible to store any data type with it as an object is the base class. ArrayList can hold multiple types of data, but array doesn't. Variables Variables can be thought of as ‘containers’ for data. Each variable has to  have a unique name, so that you can refer back to it in the program. By using variables, we can refer to values that have not yet been defined.  For example, we can refer to the speed of the ball in different parts of the  game code, but calculate the ball speed later based on different input...