Interviews Questions, Algorithms, Aptitude, C Interview Program, C Theory Question, Aptitude Tricks, Test Series,

Tuesday, 12 March 2019

Aptitude Hack#17(12-3-19)

Question:
A boat covers a certain distance downstream in 1 hour, while it comes back in 1.5 hours. If the speed of the stream be 3 Kmph, what is the speed of the boat in still water?

A. 12 kmph
B. 13 kmph
C. 14 kmph
D. 15 kmph
 E.None of these


Monday, 11 March 2019

Aptitude Hack#16(11-3-19)

Question:
The ratio of two numbers is 3 : 4 and their H.C.F. is 4. Their L.C.M. is:
A. 12     
B. 16
C. 24
D. 48



Sunday, 10 March 2019

Aptitude Hack#15(10-3-19)

Question:
Find the sum of the expression

A)7
B)8
C)9
D)10

Saturday, 9 March 2019

Aptitude Hack#14(9-3-19)

Question:
103 x 103 + 97 x 97 = ?
A)  21348
B) 20018
C) 19648
D)21428


Friday, 8 March 2019

Sixth Week Term Work Program 2 (Arraylist)

Question:
Post Graduate course of CSE department can accommodate a maximum of 20 students. Each
PG student in the department is identified by his/her Roll No, USN, Name, Semester and
Mobile Number. Using the appropriate Collection class, write a Java Program to simulate the
following scenarios:
a. On request, the capacity got increased from 20 to 25.
b. Only 10 students enroll for the course.
c. Four students from Roll No.s 3 – 6 voluntarily un-enroll from the course.
d. After a month, six more students get enrolled in the course.

e. Print the information of all the students currently enrolled in the course.

Solution:

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

