0% found this document useful (0 votes)
9 views6 pages

Java Programs

The document contains multiple Java programs demonstrating basic programming concepts including printing messages, calculating simple interest, finding the circumference and area of a circle, and using various operators (arithmetic, comparison, logical, ternary, increment/decrement). Additionally, it includes conditional statements to determine if a number is even or odd, check for leap years, and a switch case to identify vowels. Each program is structured with a main method and outputs specific results based on the operations performed.

Uploaded by

doluitrishanu
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views6 pages

Java Programs

The document contains multiple Java programs demonstrating basic programming concepts including printing messages, calculating simple interest, finding the circumference and area of a circle, and using various operators (arithmetic, comparison, logical, ternary, increment/decrement). Additionally, it includes conditional statements to determine if a number is even or odd, check for leap years, and a switch case to identify vowels. Each program is structured with a main method and outputs specific results based on the operations performed.

Uploaded by

doluitrishanu
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

//First Program

public class p1
{
public static void main(String[]args)
{
[Link]("Welcome");
}
}

//Find Interest & Amount


public class p2
{
public static void main(String[]args)
{
double p,r,n,i,a;
p=1700;
r=12.75;
n=2;
i=p*r*n/100;
a=p+i;
[Link]("Simple Interest is " +i+"Rupees");
[Link]("Amount is " +a+"Rupees");
}
}
//Find Circumfereance & Area of Circle
public class p3
{
public static void main(String[]args)
{
double pi,r,c,a;
pi=3.14;
r=5;
c=2*pi*r;
a=pi*r*r;
[Link]("Circumfereance of Circle is " +c);
[Link]("Area of Circle is " +a);
}
}

//Use of Arithmatic Operators


public class p4
{
public static void main(String[]args)
{
double a,b;
a=20;
b=10;
[Link]("Sum of A & B is " +(a+b));
[Link]("Substraction of A & B is " +(a-b));
[Link]("Multiplication of A & B is " +(a*b));
[Link]("Division of A & B is " +(a/b));
[Link]("Modulo of A & B is " +(a%b));
}
}
//Use of Comparison Operators
public class p5
{
public static void main(String[]args)
{
double a,b;
a=20;
b=10;
[Link]("Is A Greater Than B " +(a>b));
[Link]("Is A Less Than B " +(a<b));
[Link]("Is A Greater Than or Equal to B " +(a>=b));
[Link]("Is A Less Than or Equal to B " +(a<=b));
[Link]("Is A Equal to B " +(a==b));
[Link]("Is A Not Equal to B " +(a!=b));
}
}

//Use of Logical Operators


public class p6
{
public static void main(String[]args)
{
double a,b;
a=20;
b=10;
[Link]((a>b) && (a==b));
[Link]((a>b) || (a==b));
[Link]((a<b) || (a==b));
[Link](!(a>b));
[Link]((a>b) ^ (a==b));
}
}
//Use of Turnary/Conditonal Operators
public class p7
{
public static void main(String[]args)
{
int a,b,c,max;
a=20;
b=10;
c=30;

max=(a>b) ? (a>c ? a : c) : (b>c ? b : c);


[Link](max);
}
}
//Use of Increment/Decrement Operators
public class p8
{
public static void main(String[]args)
{
int a,b,c;
a=20;
b=10;
c=30;
[Link](++a + ++b + ++c);
[Link](a++ + b++ + c++);
[Link](a);
[Link](b);
[Link](c);
int x,y,z;
x=20;
y=10;
z=30;
[Link](--x + --y + --z);
[Link](x-- + y-- + z--);
[Link](x);
[Link](y);
[Link](z);
}
}

//Use of If - Else Condition to Find the Number is Even or Odd


public class p9
{
public static void main(String[]args)
{
int no=59;
if(no%2==0)
[Link](no + " is Even");
else
[Link](no + " is Odd");
}
}

//Use of If - Else Condition to Find the Year is leapyear or not


public class p10
{
public static void main(String[]args)
{
int year=2003;
if(year%4==0)
{
[Link](year + " is leapyear.");
}
else
{
[Link](year + " is not leapyear.");
}
}
}
//Use of Switch Case to find the given Alphabet is Vowel or Constant
public class p12
{
public static void main(String[]args)
{
char ch='a';
switch(ch)
{
case 'a': case 'e': case 'i': case 'o': case 'u':
[Link]("The given alphabet is Vowel.");
break;
case 'A': case 'E': case 'I': case 'O': case 'U':
[Link]("The given alphabet is Vowel.");
break;
default:
[Link]("The given alphabet is Constant.");
}
}
}

You might also like