Showing posts with label Commandline. Show all posts
Showing posts with label Commandline. Show all posts

Wednesday, 18 September 2013

Java Program to find Square Root of a number through Commandline

import java.lang.Math;

class Squareroot
{
     public static void main (String args[])
     {
          float num,sqnum;
          num = Float.valueOf(args[0]).floatValue();
          sqnum = (float)Math.sqrt(num);
          System.out.println("Square Root of "+num+" is "+sqnum);
     }
}    


Output:

Wednesday, 11 September 2013

Java Program to find factorial of a given number through Commandline

class Factorial
{
     public static void main(String ar[])
     {
          int n=Integer.parseInt(ar[0]);
          int f=0;
           
          fact(n);
     }
      
     static void fact(int n1)
     {
          int f=1;
          for(int i=1;i<=n1;i++)
          {
               f=f*i;
          }
          System.out.println("Factrorial is = "+f);
     }
} 


Output:

Tuesday, 10 September 2013

Java Program to find out entered number is armstrong or not through Commandline

class Arm
{
     public static void main(String ar[])
     {
          int num=Integer.parseInt(ar[0]);
          int n=num;
          int check=0,remainder;
          
          while(num>0)
          {
               remainder=num%10;
               check=check+(int) Math.pow(remainder,3);
               num=num/10;
          }
          
          if(check==n)
          {
               System.out.println("This is armstrong number");
          }
          else
          {
               System.out.println("This is not armstrong number");
          }
     }
}


Output:

Monday, 9 September 2013

Java Program to make table of user entered a number through Commandline

class Table
{
     public static void main(String ar[])
          {
               int num=Integer.parseInt(ar[0]);
               for(int i=1;i<=10;i++)
               {
                    System.out.println(+num +"*"+ i +"=" + (num*i));
               }
                 
          }
}               


Output: