/**
* Write a program to accept a number from the command line and determine whether
* it is an odd or an even number
*/
class OddEven
{
/**
* excution begin from here
* @param args : command line argument
*/
public static void main(String[] args)
{
if(args.length!=1)
{
System.out.println("Invalid Argument!!!");
return;
}
byte res=isNoOdd(args[0]);
if(res==0)
System.out.println(args[0] + " is Invalid Input!!");
else if(res==1)
System.out.println(args[0] + " is odd");
else if(res==2)
System.out.println(args[0] + " is even");
}
/**
* check if given no is odd or not
* @param no : input number
* @return : 0 for Error or Zero
* 1 for odd
* 2 for even
*/
public static byte isNoOdd(String no)
{
try
{
int number=Integer.parseInt(no);
if(number==0)
return 0;
if(number%2==0)
return 2;
else
return 1;
}
catch(Exception e)
{
//System.out.println("Error Occured!!");
//e.printStackTrace();
return 0;
}
}
}
Free CoreJava Programs Source codes | Examples | Video Tutorials Download
Blog Archive
-
▼
2009
(48)
-
▼
January
(37)
- Program to implement Method overloading and overri...
- How to access a hidden variable in corejava
- Variable Hiding In Java
- Demonstration of A Class Inheritance Heirarchy
- Difference Between equals() and ==
- Copy One Object Array To Another Object Array
- Program For Type Casting
- Program To Print User name, OS name, User directory
- StringIndexOutOfBoundsException Program
- Random String Display From Array Program
- Open Windows Notepad From Java
- Generate Random Numbers
- NullPointerException Program
- NegativeArraySizeException Program
- Display Memory Size Before & After Garbage Collect...
- Minimum and Maximum Values Of Integral Data Types
- Class Declaration Demo
- Print 1-50 Numbers In Descending Order
- Prints Time Duration Of Execution
- toString() Overriding Program
- Power Function
- ArithmeticException Program
- Vowel Or Consonant Check
- Vowel Or Consonant Check
- Print All Occurrences And Total Number Of Occurrences
- Integer Array Program
- Reverse String Using Command Line Arguments
- Count Lowercase, Digits and Uppercase Letter from ...
- Array Transposition
- Change Case Of Alphabet Program
- Add N Numbers Program
- Add Two Numbers Program
- Odd Even Find Program
- UserNamePassword Validation Program
- Print Different Data Types Values Program
- Program For Print Welcome Message
- Print Welcome Message
-
▼
January
(37)
My Blog List
Tuesday, January 20, 2009
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment