Showing posts with label Java. Show all posts
Showing posts with label Java. Show all posts
Monday, January 13, 2014
Saturday, November 23, 2013
Java decimal numbers to comma-punctuated numbers Conversion
Write a method to convert strings containing decimal numbers into comma-punctuated numbers, with a comma after every third digit from the right.For example, given the string 1234567 , the method should return 1,234,567
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 Temperature conversion ( JOptionPane Example )
Write a program that creates a Celsius Converter Application.The application should accept temperature in Celsius and display temperature in Farenheit
[Conversion Formula: FarenHeitTemp = CelsiusTemp * 1.8 + 32].
[Conversion Formula: FarenHeitTemp = CelsiusTemp * 1.8 + 32].
Java String to Character array ( toCharArray() method )
Write a JAVA Program which accepts text of words seperated by commas and gives the output of words printed on seperated lines with commas removed.
Monday,Tuesday,Wednesday,Thursday,Friday,Sunday
Monday
Tuesday
Wednesday
Thursday
Friday
Sunday
Sample Input & Output:
Enter the string to parseMonday,Tuesday,Wednesday,Thursday,Friday,Sunday
Monday
Tuesday
Wednesday
Thursday
Friday
Sunday
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.
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
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
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 HshMap using StringTokenizer
Write a program that gets an array of words and does the following:
Here's a sample run assuming the array of words as {i , came , i , saw , i , conquered}
came : 1
conquered : 1
i : 3
saw : 1
[came, conquered, i, saw]
[1, 1, 3, 1]
Note: Print in the same order as shown above.
- Prints each word and it's frequency
- Prints only the words
- Prints only the frequency of all words
Here's a sample run assuming the array of words as {i , came , i , saw , i , conquered}
came : 1
conquered : 1
i : 3
saw : 1
[came, conquered, i, saw]
[1, 1, 3, 1]
Note: Print in the same order as shown above.
Java HashMap Example (Phone Book)
Implement a PhoneBook using HashMap.
Hint: Create the following classes:
The user should be prompted with the following menu
Hint: Create the following classes:
- Person Class contains firstName and surName.
- PhoneNumber Class contains areaCode and number.
- BookEntry contains Person object and PhoneNumber object.
- PhoneBook contains a HashMap<Person,BookEntry>.
- 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 Map Example
Write a program that gets an array of words and does the following:
Here's a sample run assuming the array of words as {i , came , i , saw , i , conquered}
Note: Order doesn't matter in any of the above outputs.
- Prints each word and it's frequency
- Prints only the words
- Prints only the frequency of all words
Here's a sample run assuming the array of words as {i , came , i , saw , i , conquered}
- saw : 1
- came : 1
- conquered : 1
- i : 3
- [sa, cam, cons, i]
- [1, 1, 1, 3]
Note: Order doesn't matter in any of the above outputs.
Java HsahMap (Collection) example
Write a program that takes an array of words and does the following:
Eg: if the input array = i came i saw i conquered then outputs are
- 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]
Java StringBuilder Example
Write a method ..
public static int[] append(String[] a,String[] b)
that appends one array(of Strings) to another.
For example, if
a ={qqq www eee}
b ={ aaa, sss, ddd}
result ={qqq, www, eee, aaa, sss, ddd}
public static int[] append(String[] a,String[] b)
that appends one array(of Strings) to another.
For example, if
a ={qqq www eee}
b ={ aaa, sss, ddd}
result ={qqq, www, eee, aaa, sss, ddd}
Java StringBuilder class
Write a program that prompts the user to enter a String and prints whether it is a paliandrome or not.Use StringBuilder class.
Subscribe to:
Posts (Atom)