class Student{
Scanner in=new Scanner(System.in);
int Rollno;
String usn;
String Name;
int sem;
String Mobileno;
Student() {
System.out.print("Enter The Roll No:");
Rollno=in.nextInt();
System.out.println();
System.out.print("Enter The USN:");
usn=in.next();
System.out.println();
System.out.print("Enter The Name:");
Name=in.next();
System.out.println();
System.out.print("Enter The Sem");
sem=in.nextInt();
System.out.println();
System.out.print("Enter The MobileNo:");
Mobileno=in.next();
System.out.println();

}
Student(String name, int Rollno, String Mobile, String Usn, int sem)
{
this.Name=name;
this.Rollno=Rollno;
this.Mobileno=Mobile;
this.usn =Usn;
this.sem = sem;

}
public String getName() 
{
return Name;
}


public int getRollno() 
{
return Rollno;
}
public String getMobile() 
{
return Mobileno;
}

public String getUsn() 
{
return usn;
}


public int getSemester() 
{
return sem;
}

}
class Course extends Student
{
String course;


Course(String name, int Rollno, String Mobile, String Usn, int sem) 
{
super(name, Rollno, Mobile, Usn, sem);
System.out.println("Enter Course Name:");
course = in.next();


}
public String getCourse() 
{
return course;
}

public void setCourse(String course) 
{
this.course = course;
}
}
public class Pgstudent {
static Scanner in=new Scanner(System.in);
public static void main(String[] args) {
int choice;
int i=0,size=20;
List<Student> studentsList = new ArrayList<Student>(size); // array list to store user input For Student
List<Course> studentsListCourse = new ArrayList<Course>(size); // array list to store user input For Course

while (true) {
System.out.println("\n\n*******************STUDENT RECORD*******************\n");
System.out.println("1. Increase the Capacity");
System.out.println("2. Enter Student Record");
System.out.println("3. Display Record");
System.out.println("4. Enroll Course");
System.out.println("5. DeRoll Course");                                                                        
System.out.println("6. Display Enrolled Student Details");
System.out.println("7. Exit");
System.out.println("Enter choice: ");
choice = in.nextInt();
switch (choice) {
case 1:size=25;
System.out.println("Size Changed to 25");
break;

case 2: if(i<size){

System.out.println("============" + "=================");
System.out.println("Students " + "Personal Details");
System.out.println("============" + "=================");
Student student = new Student();

studentsList.add(student); // add student
i++;
}

else {
System.out.println("U Cannot Store The Student Record");
}
break;
case 3:
for (int j = 0; j < studentsList.size(); j++)
{

Student st = studentsList.get(j);

System.out.println("Information of Student : " + st.getRollno()); 
System.out.println("");
System.out.println("Name: " + st.getName() + " - Roll No: "+st.getRollno() + " - Mobile No: " + st.getMobile() + " - Student USN: " + st.getUsn() + " - Semester: " + st.getSemester());
System.out.println("");
}

break;
case 4:
System.out.println("============ENROLL" + "=================");
System.out.println("============" + "=================");
System.out.println("Enter the Roll NO");
int Froll=in.nextInt(),flag=0;
for (int j = 0; j < studentsList.size(); j++)
{
Student ct = studentsList.get(j);
if(ct.getRollno()==Froll) {
flag=1;
Course course=new Course(ct.getName(),ct.getRollno(), ct.getMobile(),ct.getUsn(),ct.getSemester());
studentsListCourse.add(course); // add student

}
}
if(flag==0) {
System.out.println("No Student Exist With Given RollNo Sorry Try Again");
}

break;
case 5:
System.out.println("Enter the Roll NO");
int Roll=in.nextInt(),flag1=0;
for (int j = 0; j < studentsListCourse.size(); j++)
{

Course ct = studentsListCourse.get(j);
if(ct.getRollno()==Roll) {
flag1=1;
System.out.println("Information of Student : " +ct.getRollno()); 
System.out.println("");
System.out.println("Name: " + ct.getName() + " - Roll No: "+ct.getRollno() + " - Mobile No: " + ct.getMobile() + " - Student USN: " + ct.getUsn() + " - Semester: " + ct.getSemester()+" -Course: "+ct.getCourse());
System.out.println("");
studentsListCourse.remove(ct);
}
}
if(flag1==0) {
System.out.println("Enter Roll No Did Not Enroll Only");
}


break;
case 6:
for (int j = 0; j < studentsListCourse.size(); j++)
{

Course ct = studentsListCourse.get(j);
System.out.println("Information of Student : " + (j + 1)); 
System.out.println("");
System.out.println("Name: " + ct.getName() + " - Roll No: "+ct.getRollno() + " - Mobile No: " + ct.getMobile() + " - Student USN: " + ct.getUsn() + " - Semester: " + ct.getSemester()+"-Course:"+ct.getCourse());
System.out.println("");

}
break;
case 7:
System.out.println("THANKS FOR VISTING");
System.exit(0);
break;
default:
System.out.println("Enter A Valid Option");

}
}   
}

}



Credit: Shubham

Aptitude Hack#13(8-3-19)

Question:
Largest five digit number exactly divisible by 39 is:
 A) 99979
B) 99956
C) 99989
D) 99996


Thursday, 7 March 2019

IA -1 Q 1 B)

Question:
Explain different ways to create a thread in java with a relevant example.


Solution:
Java lets you create a thread in the following two ways:- 
By implementing the Runnable interface.
By extending the Thread
Runnable Interface
The easiest way to create a thread is to create a class that implements the Runnable interface.
To implement Runnable interface, a class need only implement a single method called run( ), which is declared like this:
public void run( )
Inside run( ), we will define the code that constitutes the new thread
Example:
public class MyClass implements Runnable {
public void run(){
System.out.println("MyClass running");
   } 
}
To execute the run() method by a thread, pass an instance of MyClass to a Thread in its constructor(A constructor in Java is a block of code similar to a method that’s called when an instance of an object is created). Here is how that is done:
Thread t1 = new Thread(new MyClass ());
t1.start();
When the thread is started it will call the run() method of the MyClass instance instead of executing its own run() method. The above example would print out the text “MyClass running“.
Extending Java Thread
The second way to create a thread is to create a new class that extends Thread, then override the run() method and then to create an instance of that class. The run() method is what is executed by the thread after you call start(). 
Example:
public class MyClass extends Thread {
     public void run(){
     System.out.println("MyClass running");
         }
     }
To create and start the above thread you can do like this:
 MyClass t1 = new MyClass ();
 T1.start();
