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

May 07

How to convert lowercase letters to uppercase and viceversa in java?

Converting UpperCase letters to lowercase and  converting lowercase Letters to uppercase in java

To convert letters in uppercase to lowercase and viceversa we have a method in Stringutils class called swapcase which does this.

Ex: StringUtils.swapCase(“java-interview-questions”); returns

JAVA-INTERVIEW-QUESTIONS

Syntax : public static String swapCase(final String str) ;

SwapCase accepts String as argument and returns String after conversion. Continue reading