Posts

Showing posts with the label java programme

Data type and its memory size( java)

Image
 

program to calculate perimeter of rectangle

  class perimeter { public static void main(String args[]) {  int peri, length, breadth;  length=10; breadth=29; peri=2*(breadth+length); System.out.println(peri); }}

programe to calculate area of rectangle

 class area { public static void main(String args[]) {  int area, length, breadth;  length=10; breadth=29; area=breadth*  length; System.out.println(area); }}

program to convert binary to decimal(using java)

  class binary_decimal { public static void main(String args[]) { int  no=1101,b=0,sum=0,i=0; while(no>0) { b=n0%10; no=no/10; sum=sum+(int) b* Math.pow(2,i++); } System.out.println(sum); } }

check the number is binary or not(using java)

 // a number is said to binary if all the digit should be either zero or one ex-1011  binary number    ex-1201 not binary number class binary { public static void main(String args[]) { int  no=125,b=0,e=0; while(no>0) { b=n0%10; no=no/10; if(b>1) { e=1; break; } } if(e==0) System.out.println("the number is binary"); else System.out.println("the number is not binary"); } }

program to caluclate automerphic number(using java)

// if a number is present at the end of its square ex- 25   sqr=625  (25 is present at the end of 625)  class automerphic { public static void main(String args[]) { int  no=125, sqr=0,b=0,c=0,e=0; sqr=no* no; while(no>0 && sqr>0) { b=n0%10; no=no/10; c=sqr%10; sqr=sqr/10; if( b !=c) { e=1;     // e is the marking symbol break; }} if(e==0) System.out.println("automerphic"); else System.out.println("not auto merphic"); } }

program to find smallest digit of a number(using java)

  class smallest  { public static void main(String args[]) { int  no=125, small=9,b=0; while(no>0) { b=n0%10; no=no/10; if(b<small) small=b; } System.out.println(small); } }

program to find greatest digit of a number(using java)

  // a=125  ans-5 class greatest { public static void main(String args[]) { int  no=125, great=0,b=0; while(no>0) { b=n0%10; no=no/10; if(b>great) great=b; } System.out.println(great); } }

programe to add all the digit of a number (using java)

  // ex-125  ans-1+2+5=8 class add_digit { public static void main(String args[]) { int  no=125, sum=0,b=0; while(no>0) { b=n0%10; no=no/10; sum=sum+b; } System.out.println(sum); } }

check the number is Amstrong (using java)

// if the addition of cube of all the digit of a number is same as original number  ex- 153  1^3+5^3+3^3=153   class amstrong { public static void main(String args[]) { int  no=125, sum=0,copy=0,b=0; while(no>0) { b=n0%10; no=no/10; sum=sum+b * b * b; } if(copy= =sum) System.out.println("amstrong number"); else System.out.println("not amstrong"); } }

check the number is palin drome(using java)

  // if the reverse of a number is same as original number then the number is palindrome // ex- a=121  ans -121     a=125 ans -521 is not palindrome class palindrome { public static void main(String args[]) { int  no=125, rev=0,b=0 copy=no; while(no>0) { b=n0%10; no=no/10; rev=rev *10+b; } if(copy==rev) System.out.println("palindrome"); else System.out.println("not palindrome"); } }

print reverse of a number(using java)

// a=125  ans-521;   class reverse { public static void main(String args[]) { int  no=125, rev=0,b=0; while(no>0) { b=n0%10; no=no/10; rev=rev *10+b; } System.out.println(rev); } }

calculate LCM of two number (using java)

  class lcm { public static void main(String args[]) { int a=10,b=4,LCM=0; for(int i=Math.max(a,b); i<=a*b ; i++) { if(i%a==0 && i%b==0) { LCM=i break; }} System.out.println(LCM); }}

calculate HCF

  class hcf { public static void main(String args[]) { int  a=10,b=12,HCF=0; for(int i=1; i<=Math.min(a,b) ; i++) { if(a%i==0 && b%i==0) HCF=i } System.out.println(HCF); }}

find fibonic series (using java)

// fibonic number 0,1,1,2,3,5..   class fibonic { public static void main(String args[]) { int a=0,b=1,sum=0; System.out.println(a); System.out.println(b); for(int i=1; i<=n ; i++) { sum=a+b; a=b; b=sum; System.out.println(sum); } }}

Calculate factorial of a number(using java)

 // factorial of a number 5!=  5*4*3*2*1      =120 class factorial { public static void main(String args[]) { int no=10,fact=1; for(int i=1; i<=no ; i++) { fact=fact*i; } System.out.println(fact); }}

check the number is perfect (using java)

 //if the addition of factors of a number except that number is same as original number then the number is perfect ex n0=6  factor 1,2,3  that means 1+2+3=6  then it is perfect number class perfect { public static void main(String args[]) { int no=10,sum=0; for(int i=1; i<no ; i++) { if(no%i==0)  // i is the factor of that number { sum=sum+i } } if(sum==no) System.out.println("perfect number"); else System.out.println("not"); }}

check the number is prime (using java)

 class prime { public static void main(String args[]) { int no=10,count=0; for(int i=1; i<=no ; i++) { if(no%i==0)  // i is the factor of that number { count++; } } if(count==2) System.out.println("prime no"); else System.out.println("composite no"); }}

simple intrest program

double p,t,r si; p=1000; t=5; r=3; si=p×t×r; System.out.println(si);

Swapp two number using third variable

int a,b,c; a=5; b=6; c=a; a=b; b=c; System.out.println(a+""+b);