Tuesday, November 4, 2014

, , , ,

Program to find L.C.M. of any two numbers using Command Line argument.

lcm calculator


Code Box

-------------------------------------------
/*Program to find L.C.M. of any two numbers command line argument*/

class lcmc
{
public static void main(String x[]) 
{
int num1,num2,a,b,count,ans,i;
ans=1;

a=Integer.parseInt(x[0]);
b=Integer.parseInt(x[1]);

System.out.print("\n----------------- L.C.M. Calculator ---------------");
System.out.print("\nEntered first number:"+a);
System.out.print("\nEntered second number:"+b);
num1=a;
num2=b;

//prime factors are 2,3,5,7

System.out.print("\nL.C.M. Factors => ");
for(i=7;i>=2;)
{
count=0;

if(num1%i==0)
{
num1=num1/i;
count=1;
}

if(num2%i==0)
{
num2=num2/i;
count=1;
}

if(count==0)
{
i--;
}
else
{
System.out.print("  "+i);
ans=ans*i;
}
}

//in case of prime number
System.out.print(" "+num1+" "+num2);
ans=ans*num1*num2;

System.out.print("\nL.C.M. of "+a+" & "+b+" is : "+ans);
System.out.print("\n\n-------------------------------------------");
}
}
Publisher: Brijmohan Lal Sahu - 4:58 AM

Sunday, November 2, 2014

, , , ,

Program to find factor of any number using command line argument.





Code Box
------------------------------------

/* Program to find factor of any number using command line argument */

class factor
{
public static void main(String x[])
{
int num,i;
System.out.print("\n---------Factor Finder--------");
num=Integer.parseInt(x[0]);
System.out.print("\nYou have enter :"+num);

System.out.print("\nFactors of "+num+" are : ");
for(i=1;i<num;i++)
{
if(num%i==0)
{
System.out.print("  "+i);
}

}

}
}



Publisher: Brijmohan Lal Sahu - 10:38 PM
, , , ,

Program to print given number is even or odd numbers using conditional operator in command line argument .



Code Box
------------------------------------------

/* Program to print given number is even or odd numbers using 
conditional operator in command line argument */


class evenc
{
public static void main(String x[])
{
int a;
String s;

a=Integer.parseInt(x[0]);

s=(a%2==0)?"a is even":"a is odd";

System.out.print("\n"+s);

}

}
Publisher: Brijmohan Lal Sahu - 3:41 AM
, , , ,

Program to print given number is even or odd numbers using if else in command line argument.




Code Box 
-----------------------------------

/* Program to print given number is even or odd numbers using 
if else in command line argument */


class even
{
public static void main(String x[])
{
int a;

a=Integer.parseInt(x[0]);

if(a%2==0)
{
System.out.print("\n a is Even ");
}
else
{
System.out.print("\n a is Odd ");
}

}

}
Publisher: Brijmohan Lal Sahu - 3:38 AM
, , , ,

Program to print greater number in 3 numbers using if else in command line argument.




Code Box
-----------------------------------------

/* Program to print greater number in 3 numbers using 
if else in command line argument */


class greaterif3
{
public static void main(String x[])
{
int a,b,c;

a=Integer.parseInt(x[0]);
b=Integer.parseInt(x[1]);
c=Integer.parseInt(x[2]);

if(a>b && b>c)
{
System.out.print("\n a is greater a="+a);
}
else
if(b>c)
{
System.out.print("\n b is greater b="+b);
}
else
{
System.out.print("\n c is greater c="+c);
}

}

}
Publisher: Brijmohan Lal Sahu - 3:35 AM
, , , ,

Program to print greater number in 2 numbers using if else in command line argument.



Code Box
-----------------------------------------

/* Program to print greater number in 2 numbers using 
if else in command line argument */


class greaterif
{
public static void main(String x[])
{
int a,b;

a=Integer.parseInt(x[0]);
b=Integer.parseInt(x[1]);

if(a>b)
{
System.out.print("\n a is greater a="+a);
}
else
{
System.out.print("\n b is greater b="+b);
}

}

}
Publisher: Brijmohan Lal Sahu - 3:32 AM