How to find the given number is even or odd in java
public class TestEx
{
public static void main(String args[])
{
System.out.println("Enter The Any Number..");
string number;
int n=Integer.parseInt(number);
if(n%2==0)
{
System.out.println("The given number is even "+n);
}
else
{
System.out.println("The given number is odd "+n);
}
}
}
save this program in any drive and goto cmd then compile
c:> javac TestEx.java
c:> java TestEx
Enter The Any Number 5
The given number is odd 5
again execute program
Enter The Any Number 8
The given number is even
public class TestEx
{
public static void main(String args[])
{
System.out.println("Enter The Any Number..");
string number;
int n=Integer.parseInt(number);
if(n%2==0)
{
System.out.println("The given number is even "+n);
}
else
{
System.out.println("The given number is odd "+n);
}
}
}
save this program in any drive and goto cmd then compile
c:> javac TestEx.java
c:> java TestEx
Enter The Any Number 5
The given number is odd 5
again execute program
Enter The Any Number 8
The given number is even
No comments:
Post a Comment