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

Sunday, August 24, 2014

String palindrome

Write a program to to calculate string palindrome.

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.

Add between any two numbers using loop

Write a program to add between any two numbers using loop.

Palendrome number

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

Armstrong number

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

Strong number or not

Write a program to check the number is strong number or not.

Reverse a number

Write a program to to reverse a number.

Sum of digits of a number

Program to calculate the sum of digits of a number.

Factorial of a number

Program to calculate the factorial of a number:

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:
public static String[ ] SortByFirstName(string[ ] names)
{ 
   // code here 
}
Sample Input & Output: 
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:

 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].

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.

Sample Input & Output:

Enter the string to parse
Monday,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}