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();
}
}
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
Post a Comment