1.
WAJP to read an int value from the user& check
whether the number is even or odd.
package evenOrOdd;
import [Link];
public class evenOrNot {
public static void main(String[] args) {
Scanner sc=new Scanner([Link]);
[Link]("enter the number");
int a=[Link]();
if (a%2==0)
{
[Link](a+" is a even number");
}
else
{
[Link](a+" is a odd number");
}
}
}
2. WAJP to read an int value from the user& check
whether the number is even or odd without using
modulus operator.
package evenOrOdd;
import [Link];
public class WithoutUsingModulusOperator {
public static void main(String[] args) {
Scanner sc=new Scanner([Link]);
[Link]("enter the number");
int x=[Link]();
if (x/2*2==x) {
[Link](x+" is a even number");
}
else
{
[Link](x+" is a odd number");
}
}
}
3. WAJP to read an int value from the user& check
whether the number is even or odd without using if.
package evenOrOdd;
import [Link];
public class WithoutUsingIf {
public static void main(String[] args) {
Scanner sc=new Scanner([Link]);
[Link]("enter the number");
int a=[Link]();
switch (a%2) {
case 0: {
[Link](a+" is a even number");
break;
}
case 1: {
[Link](a+" is a odd number");
break;
}
}
}
}
4. WAJP to read an int value from the user& check
whether the number is even or odd without using
conditional statement.
package evenOrOdd;
import [Link];
public class WithoutUsingConditionalStatement {
public static void main(String[] args) {
Scanner sc=new Scanner([Link]);
[Link]("enter the number");
int a=[Link]();
String []s= {"even","odd"};
[Link](a+" is a "+s[(a%2)]);
}
}
5. WAJP to read 3 integer values from the user & display
the biggest one.
package Important;
import [Link];
public class biggest {
public static void main(String[] args) {
Scanner sc=new Scanner([Link]);
[Link]("enter three numbers");
int x=[Link]();
int y=[Link]();
int z=[Link]();
int big=x;
if (y>big) {
big=y;
}
if (z>big) {
big=z;
}
[Link]("the biggest number is "+big);
}
}
6. WAJP to check the user entered number is positive or
negative.
package Important;
import [Link];
public class PositiveOrNegative {
public static void main(String[] args) {
Scanner sc=new Scanner([Link]);
[Link]("enter the number");
int x=[Link]();
if (x>0) {
[Link](x+ " is positive");
}
else if (x<0) {
[Link](x+" is negative");
}
else
{
[Link]("the number is zero");
}
}
}
7. WAJP to check the user entered year is a leap year or
not.
package Important;
import [Link];
public class LeapYear {
public static void main(String[] args) {
Scanner sc=new Scanner([Link]);
[Link]("enter the year");
int year=[Link]();
if (year%4==0 && year%100!=0 || year%400==0) {
[Link]("Leap Year");
}
else
{
[Link]("not a Leap Year");
}
}
}
8. WAJP to read the month number from the user & print
how many days in that month.
package Important;
import [Link];
public class DaysInMonth {
public static void main(String[] args) {
Scanner sc=new Scanner([Link]);
[Link]("enter the month");
int month=[Link]();
switch (month) {
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:[Link](month +" has 31 days");
break;
case 2: [Link](month+ " has 28/29 days");
break;
case 4:
case 6:
case 9:
case 11:[Link](month+ " has 30 days");
break;
default: [Link]("invalid month");
break;
}
}
}
9. WAJP to read 3 random numbers from the user & print
the middle number.
package Important;
import [Link];
public class MiddleNumber {
public static void main(String[] args) {
Scanner sc=new Scanner([Link]);
[Link]("enter three numbers");
int x=[Link]();
int y=[Link]();
int z=[Link]();
if (x>y && x<z || x>z && x<y) {
[Link](x);
}
else if (y>x && y<z || y>z && y<x) {
[Link](y);
}
else
{
[Link](z);
}
}
10. WAJP to print the even numbers from 1 to 100.
package evenOrOdd;
public class From1To100
{
public static void main(String[] args) {
for (int i = 1; i <=100 ; i++) {
if (i%2==0) {
[Link](i);
}
}
}
}
11. WAJP to print fibonacci series (Important )
package fibonacciSeries;Sss
import [Link];
public class F1 {
public static void main(String[] args) {
int a=0;
int b=1;
int n=10;
for (int i = 0; i < 10; i++) {
[Link](a);
int c=a+b;
a=b;
b=c;
}
}
}