Write a program to to calculate string palindrome.
Showing posts with label Simple programs. Show all posts
Showing posts with label Simple programs. Show all posts
Sunday, August 24, 2014
Tuesday, August 5, 2014
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.
Calculate daily expenditure if monthly expenditure is given
Write a program to calculate daily expenditure if monthly expenditure is given using loop.
Monday, December 30, 2013
Sort Names by First Name
Names are stored in the pattern
last name first pattern [lastName, firstName].
For example given the name
“Sharma, Rakesh”, “Rakesh” is first name and “Sharma” is last name.
Complete the method provided to
return the collection of strings sorted based on their first name.
Method:
Sample Input & Output:
public static String[ ] SortByFirstName(string[ ] names)
{
// code here
}
UTC
|
Sample Input
|
Sample Output
|
01
|
“Sharma,
Rakesh”, “Patil, Parthiv”, “Gowda, Anil”,
“Prasad,
Vishnu”, “Khan, Amir”
|
“Khan,
Amir”, “Gowda, Anil”, “Patil, Parthiv”, “Sharma, Rakesh”, “Prasad, Vishnu”
|
02
|
“Krishna,
Gopal”, “Page,
Larry”,
“King, Gavin”,
“Swamy,
Krishna”
|
“King,
Gavin” , “Krishna, Gopal”, “Swamy, Krish-na”, “Page, Larry”
|
Triplets
Triplets are a set of three
similar things.
Complete the function to print
all the triplets such that A+B = C
public static void PrintTriplets(int[ ] data)
{
//write code here
}
Input & Output
UTC
|
Sample Input
|
Sample Output
|
01
|
data
= {2,3,4,5,7}
|
<2,3,5>
<2,5,7>
<3,4,7>
|
02
|
array
= {1,2,3,4,5,7,9}
|
<1,2,3>
<1,3,4>
<1,4,5>
<2,3,5>
<2,5,7>
<3,4,7>
<4,5,9>
|
Friday, December 27, 2013
Sum of consecutive elements in a subsequence
Complete the method to find the minimal length of the sub sequence of consecutive elements of the sequence, sum of which is greater or equal to the specified number.
Example:
If the specified number is 15 in the sequence
5 + 1 + 3 + 5 + 10 > 15 (length is 5)
1+3+5+10 >= 15 (length is 4)
3+5+10 >= 15 (length is 3)
5 + 10 >= 15 (length is 2)
10 + 7 >=15(length is 2)
There is no element in the array whose value is >= 15 and hence the minimal length is 2
Example:
| 5 | 1 | 3 | 5 | 10 | 7 | 4 | 9 | 2 | 8 |
If the specified number is 15 in the sequence
5 + 1 + 3 + 5 + 10 > 15 (length is 5)
1+3+5+10 >= 15 (length is 4)
3+5+10 >= 15 (length is 3)
5 + 10 >= 15 (length is 2)
10 + 7 >=15(length is 2)
There is no element in the array whose value is >= 15 and hence the minimal length is 2
public static int FindMinimalLength(int[] array, int value)
{
//write code here
}
| UTC | Sample Input | Sample Output |
| 01 | array = {5,1,3,5,10,7,4,9,2,8}
value = 15 |
2 |
| 02 | array = {1,2,3,4,5}
value = 11 |
3 |
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 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
Saturday, November 16, 2013
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}
Subscribe to:
Posts (Atom)