1. Addition Of Two Number
import java.util.*;
public class Addition
{
public static void main(String[] args)
{
int a,b,sum;
Scanner s1=new Scanner(System.in);
System.out.println("Enter value of a:- ");
a=s1.nextInt();
System.out.println("Enter value of b:- ");
b=s1.nextInt();
sum=a+b;
System.out.println("Addition of two number is :- "+sum);
}
}
2. Even Or Odd Program
import java.util.*;
public class evenodd
{
public static void main(String[] args)
{
int no;
Scanner s1=new Scanner(System.in);
System.out.println("Enter Number:- ");
no=s1.nextInt();
if(no%2==0)
{
System.out.println("Number is even");
}
else
{
System.out.println("Number is odd");
}
}
}
3. Multiplication Of Two Number
import java.util.*;
public class multiply
{
public static void main(String[] args)
{
int a,b,sum;
Scanner s1=new Scanner(System.in);
System.out.println("Enter value of a:- ");
a=s1.nextInt();
System.out.println("Enter value of b:- ");
b=s1.nextInt();
sum=a*b;
System.out.println("Multiplication of " +a + " and " + b + " is:-" +sum);
}
}
4. Simple Interest Program
import java.util.*;
public class interest
{
public static void main(String[] args)
{
int p ,n;
float r,inte;
Scanner s1=new Scanner(System.in);
System.out.println("Enter the principal:- ");
p=s1.nextInt();
System.out.println("Enter the Rate of Interest:- ");
r=s1.nextFloat();
System.out.println("Enter the Time Period:- ");
n=s1.nextInt();
//Interest formula :- Interest=PRN/100
inte=(p * r * n)/100;
System.out.println("Simple Interest is: "+inte);
}
}
5. Leap Year Program
import java.util.*;
public class leapyear
{
public static void main(String[] args)
{
int year;
Scanner s1= new Scanner(System.in);
System.out.println("Enter year:- ");
year=s1.nextInt();
boolean leapyear=false;
if(year%4==0)
{
/* if (year%100==0)
{
if (year%400==0)
{
leapyear=true;
}
else
{
leapyear=false;
}
leapyear=true;
}
else
{
leapyear=false;
}
leapyear=true;*/
}
else
{
leapyear=false;
}
if(leapyear==true)
{
System.out.println(year +" is a leap year");
}
else
{
System.out.println(year +" is not a leap year");
}
}
}
6. Power Program
import java.util.*;
public class power
{
public static void main(String[] args)
{
int no,pow,i;
int result=1;
Scanner s1=new Scanner(System.in);
System.out.println("Enter Number:- ");
no=s1.nextInt();
System.out.println("Enter Power of Number:- ");
pow=s1.nextInt();
for(i=1;i<=pow;i++)
{
result=result*no;
}
System.out.println(no+"^"+pow+"="+result);
}
}
7. Complex Number Program
import java.util.*;
public class complexnumber
{
double rear , img;
complexnumber(double r,double i)
{
this.rear=r;
this.img=i;
}
public static complexnumber sum(complexnumber c1,complexnumber c2)
{
complexnumber temp=new complexnumber(0,0);
temp.rear=c1.rear+c2.rear;
temp.img=c1.img+c2.img;
return temp;
}
public static void main(String[] args)
{
complexnumber c1=new complexnumber(2.2,4);
complexnumber c2=new complexnumber(4.5,6.2);
complexnumber temp=sum(c1,c2);
System.out.println(temp.rear + "+" +temp.img+"i");
}
}
8. Constant and Vowel Program
import java.util.*;
public class volveconstant
{
public static void main(String[] args)
{
char ch;
boolean vowel=false;
Scanner s1=new Scanner(System.in);
System.out.println("Enter Character :- ");
ch=s1.next().charAt(0);
switch(ch)
{
case 'a':
vowel=true;
break;
case 'e':
vowel=true;
break;
case 'i':
vowel=true;
break;
case 'o':
vowel=true;
break;
case 'u':
vowel=true;
break;
default:
vowel=false;
break;
}
if(vowel==true)
{
System.out.println(ch + " is a vowel");
}
else
{
System.out.println(ch+ " is a consonant");
}
}
}
The End
No comments:
Post a Comment