Showing posts with label Advance programs. Show all posts
Showing posts with label Advance programs. Show all posts

Monday, August 4, 2014

Count number of bits are set to 1

Write a program to count number of bits are set to 1 in an integer.

Armstrong number

Write a program to check given number is armstrong or not.

Prime factors of a number

Write a program in C language to calculate the prime factors of a number.

Monday, January 13, 2014

Java Calculator

Create a java based GUI calculator as shown below ...
Implement only the following functionalities ...
  • Addition
  • Difference
  • Multiplication
  • Division
  • CLR button
  • Back Space button

Friday, January 3, 2014

Snake Game

Snake is an old computer game. There are many versions, but all involve maneuvering a "snake" around the screen, trying to avoid running the snake into itself or an obstacle.
Simulate the game through the application, though it is very simplified version.

Consider a 10 X 10 board/matrix (refer the following diagram, where every integer value is indicating the cell number). The snake move Suppose the snake starts to move from cell number 15. The snake can move to 4 possible directions: north (N), east (E), south (S) and west (W). If the snake moves to N, then it actually moves to cell number 5. If it moves to S, then it actually moves to cell number 25. Similarly if the snake moves to E or W, which means snake is moving to cell number 26 or 24 respectively. So, with every move, the snake covers a cell and consequentially it leaves a trail along the path.

Now consider a sequence of moves, NEEESSWWNNN. That means the snake first moves from its initial position (cell number 15) to cell number 5, then takes a right turn and covers the cell number 6, 7 and 8. After that it takes a down turn and covers 18 and 28, before it takes a left turn and covers cell number 27 and 26. At last it takes again upward turn and covers cell number 16 first and meets the same trail, i.e., cell number 6. It means the snake has run on to itself. In this case, the snake made 9 successful moves and on the 10th move it runs into itself.
Again consider the sequence of moves, SSEEEEEEEE. That means from starting position (cell number 15, the snake moves downward till cell 35 and then takes a right turn to cover cell number 36 to 40, before it runs out of board. Before running out of board it made 7 moves.



Again consider sequence of moves: WWSSSEEEESSSS. That means the snake first made a left run from start position (cell number 15) and covered cell number14 and 13 and then a downward move and continued till cell number 43. Then it took a right turn to go till cell number 47 and again moved downwards and continued till cell number 87. This time the snake neither did run onto itself nor run out of board. It completed all the 13 moves successfully.


Description: Complete the given method to return the number of moves as well as the result of the moves (i.e., “SUCCESS” OR “RANOUTOFBOARD” OR “RANONTOITSELF”) for a given sequence of moves in string format.

Input: Start position as integer value and sequence of moves as string value

Output: Number of moves (made successfully or made before it ran out of board or before it ran onto itself) along with the result of the moves (i.e., “SUCCESS” OR “RANOUTOFBOARD” OR “RANONTOITSELF”).

UTC
Input
Output
UTC04_01
53 and SSSSEEENNEEEEESS
{13, RANOUTOFBOARD }
UTC04_02
3 and SSSSEESSSSWNNNNNNNN
{14, RANONTOITSELF}
UTC04_03
15 and WWSSSEEEESSSS
{13, SUCCESS}

Monday, December 30, 2013

Consecutive Characters count

Complete the method to print the consecutive characters and the number of times appearing in a String.
public static void PrintConsecutiveCharacters(string input)
{ 
   //write code
}
Input & Output: 
UTC
Sample Input
Sample Output
01
“I saw a CD player and a modem in ccd”

CD 2
DE 1 
02
“Student List do not exist in system”


ST 4
DE 1
NO 1

Wednesday, November 27, 2013

Dot Net: Collections

Count the frequency of different words in a sentence.

Objective:
To choose appropriate collection class for storing key/value pair.

Problem Statement:
Write a program to create a list of words present in a sentence passed from command line. The list also contains count of the appearance of each word in that sentence. The program has to display the words in sorted order and its frequency.

If the input is: “DotNet is technology and DotNet is interoperable and DotNet is simple”.


Output should be:  [and = 2, DotNet =3, interoperable = 1, is = 3, simple =1, technology=1]

Monday, November 25, 2013

Dot Net: Matrix Arrangement

Write a function to return an array where the midst position contains the smallest value followed by the next smallest value on the right of the midst position, followed by the next smallest value to the left of the midst position and the rest of numbers continue in this format.

Function signature:
public static int[ ] ArrangeElements(int[,] inputArray) 
{ 
   // write the code here
}



Saturday, November 23, 2013

Java BufferedReader & StreamTokenizer Example

Write a method that will take a string containing integers and return the sum of the numbers present in the string. For example, given the string "10 2 20 30" should print 62.

Java HashSet Example

Create a class Employee with class members firstName(String), lastName(String) and salary(int).Do the following:

  • Create a HashSet of Employees.
  • Print the employee details.
  • Sort the employees in HashSet by salary and print the result.
  • Print the employee with the least salary.
  • Print the employee with the highest salary.
  • Search for an employee.

Java FileInputStream Example

Write a JAVA Program which reads an input file from the Command Line which contains the numbers sperated by space and find the average for the numbers.

Java File concatenation (Multiple file Handling)

Write a JAVA Program which reads a number of text files from the command line and concatenates the contents of the files into the last file entered on the command line.

Example:
Java Concatenate src1.txt src2.txt src3.txt dest.txt
All the contents of the source files should be concatenated and written in destination file.

Friday, November 22, 2013

Java File write operation from Console

Write a JAVA Program which accepts lines of text from the console until 'stop' is entered and prints the lines of text it read.

Sample Input & Output :
Enter lines of text
Enter 'stop' to quit
---------------------
India's plans to wrap up a quick nuclear deal with Russia
The Prime Minister arrived here yesterday to a red carpet welcome
Top government sources said lawyers of both the sides have to clear the text of the agreement
stop

The lines you entered are :
--------------------------
India's plans to wrap up a quick nuclear deal with Russia
The Prime Minister arrived here yesterday to a red carpet welcome
Top government sources said lawyers of both the sides have to clear the text of the agreement

Monday, November 18, 2013

Java File reading

Write a JAVA Program which reads a text file from the Command Line and prints it to the console.

Java Threads

Write a program using threads which prints the following:

In first thread:0
In Second Thread:0
In Second Thread:1
In first thread:1
In Second Thread:2
In Second Thread:3
In first thread:2
In Second Thread:4
In Second Thread:5
In first thread:3
In Second Thread:6
In Second Thread:7
In first thread:4
In Second Thread:8
In Second Thread:9
End of first thread
End of second thread

Java PriorityQueue Example

Write a program that creates and prints a priority queue of some country names in descending order.

Java HashMap Example (Phone Book)

Implement a PhoneBook using HashMap.
Hint: Create the following classes:

  1. Person Class contains firstName and surName.
  2. PhoneNumber Class contains areaCode and number.
  3. BookEntry contains Person object and PhoneNumber object.
  4. PhoneBook contains a HashMap<Person,BookEntry>.
  5. TestPhoneBook Class contains main() to do the following:

The user should be prompted with the following menu

  • Enter 1 to add a new phonebook entry
  • Enter 2 to find the number for a name.
  • Enter 3 to find name for a number
  • Enter 9 to quit

Anagram

An anagram is a word made by transposing the letters of another word ; for example, "software" is an anagram of "swearoft".Write a program that figures out whether one string is an anagram of another string.

Saturday, November 16, 2013

Java List Example using Comprable class

Create a Student class with name, id and age. Write a program that gets some students from user and then sorts by

  • Ascending order of Name (Use Comparable)
  • Descending order of Name
  • Both age and name.(Use Comparator)

Java HsahMap (Collection) example

Write a program that takes an array of words and does the following:

  • Prints out any duplicate words
  • Prints the number of distinct words
  • Prints the list of the words with duplicates eliminated.

Eg: if the input array = i came i saw i conquered then outputs are

  • Duplicate present: i
  • Number of distinct elements: 4
  • Distinct elements: [saw, came, conquered, i]