code

WRITE A PROGRAM TO PRINT A BINARY RIGHT ANGLED TRIANGLE UPTO N TERMS IN JAVA

class Btri { public static void main(String args[])         {             int i, j,n;           n=Integer.parseInt(args[0]);                          for (i = 1; i <= n; i++)             {                 for (j = 1; j <= i; j++)                 {                     if (j % 2 == 0)                     {                         System.out.print(“0 “);                     }                     else                     {                         System.out.print(“1 “);                     }                 }                     System.out.println(“”);             }          }       } OUTPUT:

WRITE A PROGRAM TO CHECK WHETHER A NUMBER IS ARMSTRONG NUMBER OR NOT IN JAVA

class ArmstrongNumber  {     public static void main(String args[])      {         int n, temp , r, s=0 ;         n=Integer.parseInt(args[0]);         temp = n;         while (temp != 0)        {             r = temp % 10;             s = s + (r * r * r);             temp = temp / 10;         }         if (n== s)        {             System.out.println(” It is an Armstrong Number”); …

WRITE A PROGRAM TO CHECK WHETHER A NUMBER IS ARMSTRONG NUMBER OR NOT IN JAVA Read More »

WRITE A PROGRAM TO FIND THE FIBONACCI SERIES UPTO N TERMS IN JAVA

class Fibonacci { public static void main(String args[]) { int num = Integer.parseInt(args[0]);  System.out.println(“**Fibonacci Series**”); int f1, f2=0, f3=1; for(int i=1;i<=num;i++) { System.out.print(” “+f3+” “); f1 = f2; f2 = f3; f3 = f1 + f2; } } } OUTPUT:

WRITE A PROGRAM TO FIND THE PRIME NUMBERS BETWEEN 1 TO 100 In JAVA.

class prime  {      public static void main(String args[])      {          int i,k,j;          for(i=1;i<100;i++)          {              k=0;              for(j=2;j<i;j++)              {                  if(i%j==0)                  {                      k=1;                      break;                  }              }              if(k==0)              {                  System.out.print(” “+i);              }          }      }  } OUTPUT: