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

How to Send OTP in Mobile Number | login with OTP mobile Number | How to send OTP in mobile no with Spring Boot APP

   ðŸ˜‚               Login with Mobile Number OTP ---------------------------------------------------------------------------- If you want to develop a project to log in with OTP mobile Number in Spring Boot Applications then this post for you. In this post, I am going to use some other service to send the OTP in mobile number. we have to use it in this project spring boot. we are going to use Twilio to send SMS. we are going to use a web socket to send the data from the browser to the SMS gateway. Oracle Database for store the user details. <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> <version>2.3.3.RELEASE</version> </dependency> <dependency> <groupId>com.twilio.sdk</grou

Spring Boot With MySQL Database connection with Examples | MySQl Database Configuration with Spring Boot Projects

 ðŸ˜ƒ MySQL Database Configuration with Spring Boot Projects  In this article, we are going to introduce How to connect MySQL Database with the Spring Boot project. pom.xml   <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <scope>runtime</scope> <optional>true</optional> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <scope>runtime</scope> </dependency> <dependency> <groupId>org.projectlombok</gro

How can we create Auto generated field or ID for mongodb using spring boot

😂 How can we create an Auto-generated field or ID for MongoDB using spring boot? First Create One Application Like Mongodb_sequence-id-generator Pom.XML <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-mongodb</artifactId> </dependency> <dependency> <groupId>de.flapdoodle.embed</groupId> <artifactId>de.flapdoodle.embed.mongo</artifactId> </dependency> User.java package com.app; import org.springframework.data.annotation.Id; import org.springframework.data.annotation.Transient; import org.springframework.data.mongodb.core.mapping.Document; @Document(collection = "users_db") public class User { @Transient public static final String SEQUENCE_NAME = &