Beruflich Dokumente
Kultur Dokumente
//Area of circle
public class Main
// always class should be Main
{
double r=Double.parseDouble(args[0]);
double a=(22*r*r)/7;
System.out.format("%.2f",a);
//even or odd
public class Main
{
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
{
int n=Integer.parseInt(args[0]);
if(n%4==0)
if(n%100==0)
if(n%400==0)
System.out.println("Leap Year");
else
else
System.out.println("Leap Year");
else
}
}
/// Area of triangle
public class Main
{
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
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
originalString = args[0];
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;
if(num % i == 0)
flag = true;
break;
++i;
}
if (!flag)
else
}
}
// sum of a number
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
{
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
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
int gcd=1;
int a=Integer.parseInt(args[0]);
int b=Integer.parseInt(args[1]);
if(a%i==0&&b%i==0)
gcd=i;
int lcm=(a*b)/gcd;
}
}
// greatest of two
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
int temp;
int a=Integer.parseInt(args[0]);
int b=Integer.parseInt(args[1]);
temp=a;
a=b;
b=temp;
}
}
// factorial of number
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 );
}
}