My Java Programs
My Java Programs
{
public static void main(String[] args)
{
int age=12;
if(age>=18)
{
System.out.println("Eligible to vote");
}
else
{
System.out.println("not Eligible to vote");
}
}
}
-----------------------------------------------------------------------------------
----------------------------------------------------
VOTING ELIGIBILITY
import java.util.Scanner;
public class EmployeeVoting
{
public static void main(String args[])
{
int age;
Scanner c=new Scanner(System.in);
System.out.println("Enter the Voter's Age:");
age=c.nextInt();
if(age>=18)
{
System.out.println("YOU CAN VOTE");
}
else
{
System.out.println("YOU CANNOT VOTE");
}
}
}
-----------------------------------------------------------------------------------
------------------------------------------------------
POSITIVE NUMBER
import java.util.Scanner;
import java.util.Scanner;
ENTER NUMBER1
23
ENTER NUMBER2
45
IF NUMBER1>NUMBER2
PRINT NUMBER1 IS GREATER
ELSE
PRINT
NUMBER2 IS GREATER
import java.util.Scanner;
public class BiggerNumber
{
public static void main(String args[])
{
int NUMBER1, NUMBER2;
System.out.println("Enter Number1");
Scanner NUM1=new Scanner(System.in);
NUMBER1=NUM1.nextInt();
System.out.println("Enter Number2");
Scanner NUM2=new Scanner(System.in);
NUMBER2=NUM2.nextInt();
if(NUMBER1>NUMBER2)
{
System.out.println("Number1 is bigger");
}
else
{
System.out.println("Number2 is bigger");
}
}
}
-----------------------------------------------------------------------------------
------------------------------------------------------------------
Write a program to check given number is even or odd. (Hint: use % operator)
ENTER NUMBER
23
IF(NUMBER%2==0)
EVEN NUMBER
ELSE
ODD NUMBER
import java.util.Scanner;
public class EvenOdd
{
public static void main(String args[])
{
int NUMBER;
System.out.println("Enter the number");
Scanner A=new Scanner(System.in);
NUMBER=A.nextInt();
if(NUMBER%2==0)
{
System.out.println("This is an EVEN number");
}
else
{
System.out.println("This is an ODD number");
}
}
}
-----------------------------------------------------------------------------------
--------------------------------------------------------------------
2
4
6
8
10
12
14
16
18
20
1
3
5
7
9
11
13
15
17
19
public class PrintEvenOdd
{
public static void main(String[] args)
{
import java.util.Scanner;
public class Largest_Number
{
public static void main(String[] args)
{
int n, max;
Scanner s = new Scanner(System.in);
System.out.print("Enter number of elements in the array:");
n = s.nextInt();
int a[] = new int[n];
System.out.println("Enter elements of array:");
for(int i = 0; i < n; i++)
{
a[i] = s.nextInt();
}
max = a[0];
for(int i = 0; i < n; i++)
{
if(max < a[i])
{
max = a[i];
}
}
System.out.println("Maximum value:"+max);
}
}
-----------------------------------------------------------------------------------
----------------------------------------------------
INHERITANCE- SINGLE
import org.jdom2.Document;
import org.jdom2.Element;
import org.jdom2.JDOMException;
import org.jdom2.input.SAXBuilder;