Variable and Constant in Java:-

101
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
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.
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.

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
Tags

إرسال تعليق

101تعليقات

POST Answer of Questions and ASK to Doubt

  1. class Electro
    {
    public static void main(String args[])
    {
    int up=10,c=300;
    int eb=up*c;
    System.out.println(eb);
    }
    }

    ردحذف
  2. class Maxt
    {
    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);
    }
    }

    ردحذف
  3. class Middle
    {
    public static void main(String args[])
    {
    int a=247;
    int m;
    a=a/10;
    m=a%10;
    System.out.println("Middle Digit is: "+m);
    }
    }

    ردحذف
  4. 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);
    }
    }

    ردحذف
  5. import java.util.Scanner;
    class 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");
    }
    }

    ردحذف
  6. Q:- Example of non-static variable :-
    Solution:-
    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);
    }
    }

    ردحذف
  7. Q:- Complete Explanation of non-static Vairiable by Program:-
    Solution:-
    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);
    }
    }

    ردحذف
  8. Q:- WAP to calculate the multiplication of complex numbers ??
    Solution :-
    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");
    }
    }

    ردحذف
  9. Q:- Program to perform the addition of complex numbers ??
    Solution:-
    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");
    }
    }

    ردحذف
  10. class Ebill
    {
    public static void main(String args[])
    {
    int tunit=100, punit=4, ebill;
    ebill=tunit*punit;
    System.out.println(ebill);
    }
    }


    ردحذف
  11. // 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 ");
    }
    }
    }

    ردحذف
  12. //Multiplication of complex numbers

    class 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");
    }
    }

    ردحذف
  13. //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 ");
    }
    }
    }

    ردحذف
  14. // Middle numbers using three-digit number.


    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);
    }
    }

    ردحذف
  15. //Calculate the area of a circle where pi will be constant and radius will be variable.
    class 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);
    }
    }

    ردحذف
  16. // Calculate simple interest using instance type variable?

    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);
    }
    }


    ردحذف
  17. class Ebill
    {
    public static void main(String[]args)
    {
    int unitrate=10, totalunit=250, bill;
    bill= totalunit*unitrate;
    System.out.println("bill=" + bill);
    }
    }

    ردحذف
  18. class Complexadd
    {
    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");
    }
    }

    ردحذف
  19. class Complexadd
    {
    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");

    }
    }

    ردحذف
  20. class Complexadd
    {
    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");
    }
    }

    ردحذف
  21. class Complexadd
    {
    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");
    }
    }

    ردحذف
  22. class Obi
    {
    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);
    }
    }

    ردحذف
  23. class Circle
    {
    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);
    }
    }

    ردحذف
  24. class Simp
    {
    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);
    }
    }

    ردحذف
  25. class Mn
    {
    public static void main(String arg[])
    {
    int a=457;
    int b=a/10;
    int m=b%10;
    System.out.println(m);
    }
    }

    ردحذف
  26. class Area
    {
    public static void main(String arg[])
    {
    final int p=5;
    int r=2;
    int a=p*r*r;
    System.out.println(a);
    }
    }

    ردحذف
  27. class Sinterset
    {
    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);

    }}

    ردحذف
  28. class Temp
    {
    static float tc=50;
    static float f=tc*9/5+32;
    public static void main(String arg[])
    {

    System.out.println(Temp.f+"F");
    }
    }

    ردحذف
  29. class Complex
    {
    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");
    }
    }

    ردحذف
  30. class Max
    {
    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);
    }
    }
    }

    ردحذف
  31. class variable
    {
    public static void main(String args[])
    {
    int x=457;
    int y;
    y=x/10;
    int n=y%10;
    System.out.println(n);
    }
    }

    ردحذف
  32. class Acr
    {
    public static void main(String args[])
    {
    int r=45,pi=46;
    int a=pi*r*r;
    System.out.println(a);

    }

    ردحذف
  33. class A
    {
    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);
    }
    }

    ردحذف
  34. class cles
    {
    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();
    }
    }

    ردحذف
  35. class max
    {
    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();
    }
    }

    ردحذف
  36. class cles
    {

    static float cel=15;

    static float fah=((cel+9)/5+32);

    public static void main(String args[])
    {
    System.out.println(fah);

    }
    }

    ردحذف
  37. class Complex
    {
    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);
    }

    ردحذف
  38. class Complex
    {
    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)
    }

    ردحذف

  39. WAP 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)
    }
    }
    }

    ردحذف
  40. #NAYANSI PURWAR

    Q.)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);

    }
    }

    ردحذف
  41. package Basics;

    public 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);

    }

    }

    }

    ردحذف
  42. package Basics;

    public 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);



    }

    }

    ردحذف
  43. #NAYANSI PURWAR

    Q)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);
    }

    }
    }

    ردحذف
  44. #NAYANSI PURWAR

    Q)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);

    }
    }

    ردحذف
  45. Q.) WAP to calculate the area of a circle where pi will be constant and radius will be variable?

    sol-

    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);






    }
    }

    ردحذف
  46. Q) WAP to calculate simple interest using instance type variable?


    class 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);







    }
    }

    ردحذف
  47. //WAP to convert temperature from Celsius to Fahrenheit using static data members globally?


    class Celcius
    {
    static double Fahrenheit,Celcius=40;
    public static void main(String[] args)
    {
    Fahrenheit=(Celcius*1.8)+32;
    System.out.println("Celcius to Fahrenheit:"+Fahrenheit);

    }
    }

    ردحذف
  48. Q.)WAP to calculate electricity bill where unit price and total consumption will be assigned by the users?

    Program:
    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.");
    }
    }

    ردحذف
  49. WAP to calculate the multiplication of complex numbers?
    Program:
    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");
    }
    }

    ردحذف
  50. Program to perform the addition of complex numbers?
    Program:

    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");
    }
    }

    ردحذف
  51. WAP to find middle numbers using three-digit numbers?
    Program:

    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) ;
    }
    }

    ردحذف
  52. WAP to find the maximum number in any three-digit number?
    Program:
    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) ;
    }
    }
    }

    ردحذف
  53. WAP to calculate the area of a circle where pi will be constant and radius will be variable?
    Program:
    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);
    }
    }

    ردحذف
  54. WAP to calculate simple interest using instance type variable?
    Program:

    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);
    }
    }

    ردحذف
  55. WAP to convert temperature from Celsius to Fahrenheit using static data members globally?
    Program:
    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);
    }
    }

    ردحذف
  56. //WAP to calculate electricity bill where unit price and total consumption will be assigned by the users?

    class 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));
    }
    }

    ردحذف
  57. class Middle
    {
    public static void main(String args[])
    {
    int b,num=247;

    num=num/10;
    b=num%10;
    System.out.println(b);


    }}

    ردحذف
  58. class Complex_Multi
    {
    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);




    }
    }

    ردحذف


  59. import 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);





    }


    }

    ردحذف
  60. import java.util.Scanner;


    class 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);




    }
    }

    ردحذف
  61. //WAP to calculate electricity bill where unit price and total consumption will be assigned by the users?
    import 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);
    }
    }

    ردحذف
  62. //WAP to calculate salary where basic, ta, da, comm, pf,hra,no.ofleave will be assigned by the users?
    import 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);
    }
    }


    ردحذف
  63. //WAP to find middle numbers using three-digit numbers?

    class 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);
    }
    }

    ردحذف
  64. //WAP to calculate the area of a circle where pi will be constant and radius will be variable?

    import 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);
    }
    }

    ردحذف
  65. -WAP to calculate the area of a circle where pi will be constant and radius will be variable?

    import 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);
    }
    }

    ردحذف
  66. -WAP to calculate simple interest using instance type variable?

    class 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);


    }



    }

    ردحذف
  67. -WAP to calculate the area of a circle where pi will be constant and radius will be variable?

    import 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);
    }
    }

    ردحذف
  68. -WAP to multiply complex number

    class 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");
    }
    }

    ردحذف
  69. -WAP to find middle numbers using three-digit numbers?

    import 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);
    }
    }

    ردحذف
  70. -WAP to find the maximum number in any three-digit number?

    import 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);
    }
    }

    ردحذف
  71. //WAP to find the maximum number in any three-digit number?
    import 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);

    }
    }

    ردحذف



  72. 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);
    }
    }
    }

    ردحذف


  73. Ankita Verma

    class Middle
    {
    public static void main(String args[])
    {
    int x=457;
    x=x/10;
    int a=x%10;

    System.out.println(a);
    }
    }

    ردحذف
  74. Ankita Verma

    class 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);
    }
    }

    ردحذف
  75. Ankita Verma


    class 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);
    }
    }

    ردحذف
  76. Ankita Verma

    class 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);

    }
    }

    ردحذف
  77. class convert
    {
    static float celsious=52,fahrenheit;
    public static void main(String args[])
    {
    fahrenheit=(celsious*9/5)+32;
    System.out.println("TEMPRATURE IN FAHRENHEIT IS:- "+fahrenheit);
    }
    }

    ردحذف
  78. class SI
    {
    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);
    }
    }

    ردحذف
  79. class bill
    {
    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);
    }
    }

    ردحذف
  80. class circlearea
    {
    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);
    }

    }

    ردحذف
  81. class middleno
    {
    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);
    }
    }

    ردحذف
  82. class Complex
    {

    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");

    }

    }

    ردحذف
  83. class Middle
    {
    public static void main(String args[])
    {
    int a=378;
    int m;
    a=a/10;
    m=a%10;
    System.out.println("Middle Digit= "+m);
    }
    }

    ردحذف
  84. class Max
    {
    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);
    }
    }
    }

    ردحذف
  85. class AreaOfCircle
    {
    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);
    }

    ردحذف
  86. public class SimpleInt {
    int 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);


    }

    }

    ردحذف
  87. public class Bill3 {


    public static void main(String args[])
    {

    int up=10,c=300;
    int eb=up*c;
    System.out.println(eb);
    }
    }

    ردحذف
  88. import java.util.Scanner;
    public 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);
    }
    }

    ردحذف
  89. import java.util.Scanner;
    class 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");

    }


    }

    ردحذف
  90. //yogesh seroke
    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");

    }

    ردحذف
  91. //yogesh seroke
    //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");

    }
    }

    ردحذف
  92. //yogesh seroke
    // electricity bill
    class Ebill
    {
    public static void main(String args[])
    {
    int tunit=100, punit=4, ebill;
    ebill=tunit*punit;
    System.out.println(ebill);
    }
    }

    ردحذف
  93. // yogesh seroke
    // 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 ");
    }
    }
    }

    ردحذف
  94. // yogesh seroke
    // 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)
    }
    }
    }

    ردحذف
  95. // yogesh seroke
    // 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);
    }
    }

    ردحذف
  96. // yogesh seroke
    // 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);
    }
    }

    ردحذف
  97. // yogesh seroke
    // 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);
    }
    }

    ردحذف
  98. // yogesh seroke
    // 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);
    }
    }

    ردحذف
  99. // 1)WAP to calculate electricity bill where unit price and total consumption will be assigned by the users?
    class Electricbill
    {
    public static void main(String args[])
    {
    int up = 10;
    int con = 500;
    int elecbill = up*con;
    System.out.println(elecbill);


    }
    }

    ردحذف
  100. Salary Calculator
    class 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));



    }


    }

    ردحذف
  101. package baser;

    public class MaxDigit {
    public static void main(String[] args) {


    int num = 798;
    int d1=num%10;

    num = num/10;

    int d2=num%10;
    num = num/10;

    int d3 = num%10;
    num=num/10;

    if(d1>d2) {
    if(d1>d3) {
    System.out.println("gr8 num is:"+d1);

    }

    }
    else if(d2>d3) {
    System.out.println("gr8 no is :"+ d2);
    }
    else {
    System.out.println("gr8 no is:"+d3);
    }


    }
    }

    ردحذف
إرسال تعليق