Vous êtes sur la page 1sur 7

use online gdb compiler to execute these

//Area of circle
public class Main
// always class should be Main
{

public static void main(String[] args) {

double r=Double.parseDouble(args[0]);

double a=(22*r*r)/7;

System.out.format("%.2f",a);

//even or odd
public class Main
{

public static void main(String[] args) {

int r=Integer.parseInt(args[0]);

if(r%2==0)

System.out.println("even");

else

System.out.println("not even");

}
}
//leap year
public class Main
{

public static void main(String[] args) {

int n=Integer.parseInt(args[0]);

if(n%4==0)

if(n%100==0)

if(n%400==0)
System.out.println("Leap Year");

else

System.out.println("Not Leap Year");

else

System.out.println("Leap Year");

else

System.out.println("Not Leap Year");

}
}
/// Area of triangle
public class Main
{

public static void main(String[] args) {

float b=Float.parseFloat(args[0]);

float h=Float.parseFloat(args[1]);

float a=b*h/2;

System.out.format("%.2f",a);

}
}

// pallindrome of a number

public class Main


{
public static void main(String[] args) {
int reverse=0,rem,temp;
int num = Integer.parseInt(args[0]);//for command line arguments

temp=num;
while(temp!=0)
{
rem=temp%10;
reverse=reverse*10+rem;
temp=temp/10;
}
if(reverse==num)
System.out.println("pallindrome");
else
System.out.println("not");
}
}
// palindrome of string

class Main// it should be main


{
public static void main(String args[])
{
String originalString, reverseString="";

originalString = args[0];

int length = originalString.length();

for ( int i = length - 1 ; i >= 0 ; i-- )


reverseString = reverseString + originalString.charAt(i);

if (originalString.equals(reverseString))
System.out.println("Entered string is a palindrome.");
else
System.out.println("Entered string is not a palindrome.");

}
}

// prime number

class Main
{
public static void main(String args[])
{
int num=Integer.parseInt(args[0]);

int i = 2;

boolean flag = false;

while(i <= num/2)


{

// condition for nonprime number

if(num % i == 0)

flag = true;

break;

++i;

}
if (!flag)

System.out.println(num + " is a prime number.");

else

System.out.println(num + " is not a prime number.");

}
}
// sum of a number

public class Main


{

public static void main(String[] args) {

int n;

int a=0,sum=0;

n=Integer.parseInt(args[0]);

while(n!=0)

a=n%10;

n=n/10;

sum=sum+a;

System.out.println("sum of digits:"+sum);

}
// fibanocci series
public class Main
{

public static void main(String[] args) {

int n1=0,n2=1,n3=0;
int sum=0,count;
count=Integer.parseInt(args[0]);
System.out.println(n1+" "+n2);
for(i=2;i<count;i++)
{
n3=n1+n2;
System.out.println(" "+n3);
n1=n2;
n2=n3;
}
}
}
// avg of 2 numbers

public class Main


{

public static void main(String[] args) {

float avg;

int sum=0;

int a=Integer.parseInt(args[0]);

int b=Integer.parseInt(args[1]);

sum=(a+b);

avg=(float)((sum)/2);

System.out.println(" "+avg);

}
}
// lcm of two numbers

public class Main


{

public static void main(String[] args) {

int gcd=1;

int a=Integer.parseInt(args[0]);

int b=Integer.parseInt(args[1]);

for(int i=1; i<=a&&i<=b;i++)

if(a%i==0&&b%i==0)

gcd=i;

int lcm=(a*b)/gcd;

System.out.println(" lcm: "+lcm);

}
}
// greatest of two

public class Main


{

public static void main(String[] args) {

int a=Integer.parseInt(args[0]);

int b=Integer.parseInt(args[1]);

if(a>b)

System.out.println(" a is great");

if(b>a)

System.out.println("b is grater");

}
}
}
// swap of 2

public class Main


{

public static void main(String[] args) {

int temp;

int a=Integer.parseInt(args[0]);

int b=Integer.parseInt(args[1]);

System.out.println("before swap a ="+a+"\n b="+b);

temp=a;

a=b;

b=temp;

System.out.println("after swap a ="+a+"\n b="+b );

}
}
// factorial of number

public class Main


{

public static void main(String[] args) {


int fact=1;

System.out.println("enter n");

int n=Integer.parseInt(args[0]);

for(int i=1;i<=n;i++)

fact= fact*i;

System.out.println(" "+fact );

}
}