Variable and Constant in Java:-
Variable or Data Member:- It is a special identifier whose value can be changed at compile-time or runtime.
Variable declaration Syntax:-
access modifier + non access modifier + datatype + identifier
public static int x
int x =10 ; //default instance int x=10 dynamic memory allocation using object
static int y=20 // default static int y=20 one-time memory allocated at compile time
Types of variables:-
1 Instance or Dynamic:-
It will be declared without any static modifier and it will allocate memory at the time of execution by the object.
a variable that will be declared underclass or under instance method without using static modifier will be an instance variable
int x =10 ; //default instance int x=10 dynamic memory allocation using object
static int y=20 // default static int y=20 one-time memory allocated at compile time
Types of variables:-
1 Instance or Dynamic:-
It will be declared without any static modifier and it will allocate memory at the time of execution by the object.
a variable that will be declared underclass or under instance method without using static modifier will be an instance variable
instance variable will never declare under the static method but it can be used.
this type of variable is also called dynamic data members in OOP'S Programming. means non-static, for instance, dynamic all are the same.
this type of variable is also called dynamic data members in OOP'S Programming. means non-static, for instance, dynamic all are the same.
Example of nonstatic variable:-
class Dynamic
{
int a,b,c;
public static void main(String args[])
{
Dynamic obj= new Dynamic();
obj.a=100;
obj.b=200;
obj.c=obj.a+obj.b;
System.out.println(obj.c);
}
}
class A
{
int x=10; //global instance variable
void fun()
{
int y=20; //local instance variable
}
}
A obj = new A(); //object
Complete Explanation by Program:-
class Add
{
int a=100,b=200,c;
public static void main(String args[])
{
Add obj = new Add();
obj.c=obj.a+obj.b;
System.out.println(obj.c);
Add obj1 = new Add();
obj1.a=10;
obj1.b=20;
obj1.c=obj1.a+obj1.b;
System.out.println(obj1.c);
}
}
2 Static:-
This type of variable will allocate memory after compile-time, static has constant memory but not the constant value, a value can be changed in the same memory multiple times.
static datatype identifier=value
static int x=100;
x=10;
x=12;
we can define static variable underclass using static keyword and static method without using the static keyword. if we define a static variable under the static method then no need to declare a static keyword.
class A
{
static int a=100;
void fun()
{
int b=20;
}
public static void main()
{
int c=30;
}
}
Program of Static With Complete explanation?
class Add
{
static int a=100,b=200,c;
public static void main(String args[])
{
c=a+b;
System.out.println(c);
a=10;
b=20;
c=a+b;
System.out.println(c);
}
}
.........................................................................................................................................
Program explanation in Java:-
class Dynamic
{
int a,b,c;
public static void main(String args[])
{
Dynamic obj=new Dynamic();
obj.a=100;
obj.b=200;
obj.a=20;
Dynamic obj1=new Dynamic();
obj1.a=2000;
obj1.b=3000;
obj=obj1;
obj.c=obj.a+obj.b;
System.out.println(obj.c);
}
}
Constant:-....................................................................................................................................................
If we can not change the value of the identifier at compile-time or run-time then it is called constant.
java provides the final keyword to a constant declaration.
final static datatype variablename=value;
constant memory always will be static by default.
class ConstDemo
{
final static int A=100;
public static void main(String args[])
{
A=20;
System.out.println(A);
}
}
Assignment:-
1)WAP to calculate electricity bill where unit price and total consumption will be assigned by the users?
2) WAP to calculate salary where basic, ta, da, comm, pf,hra,noofleave will be assigned by the users?
3) WAP to calculate the multiplication of complex numbers?
The solution to this program:-
class Complex
{
public static void main(String args[])
{
int a,b,c,d,r,i;
a=2;
b=3;
c=4;
d=5;
r = a*c-b*d;
i = a*d+b*c;
System.out.println(r + "+" + i + "i");
}
}
Program to perform the addition of complex numbers?
class Complex
{
public static void main(String args[])
{
int a,b,c,d,r,i;
a=2;
b=3;
c=4;
d=5;
r = a+c;
i = b+d;
System.out.println(a + "+" + b + "i");
System.out.println(c + "+" + d + "i");
System.out.println(r + "+" + i + "i");
}
}
4) WAP to find the maximum number in any three-digit number?
int a= 457 ; //7
5) WAP to find middle numbers using three-digit numbers?
6) WAP to calculate the area of a circle where pi will be constant and radius will be variable?
7) WAP to calculate simple interest using instance type variable?
8) WAP to convert temperature from Celsius to Fahrenheit using static data members globally?
c/5 = f-32/9
class Electro
ReplyDelete{
public static void main(String args[])
{
int up=10,c=300;
int eb=up*c;
System.out.println(eb);
}
}
class Maxt
ReplyDelete{
public static void main(String args[])
{
int a=247;
int d1,d2,d3,max;
d3=a%10;
a=a/10;
d2=a%10;
a=a/10;
d1=a;
max=d1;
if(max<d2)
{
max=d2;
}
if(max<d3)
{
max=d3;
}
System.out.println("Highest Digit is: "+max);
}
}
class Middle
ReplyDelete{
public static void main(String args[])
{
int a=247;
int m;
a=a/10;
m=a%10;
System.out.println("Middle Digit is: "+m);
}
}
class Area
ReplyDelete{
public static void main(String args[])
{
double r=14;
double area= Math.PI*r*r;
System.out.println("Area of circle with radius "+r+" is: "+area);
}
}
import java.util.Scanner;
ReplyDeleteclass complexnum
{
public static void main(String[]arg)
{
int a,b,c,d;
Scanner sc=new Scanner(System.in);
System.out.println("enter the value of a");
a=sc.nextInt();
System.out.println("enter the value of b");
b=sc.nextInt();
System.out.println("enter the value of c");
c=sc.nextInt();
System.out.println("enter the value of d");
d=sc.nextInt();
int r=a*c-b*d;
int i=a*d+b*c;
System.out.println(r+"+"+i+"i");
}
}
Q:- Example of non-static variable :-
ReplyDeleteSolution:-
class Dynamic
{
int a,b,c;
public static void main(String args[])
{
Dynamic obj= new Dynamic();
obj.a=929;
obj.b=584;
obj.c=obj.a+obj.b;
System.out.println(obj.c);
}
}
Q:- Complete Explanation of non-static Vairiable by Program:-
ReplyDeleteSolution:-
class Add
{
int a=929,b=854,c;
public static void main(String args[])
{
Add obj = new Add();
obj.c=obj.a+obj.b;
System.out.println(obj.c);
Add obj1 = new Add();
obj1.a=25;
obj1.b=75;
obj1.c=obj1.a+obj1.b;
System.out.println(obj1.c);
}
}
Q:- WAP to calculate the multiplication of complex numbers ??
ReplyDeleteSolution :-
class Complex
{
public static void main(String args[])
{
int a,b,c,d,r,i;
a=2;
b=3;
c=4;
d=5;
r = a*c-b*d;
i = a*d+b*c;
System.out.println(r + "+" + i + "i");
}
}
Q:- Program to perform the addition of complex numbers ??
ReplyDeleteSolution:-
class Complex
{
public static void main(String args[])
{
int a,b,c,d,r,i;
a=2;
b=3;
c=4;
d=5;
r = a+c;
i = b+d;
System.out.println(a + "+" + b + "i");
System.out.println(c + "+" + d + "i");
System.out.println(r + "+" + i + "i");
}
}
class Ebill
ReplyDelete{
public static void main(String args[])
{
int tunit=100, punit=4, ebill;
ebill=tunit*punit;
System.out.println(ebill);
}
}
// maximum number in any three-digit number
ReplyDeleteclass MaxNumber
{
public static void main(String args[])
{
int num=156;
if((1>5) && (1>6))
{
System.out.println(" 1 is maximum number ");
}
else if(5>6 && 5>1)
{
System.out.println(" 5 is maximum number ");
}
else
{
System.out.println(" 6 is maximum number ");
}
}
}
//Multiplication of complex numbers
ReplyDeleteclass ComplexMul
{
public static void main(String args[])
{
int a=3, b=4, c=3 ,d=4, e, f;
e = a*b;
f= c*d;
System.out.println(e +"+" +f + "i^2");
}
}
//Maximum number in any three-digit number
ReplyDeleteclass MaxNumber
{
public static void main(String args[])
{
int num=156;
if((1>5) && (1>6))
{
System.out.println(" 1 is maximum number ");
}
else if(5>6 && 5>1)
{
System.out.println(" 5 is maximum number ");
}
else
{
System.out.println(" 6 is maximum number ");
}
}
}
// Middle numbers using three-digit number.
ReplyDeleteclass MiddleNumber
{
public static void main(String args[])
{
int number=369;
int middlenumber;
number = number/10;
middlenumber = number%10;
System.out.println("Middle Number = "+middlenumber);
}
}
//Calculate the area of a circle where pi will be constant and radius will be variable.
ReplyDeleteclass AreaCircle
{
static final float pi=3.14F;
public static void main(String args[])
{
int r =20;
float area;
area=pi*r*r;
System.out.println("Area of circle =" +area);
}
}
// Calculate simple interest using instance type variable?
ReplyDeleteclass Sinterest
{
int p,t;
float r;
float s;
public static void main(String args[])
{
Sinterest obj= new Sinterest();
obj.p=5000;
obj.r=0.07F;
obj.t=5;
obj.s = obj.p*obj.r*obj.t;
System.out.println(obj.s);
}
}
class Ebill
ReplyDelete{
public static void main(String[]args)
{
int unitrate=10, totalunit=250, bill;
bill= totalunit*unitrate;
System.out.println("bill=" + bill);
}
}
class Complexadd
ReplyDelete{
public static void main(String[]args)
{
int a=5,b=6,c=8,d=3,r,i;
r=a+c;
i=b+d;
System.out.println(a + "+" + c + "i");
System.out.println(b + "+" + d + "i");
System.out.println(r + "+" + i + "i");
}
}
class Complexadd
ReplyDelete{
public static void main(String[]args)
{
int a=5,b=6,c=8,d=3,r,i;
r=a+c;
i=b+d;
System.out.println(r);
System.out.println(i + "i");
}
}
class Complexadd
ReplyDelete{
public static void main(String[]args)
{
int a=5,b=6,c=8,d=3,r,i;
r=a+c;
i=b+d;
System.out.println(a + "+" + b + "i");
System.out.println(c + "+" + d + "i");
System.out.println(r + "+" + i + "i");
}
}
class Complexadd
ReplyDelete{
public static void main(String[]args)
{
int a=5,b=6,c=8,d=3,r,i;
r=a+c;
i=b+d;
System.out.println(r + "+" + i + "i");
}
}
class Obi
ReplyDelete{
int a=7195, b=3595, c;
public static void main(String[]args)
{
Obi obj= new Obi();
obj.c= obj.a + obj.b;
System.out.println(obj.c);
}
}
class Circle
ReplyDelete{
final static double pi=3.14
public static void main(String[]args)
{
double r=9, a;
a= pi*r*r;
System.out.println("A=" +a);
}
}
class Simp
ReplyDelete{
int p,r,t,s;
public static void main(String args[])
{
Simp obj=new Simp();
obj.p=50000;
obj.t=2;
obj.r=7;
obj.s=((obj.p*obj.t*obj.r)/100);
System.out.println(obj.s);
}
}
class Mn
ReplyDelete{
public static void main(String arg[])
{
int a=457;
int b=a/10;
int m=b%10;
System.out.println(m);
}
}
class Area
ReplyDelete{
public static void main(String arg[])
{
final int p=5;
int r=2;
int a=p*r*r;
System.out.println(a);
}
}
class Sinterset
ReplyDelete{
int p,t;
float r;
float s;
public static void main(String arg[])
{
Sinterset obj=new Sinterset();
obj.p=2000;
obj.r=2;
obj.t=2;
obj.s=(obj.p*obj.r*obj.t)/100;
System.out.println(obj.s);
}}
class Temp
ReplyDelete{
static float tc=50;
static float f=tc*9/5+32;
public static void main(String arg[])
{
System.out.println(Temp.f+"F");
}
}
class Complex
ReplyDelete{
public static void main(String arg[])
{
int a,b,c,d,r,i;
a=4;
b=6;
c=2;
d=4;
r=a*c-b*d;
i=a*d+b*c;
System.out.println(r+ "+" +i +"i");
}
}
class Max
ReplyDelete{
public static void main(String arg[])
{
int a=257;
int a1,a2,a3,max;
a3=a%10;
a=a/10;
a2=a%10;
a=a/10;
a1=a;
max=a1;
if(max<a3)
{
max=a3;
}
if(max<a2)
{
max=a2;
}
else
{
System.out.println("maximum no. is"+max);
}
}
}
class variable
ReplyDelete{
public static void main(String args[])
{
int x=457;
int y;
y=x/10;
int n=y%10;
System.out.println(n);
}
}
class Acr
ReplyDelete{
public static void main(String args[])
{
int r=45,pi=46;
int a=pi*r*r;
System.out.println(a);
}
class A
ReplyDelete{
int p,t;
int r;
int s;
public static void main(String args[])
{
A a=new A();
a.p=2000;
a.r=2;
a.t=3;
a.s=a.p*a.r*a.t/100;
System.out.println(a.s);
}
}
class cles
ReplyDelete{
static void main()
{
float fah,cel;
cel=13;
fah=((cel+9)/5+32);
System.out.println(fah);
}
public static void main(String args[])
{
cles a=new cles();
a.main();
}
}
class max
ReplyDelete{
public static void main(String args[])
{
int a=4,b=5,c=7;
if(a>=b)
{
if(a>=c)
{
System.out.println("maximum number="+a);
}
else
{
System.out.println("maximum number="+c);
}
}
else
{
if(b>=c)
{
System.out.println("maximum number="+b);
}
else
{
System.out.println("maximum number="+c);
}
}
System.out.println();
}
}
class cles
ReplyDelete{
static float cel=15;
static float fah=((cel+9)/5+32);
public static void main(String args[])
{
System.out.println(fah);
}
}
class Complex
ReplyDelete{
public static void main(Strings args[])
{
int a=2,b=3;//a+ib is complex number
int c=3,d=2;//c+id is complex number
int x,y;
x=(a*c)+((b*d)*-1);
y= a*d+b*c;
System.out.println("Result of " +a +"i"+b + "and " + c+ "i"+d+ "is ");
System.out.println(x+"i"+z);
}
class Complex
ReplyDelete{
int p, r, t;
public static void main(Strings args[])
{
float si;
Complex c= new Complex();
c.p = 10000,
c.r=10;
c.t=2;
si =(c.p*c.r*c.t)*.01;
System.out.print(si)
}
ReplyDeleteWAP to find the maximum number in any three-digit number?
int a= 457 ;
class Bigger
{
public static void main(String args[])
{
int num,a,b,c;
a=num%10;
num=num/10;
b=num%10;
num=num/10;
c=num%10;
if (a>b)
{
if (a>c)
{
System.out.println(a)
}
else
{
System.out.println(c)
}
}
else
{
if(b>c)
{
System.out.println(b)
}
else
{
System.out.println(c)
}
}
}
#NAYANSI PURWAR
ReplyDeleteQ.)WAP to calculate electricity bill where unit price and total consumption will be assigned by the users?
SOL-
import java.util.Scanner;
class ElectricConstant
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
System.out.println("enter unit price");
final int unit_price;
unit_price=sc.nextInt();
System.out.println("enter total consumption:");
float total_consumption=sc.nextFloat();
float bill=unit_price*total_consumption;
System.out.println("total bill:"+bill);
}
}
package Basics;
ReplyDeletepublic class greaterNo {
public static void main(String []args)
{
int number=837,a,b,c,d;
a=number%10;
b=(int)number/10;
c=b%10;
d=(int)b/10;
d=d%10;
//System.out.println("Value is "+d);
//System.out.println("Value is "+c);
//System.out.println("Value is "+a);
if(d>c && d>a)
{
System.out.println(d);
}
else if(c>a && c>d)
{
System.out.println(c);
}
else
{
System.out.println(a);
}
}
}
package Basics;
ReplyDeletepublic class areaOfCircle {
final static float Pi=3.14F;
public static void main(String[] args) {
int r=5;
float Area;
Area= areaOfCircle.Pi*r*r;
System.out.println("Area of circle is "+Area);
}
}
#NAYANSI PURWAR
ReplyDeleteQ)WAP to find the maximum number in any three-digit number?
sol-class Max
{
public static void main(String args[])
{
int a,b,c,num=356;
a=num%10;// 6
num=num/10; //35
b=num%10;//5
num=num/10; //3
c=num;
if(a>b && a>c)
{
System.out.println(+a);
}
else if (b>c)
{
System.out.println(+b);
}
else
{
System.out.println(+c);
}
}
}
#NAYANSI PURWAR
ReplyDeleteQ)WAP to find middle numbers using three-digit numbers?
sol-
class Middle
{
public static void main(String args[])
{
int a,b,c,num=389;
a=num%10;// 6
num=num/10; //35
b=num%10;//5
num=num/10; //3
System.out.println(b);
}
}
Q.) WAP to calculate the area of a circle where pi will be constant and radius will be variable?
ReplyDeletesol-
import java.util.Scanner;
class SimpleFinal
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
final float pi=3.14f;
System.out.println("Enter radius:");
float radius =sc.nextFloat();
float area=pi*radius*radius;
System.out.println("Area of circle:"+area);
}
}
Q) WAP to calculate simple interest using instance type variable?
ReplyDeleteclass SimpleFinal
{
int p=1000,t=3;
float r=3.4f;
public static void main(String[] args)
{
SimpleJava sc= new SimpleJava();
Float SI=(sc.p*sc.r*sc.t)/100;
System.out.println("Simple Interest:"+SI);
}
}
//WAP to convert temperature from Celsius to Fahrenheit using static data members globally?
ReplyDeleteclass Celcius
{
static double Fahrenheit,Celcius=40;
public static void main(String[] args)
{
Fahrenheit=(Celcius*1.8)+32;
System.out.println("Celcius to Fahrenheit:"+Fahrenheit);
}
}
Q.)WAP to calculate electricity bill where unit price and total consumption will be assigned by the users?
ReplyDeleteProgram:
class Bill {
public static void main(String[] args) {
int unit_price=4,total_consumption=250,amount;
amount=unit_price*total_consumption;
System.out.println("Amount to be paid - "+amount+" Rs.");
}
}
WAP to calculate the multiplication of complex numbers?
ReplyDeleteProgram:
class Complex_number{
public static void main(String[] args) {
int a=6,b=4,c=5,d=6,real,imaginary;
real=a*c-b*d;
imaginary=a*d+b*c;
System.out.println("complex numbers - "+a+"+"+b+"i\t"+c+"+"+d+"i");
System.out.print("sum = "+real+"+"+imaginary+"i");
}
}
Program to perform the addition of complex numbers?
ReplyDeleteProgram:
class Complex_number{
public static void main(String[] args) {
int a=2,b=4,c=5,d=6,real,imaginary;
real=a+c;
imaginary=b+d;
System.out.println("complex numbers - "+a+"+"+b+"i\t"+c+"+"+d+"i");
System.out.print("sum = "+real+"+"+imaginary+"i");
}
}
WAP to find middle numbers using three-digit numbers?
ReplyDeleteProgram:
class Middle_number {
public static void main(String[] args) {
int a=457,temp=a;
a=a/10;
a=a%10;
System.out.println("Middle number in "+ temp+" is "+a) ;
}
}
WAP to find the maximum number in any three-digit number?
ReplyDeleteProgram:
int a= 457 ;
class Maximum_num {
public static void main(String[] args) {
int a=457,temp=a,x,y,z;
x=a%10;
a=a/10;
y=a%10;
a=a/10;
z=a%10;
if(x>y&&x>z) {
System.out.println("Maximum number in "+ temp+" is "+x) ;
}
else if(y>x&&y>z) {
System.out.println("Maximum number in "+ temp+" is "+y) ;
}
else {
System.out.println("Maximum number in "+ temp+" is "+z) ;
}
}
}
WAP to calculate the area of a circle where pi will be constant and radius will be variable?
ReplyDeleteProgram:
class Area_of_circle {
public static void main(String[] args) {
int radius=4;
final double PI=3.1415;
double area=PI*radius*radius;
System.out.println("Area of circle of radius "+radius+" is "+area);
}
}
WAP to calculate simple interest using instance type variable?
ReplyDeleteProgram:
class Simple_interest {
int p=10000,r=2,t=2;
double si=(double)p*r*t/100;
public static void main(String[] args) {
Simple_interest obj=new Simple_interest();
System.out.println("Simple Interest = "+obj.si);
}
}
WAP to convert temperature from Celsius to Fahrenheit using static data members globally?
ReplyDeleteProgram:
class Celsius_to_Fahrenheit {
static double f,c=30.00;
public static void main(String[] args) {
f=(c*9/5)+32;
System.out.println(f);
}
}
//WAP to calculate electricity bill where unit price and total consumption will be assigned by the users?
ReplyDeleteclass Bill
{
public static void main(String...args)
{
double unit_price=1.5,total_consump=1500;
System.out.println("Electricity Bill is"+(unit_price*total_consump));
}
}
class Middle
ReplyDelete{
public static void main(String args[])
{
int b,num=247;
num=num/10;
b=num%10;
System.out.println(b);
}}
class Complex_Multi
ReplyDelete{
public static void main(String args[])
{
int r1=2,r2=5,im1=3,im2=6,r,im;
r=r1*r2;
im=im1*im2;
System.out.println(r + "i" + im);
}
}
ReplyDeleteimport java.util.Scanner;
class Area
{
final static float pi=3.41F;
public static void main(String args[])
{
float r,area;
Scanner sc=new Scanner(System.in);
System.out.println("enter radius");
r=sc.nextFloat();
area=pi*r*r;
System.out.println(area);
}
}
import java.util.Scanner;
ReplyDeleteclass Simple_interest
{
float p,r,t,si;
public static void main(String args[])
{
Simple_interest obj=new Simple_interest();
Scanner sc=new Scanner(System.in);
System.out.println("enter value of p");
obj.p=sc.nextFloat();
System.out.println("enter value of r");
obj.r=sc.nextFloat();
System.out.println("enter value of t");
obj.t=sc.nextFloat();
obj.si=(obj.p*obj.r*obj.t)/100;
System.out.println(obj.si);
}
}
//WAP to calculate electricity bill where unit price and total consumption will be assigned by the users?
ReplyDeleteimport java.util.Scanner;
class Electricbill
{
public static void main(String args[])
{
Scanner sc= new Scanner(System.in);
System.out.println("enter unit price");
int a=sc.nextInt();
System.out.println("enter total consumption");
int b=sc.nextInt();
System.out.println(a*b);
}
}
//WAP to calculate salary where basic, ta, da, comm, pf,hra,no.ofleave will be assigned by the users?
ReplyDeleteimport java.util.Scanner;
class Salaryuser
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("enter basic");
int basic=sc.nextInt();
System.out.println("enter ta");
int ta=sc.nextInt();
System.out.println("enter da");
int da=sc.nextInt();
System.out.println("enter comm");
int comm=sc.nextInt();
System.out.println("enter pf");
int pf=sc.nextInt();
System.out.println("enter hra");
int hra=sc.nextInt();
System.out.println("enter no. of leaves");
int leaves=sc.nextInt();
System.out.println(basic+ta+da+comm+pf+hra);
System.out.println(basic+ta+da+comm-pf+hra-leaves);
}
}
//WAP to find middle numbers using three-digit numbers?
ReplyDeleteclass MiddleNo
{
public static void main(String args[])
{
int a,b,c,num=789;
a=num%10;
num=num/10;
b=num%10;
num=num/10;
System.out.println(b);
}
}
//WAP to calculate the area of a circle where pi will be constant and radius will be variable?
ReplyDeleteimport java.util.Scanner;
class AreaCirclepir
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
final float pi=3.14f;
System.out.println("Enter r");
float r =sc.nextFloat();
float area=pi*r*r;
System.out.println("Area of circle is="+area);
}
}
-WAP to calculate the area of a circle where pi will be constant and radius will be variable?
ReplyDeleteimport java.util.Scanner;
class AreaofCircle
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter r");
float r =sc.nextFloat();
final float pi=3.14F;
float area=pi*r*r;
System.out.println("Area of circle is= "+area);
}
}
-WAP to calculate simple interest using instance type variable?
ReplyDeleteclass Interest
{
int p=1000;
float r=2.2F,t=2.1F,si;
public static void main(String args[])
{
Interest obj=new Interest();
obj.si=(obj.p*obj.r*obj.t)/100;
System.out.println("result is =" + obj.si);
}
}
-WAP to calculate the area of a circle where pi will be constant and radius will be variable?
ReplyDeleteimport java.util.Scanner;
class Area
{
final static float pi=3.14F;
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter r");
float r=sc.nextFloat();
float area=pi*r*r;
System.out.println("Area of circle is= "+area);
}
}
-WAP to multiply complex number
ReplyDeleteclass ComplexMul
{
public static void main(String args[])
{
int r1=5,r2=3,img1=2,img2=6;
int r=r1*r2-img1*img2;
int img=r1*img1+r2*img1;
System.out.println("Real= "+r+" Imaginary= "+img+ " i");
}
}
-WAP to find middle numbers using three-digit numbers?
ReplyDeleteimport java.util.Scanner;
class Middle
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter 3 digit no: ");
int num=sc.nextInt();
int a=num%10;
num=num/10;
int b=num%10;
System.out.println("Middle number is= "+b);
}
}
-WAP to find the maximum number in any three-digit number?
ReplyDeleteimport java.util.Scanner;
class Max
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter 3 digit no: ");
int num=sc.nextInt();
int a=num%10;
num/=10;
int b=num%10;
num/=10;
int c=num;
if(a>b)
{
if(a>c)
System.out.println("Maximum number is= "+a);
else
System.out.println("Maximum number is= "+c);
}
else
System.out.println("Maximum number is= "+b);
}
}
//WAP to find the maximum number in any three-digit number?
ReplyDeleteimport java.util.Scanner;
class Max
{
public static void main(String abc[])
{
int num,temp,max=0;
Scanner sc= new Scanner(System.in);
System.out.println("enter three digit number");
num=sc.nextInt();
temp=num%10;
num=num/10;
int a=num%10;
num=num/10;
int b=num%10;
if(temp>a)
max=temp;
if (a>b)
max=a;
if(b>a)
max=b;
System.out.println("the maximum number is" +max);
}
}
Ankita Verma
class Max
{
public static void main(String args[])
{
int x=457;
int a=x%10;
x=x/10;
int b=x%10;
x=x/10;
int c=x%10;
x=x/10;
int max=0;
if(max<a)
{
max=a;
System.out.println(max);
}
}
}
ReplyDeleteAnkita Verma
class Middle
{
public static void main(String args[])
{
int x=457;
x=x/10;
int a=x%10;
System.out.println(a);
}
}
Ankita Verma
ReplyDeleteclass Simple
{
int p,t;
float r,s;
public static void main(String args[])
{
Simple obj=new Simple();
obj.p=100;
obj.r=2.5F;
obj.t=3;
obj.s=(obj.p*obj.r*obj.t)/100;
System.out.println(obj.s);
}
}
Ankita Verma
ReplyDeleteclass Areac
{
final static double pi=3.14;
public static void main(String args[])
{
int r=5;
double c=pi*r*r;
System.out.println("area of circle =" +c);
}
}
Ankita Verma
ReplyDeleteclass Add
{
float celsious;
float fahrenheit=24;
public static void main(String args[])
{
Add obj=new Add();
obj.celsious=5*(obj.fahrenheit-32)/9;
System.out.println(obj.celsious);
Add obj1=new Add();
obj1.fahrenheit=5;
obj1.celsious=5*(obj1.fahrenheit-32)/9;
System.out.println(obj1.celsious);
}
}
class convert
ReplyDelete{
static float celsious=52,fahrenheit;
public static void main(String args[])
{
fahrenheit=(celsious*9/5)+32;
System.out.println("TEMPRATURE IN FAHRENHEIT IS:- "+fahrenheit);
}
}
class SI
ReplyDelete{
public static void main(String args[])
{
Integer p=Integer.valueOf(2000);
Integer r=Integer.valueOf(25);
Integer t=Integer.valueOf(2);
Integer si=Integer.valueOf(p*r*t/100);
System.out.println("Simple Intrest is:-"+si);
}
}
class bill
ReplyDelete{
public static void main(String args[])
{
final float Unit_price=5.8F;
int Consumption=200;
float bill=(Unit_price*Consumption);
System.out.println("Total electricity bill is:- "+bill);
}
}
class circlearea
ReplyDelete{
public static void main(String args[])
{
final float pi=3.14F;
int r=7;
float area=r*r*pi;
System.out.println("Area of circle is:- "+area);
}
}
class middleno
ReplyDelete{
public static void main(String args[])
{
int num=568;
int a=num%10;
num=num/10;
int b=num%10;
int c=num/10;
System.out.println("Middle number is:- "+b);
}
}
class Complex
ReplyDelete{
public static void main(String args[])
{
int a,b,c,d,r,i;
a=10;
b=20;
c=40;
d=50;
r = a+c;
i = b+d;
System.out.println(a + "+" + b + "i");
System.out.println(c + "+" + d + "i");
System.out.println("Add= "+r + "+" + i + "i");
}
}
class Middle
ReplyDelete{
public static void main(String args[])
{
int a=378;
int m;
a=a/10;
m=a%10;
System.out.println("Middle Digit= "+m);
}
}
class Max
ReplyDelete{
public static void main(String arg[])
{
int a=257;
int a1,a2,a3,max;
a3=a%10;
a=a/10;
a2=a%10;
a=a/10;
a1=a;
max=a1;
if(max<a3)
{
max=a3;
}
if(max<a2)
{
max=a2;
}
else
{
System.out.println("maximum no. is"+max);
}
}
}
class AreaOfCircle
ReplyDelete{
static final float pi=3.14F;
public static void main(String a[])
{
int r =20;
float area;
area=pi*r*r;
System.out.println("Area of circle =" +area);
}
public class SimpleInt {
ReplyDeleteint p=1000;
float r=2.2F,t=2.1F,si;
public static void main(String[] args)
{
SimpleInt obj=new SimpleInt();
obj.si=(obj.p*obj.r*obj.t)/100;
System.out.println("result is =" + obj.si);
}
}
public class Bill3 {
ReplyDeletepublic static void main(String args[])
{
int up=10,c=300;
int eb=up*c;
System.out.println(eb);
}
}
import java.util.Scanner;
ReplyDeletepublic class UserDetails
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("enter basic");
int basic=sc.nextInt();
System.out.println("enter ta");
int ta=sc.nextInt();
System.out.println("enter da");
int da=sc.nextInt();
System.out.println("enter comm");
int comm=sc.nextInt();
System.out.println("enter pf");
int pf=sc.nextInt();
System.out.println("enter hra");
int hra=sc.nextInt();
System.out.println("enter no. of leaves");
int leaves=sc.nextInt();
System.out.println(basic+ta+da+comm+pf+hra);
System.out.println(basic+ta+da+comm-pf+hra-leaves);
}
}
import java.util.Scanner;
ReplyDeleteclass ComplexNo {
public static void main(String args[])
{
Scanner sc= new Scanner(System.in);
int w,x,y,z,r,i;
System.out.print("Enter Complex w =");
w=sc.nextInt();
System.out.print("Enter Complex x = ");
x=sc.nextInt();
System.out.print("Enter Complex y =");
y=sc.nextInt();
System.out.print("Enter Complex z =4");
z=sc.nextInt();
r = w*y-x*z;
i = w*z+x*y;
System.out.println(r + "+" + i + "i");
}
}
//yogesh seroke
ReplyDeleteclass Complex
{
public static void main(String args[])
{
int a,b,c,d,r,i;
a=2;
b=3;
c=4;
d=5;
r = a*c-b*d;
i = a*d+b*c;
System.out.println(r + "+" + i + "i");
}
//yogesh seroke
ReplyDelete//complex num addition
class Complex
{
public static void main(String args[])
{
int a,b,c,d,r,i;
a=2;
b=3;
c=4;
d=5;
r = a+c;
i = b+d;
System.out.println(a + "+" + b + "i");
System.out.println(c + "+" + d + "i");
System.out.println(r + "+" + i + "i");
}
}
//yogesh seroke
ReplyDelete// electricity bill
class Ebill
{
public static void main(String args[])
{
int tunit=100, punit=4, ebill;
ebill=tunit*punit;
System.out.println(ebill);
}
}
// yogesh seroke
ReplyDelete// maximum number in any three-digit number
class MaxNumber
{
public static void main(String args[])
{
int num=156;
if((1>5) && (1>6))
{
System.out.println(" 1 is maximum number ");
}
else if(5>6 && 5>1)
{
System.out.println(" 5 is maximum number ");
}
else
{
System.out.println(" 6 is maximum number ");
}
}
}
// yogesh seroke
ReplyDelete// max number
class Bigger
{
public static void main(String args[])
{
int num,a,b,c;
a=num%10;
num=num/10;
b=num%10;
num=num/10;
c=num%10;
if (a>b)
{
if (a>c)
{
System.out.println(a)
}
else
{
System.out.println(c)
}
}
else
{
if(b>c)
{
System.out.println(b)
}
else
{
System.out.println(c)
}
}
}
// yogesh seroke
ReplyDelete// middle num
class MiddleNumber
{
public static void main(String args[])
{
int number=369;
int middlenumber;
number = number/10;
middlenumber = number%10;
System.out.println("Middle Number = "+middlenumber);
}
}
// yogesh seroke
ReplyDelete// circle area
class Area
{
public static void main(String args[])
{
double r=14;
double area= Math.PI*r*r;
System.out.println("Area of circle with radius "+r+" is: "+area);
}
}
// yogesh seroke
ReplyDelete// si
class Sinterest
{
int p,t;
float r;
float s;
public static void main(String args[])
{
Sinterest obj= new Sinterest();
obj.p=5000;
obj.r=0.07F;
obj.t=5;
obj.s = obj.p*obj.r*obj.t;
System.out.println(obj.s);
}
}
// yogesh seroke
ReplyDelete// CtoF
class CtoF
{
static int c = 40;
static double feature;
public static void main(String args[])
{
f= c*1.8000+32.00;
System.out.println(f);
}
}
// 1)WAP to calculate electricity bill where unit price and total consumption will be assigned by the users?
ReplyDeleteclass Electricbill
{
public static void main(String args[])
{
int up = 10;
int con = 500;
int elecbill = up*con;
System.out.println(elecbill);
}
}
Salary Calculator
ReplyDeleteclass SalaryCalc
{
public static void main(String args[])
{
float
basic=10000,ta=2000,da=1000,comm=500,hra=4000,nl=3,pf=1000;
float gsal,nsal;
gsal = basic+ta+da+comm+hra+pf;
System.out.println("Gross salary is "+gsal);
nsal = gsal-pf;
float ded = (nsal/30)*(nl-1);
System.out.print("Net salary is "+(nsal-ded));
}
}