When the run() method executes it will print out the text “MyClass running“.

Sixth week Term Work Program 4

Question:
Write a Java program to that simulates copy command.

Solution:
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

// file streams (STREAMS)
public class program {
public static void main(String[] args)  {
FileInputStream fin=null;
FileOutputStream fout=null;
int num;
try {
fin=new FileInputStream(args[0]);
fout=new FileOutputStream(args[1]);
while((num=fin.read())!=-1) {
fout.write(num);
System.out.print((char)num);
}

}catch(Exception e) {
e.printStackTrace();

}
finally {
System.out.println();
if(fin!=null)
try {
fin.close();
} catch (IOException e) {
e.printStackTrace();
}
if(fout!=null)
try {
fout.close();
}catch(Exception e) {
e.printStackTrace();

}
}

}

}

Output:
//Command Line Argument
123456789000111 My name Khan And I am not A hero.

Sixth Week Term Work Program 3 [ IA-1 2 B) ]

Question:
Write a Java program the implements a generic sort method using any of the sorting techniques.

public class GenericSorting {
//Modification: Sorting Wrt To String Length.
public static <T extends Comparable<T>> void sortingMethod1(T array[])
   {
   int i,j,n;
   n=array.length;
   for(i=0;i<n;i++)
   for(j=0;j<n-i-1;j++)
   if((((String) array[j]).length())>((String) array[j+1]).length())
   {
   T temp;
   temp=array[j];
   array[j]=array[j+1];
   array[j+1]=temp;
   }
   
   for(T element: array)
  System.out.printf("%s ", element);
   System.out.println();
   }

   public static <T extends Comparable<T>> void sortingMethod(T array[])
   {
   int i,j,n;
   n=array.length;
   for(i=0;i<n;i++)
   for(j=0;j<n-i-1;j++)
   if(array[j].compareTo(array[j+1])>0)
   {
   T temp;
   temp=array[j];
   array[j]=array[j+1];
   array[j+1]=temp;
   }
   
   for(T element: array)
  System.out.printf("%s ", element);
   System.out.println();
   }
   public static void main(String args[])
   {
   Integer i[]={3,2,1,7,6};
           String s[]={"pear","orange","apple"};
   sortingMethod(i);
 sortingMethod(s);
 
 System.out.println("\nSorting As per String Length");
 sortingMethod1(s);
 
   }
}

Output:
1 2 3 6 7 
apple orange pear 

Sorting As per String Length

pear apple orange 

Blue Marked Are Modification Asked By Ma'am In B1 Batch.

Sixth Week Term Work Program 1 [ IA-1 3 A) ]

Question:
 Write a Java program to create the below-mentioned Student record using appropriate
Collection class to perform the following operations on a single student:
a. Add a student
b. Display all the details of the student
c. Delete/remove student record
Members of the class Student is given below:

Student
name
USN
division
CGPA


Solution:
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Scanner;
public class SingleStudentRecord {
 ArrayList<Comparable> stud=new   ArrayList<Comparable>(4);
static Scanner in=new Scanner(System.in);
public void EnterRecord() {
System.out.print("Enter The Name:");
stud.add(in.next());
System.out.println();
System.out.print("Enter The USN:");
stud.add(in.next());
System.out.println();
System.out.print("Enter The Division:");
stud.add(in.next());
System.out.println();
System.out.print("Enter The CGPA:");
stud.add(in.nextFloat());
System.out.println();
}
public void DisplayRecord() {
Iterator<Comparable> itr=stud.iterator();
while(itr.hasNext()) {
System.out.println(itr.next());
}        

}
public void DeleteRecord() {
System.out.println("Deleted The Student Record");
stud.removeAll(stud);
}
public static void main(String[] args) {
SingleStudentRecord s=new SingleStudentRecord();
int choice;
int i=0;
    while (true) {
        System.out.println("\n\n*******************STUDENT RECORD*******************\n");
        System.out.println("1. Enter Student Record");
        System.out.println("2. Display Record");
        System.out.println("3. Delete Record");
        System.out.println("4. Exit");
        System.out.println("Enter choice: ");
        choice = in.nextInt();
        switch (choice) {
        case 1: if(i==0)
        {
        s.EnterRecord();
        i++;
        }
        else {
        System.out.println("U Can Store Only One Student Record");
        }
                break;
        case 2:
        if(i==1)
        {
        s.DisplayRecord();
        }
        else {
        System.out.println("No Record Exists");
        }
        break;
        case 3:if(i==1) {
        s.DeleteRecord();
        i--;
        }
        else {
        System.out.println("No Record To delete");
        }
        break;
        case 4:
        System.out.println("THANKS FOR VISTING");
        System.exit(0);
        break;
        default:
        System.out.println("Enter A Valid Option");

}
}
}
}

