Jan 04

Top 20 string coding interview questions in java?

String coding interview questions in java

1)      Write a java program to reverse string in java without using reverse() method of string api?

2)      Write a program to check if a string is palindrome or not?

3)      Write a program to count number of occurrences of characters in String in java?

4)      How to split strings in java?

5)      How to convert string to date in java?

6)      How to convert String to int in java? Continue reading

Jun 04

Write a java program to accept 3 numbers and print the max value

Write a program to accept 3 numbers and print the maximum value

This program demonstrates to find greatest of 3 numbers .

[code lang=”java”]public class Greatest
{
public static void main(String[] args)
{
greatestNumber(3, 100, 1);

greatestNumber(111, 12, 5);
}

private static void greatestNumber(int num1, int num2, int num3) {

if(num1>num2)
{
if(num1>num3)
{
System.out.println("num1 is greater "+num1);
}
else
{
System.out.println("num3 is greater "+num3);
}
}
else
{
if(num2>num3)
{
System.out.println("num2 is greater "+num2);
}
else
{
System.out.println("num3 is greater "+num3);
}
}
}
}[/code]

Output

num2 is greater 100
num1 is greater 111

 

May 29

Write a java program to check whether a number is +ve or -ve?

[code lang=”java”]package programminginterview;

public class NumberCheckDemo {
public static void main(String[] args) {

check(5);

check(-1);
}

private static void check(Integer number) {
if(number<0)
{
System.out.println(number + " is negative ");
}
else
{
System.out.println(number + " is positive ");
}

}

}[/code]

Output

5 is positive
-1 is negative