Output:

**********STUDENT RECORD**********

1. Enter Student Record
2. Display Record
3. Delete Record
4. Exit
Enter choice: 
1
Enter The Name:Amit

Enter The USN:2Sd16cs012

Enter The Division:B

Enter The CGPA:8.4


Enter choice: 
2
Amit
2Sd16cs012
B
8.4


Enter choice: 
3
Deleted The Student Record


Enter choice: 
4
THANKS FOR VISTING


Aptitude Hack#12(7-3-19)


 Question:

Which one is NOT divisible by 3?

A) 5271
B) 6291
C) 4372
D) 8952


Wednesday, 6 March 2019

Aptitude Hack#11(6-3-19)


Question: (1015)2 = ?
A) 1040125
B) 1030225
C) 1050125
D) 1025125


Tuesday, 5 March 2019

Aptitude Hack#10(5-3-19)

Question:
Given the sequence of terms, AD CG FK JP, the next term is

 A) OV

B) OW

C) PV

D)PW



Monday, 4 March 2019

Aptitude Hack#9(4-3-19)

Question:
An automobile plant contracted to buy shock absorbers from two suppliers X and Y. X supplies 60% and Y supplies 40% of the shock absorbers. All shock absorbers are subjected to a quality test. The ones that pass the quality test are considered reliable. Of X’s shock absorbers, 96% are reliable. Of Y’s shock absorbers, 72% are reliable. The probability that a randomly chosen shock absorber, which is found to be reliable, is made by Y is

A)0.288
B)0.334
C)0.667
D)0.720



Sunday, 3 March 2019

Aptitude Hack#1 (24-2-19)

Question:

There are 25 horses among which you need to find out the fastest 3 horses. You can conduct race among at most 5 to find out their relative speed. At no point, you can find out the actual speed of the horse in a race. Find out how many races are required to get the top 3 horses.


A) 5

B) 6 

C) 7

D) 8   


Aptitude Hack#4(27-2-19)

Question:

Three friends started running together on a circular track at 8:00:00 am. Time taken by them to complete one round of the track is 15 min, 20 min, 30 min respectively. If they run continuously without any halts, then at what time will they meet again at the starting point for the fourth time?
A )  8:30:00 am
B )  9:00:00 pm
C  )12:00:00 pm
D )12:00:00 am


Aptitude Hack#5(28-2-19)

Question:

It was Sunday on Jan 1, 2006. What was the day of the week Jan 1, 2010?

A.        Sunday
B.        Saturday
C.        Friday
D.        Wednesday



Aptitude Hack#6(1-3-19)

Question:

Suppose a fair six-sided dice is rolled once. If the value on the dice is 1, 2, or 3, the die is rolled a second time. What is the probability that the sum total of values that turn up is at least 6?

A 10/21
B 5/12
C 2/3
D 1/6

Aptitude Hack#7(2-3-19)

Question:

The cost function for a product in a firm is given by 5q2, where q is the amount of production. The firm can sell the product at a market price of Rs 50 per unit. The number of units to be produced by the firm such that the profit is maximized is

A)5
B)10
C)15
D)25



Aptitude Hack#8(3-3-19)

Question:

A political party orders an arch for the entrance to the ground in which the annual convention is being held. The profile of the arch follows the equation y = 2x – 0.1x2 where y is the height of the arch in meters. The maximum possible height of the arch is

A)8 meters
B)10 meters
C)12 meters
D)14 meters