You are on page 1of 5

1.

Count the number of legs and head of rabbit and chicken

import java.util.Scanner;

public class Main{

public static void main(String args[])

Scanner obj =new Scanner(System.in);

int c, r;

int h=obj.nextInt();

int l=obj.nextInt();

r = l/4 ;

c = h – r;

System.out.println("Rabbits = " + r);

System.out.println("Chicken = " + c);

}
2.Volume

import java.util.*;

public class Main

public static void main(String[] args) {

int l,b,t;

Scanner scan =new Scanner(System.in);

l= scan.nextInt();

b= scan.nextInt();

t= scan.nextInt();

int h=b;

double R=l/(2*(3.14));

double r=R-t;

double V=3.14*h*(Math.pow(R,2)); double v=3.14*h*(Math.pow(r,2));

double vol=V-v;

System.out.println(vol);

}
3.Factorial

import java.util.*;

public class Main

int fact(int n){

int f=1;

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

f=f*i;

return f;

public static void main(String[] args) {

Scanner obj = new Scanner(System.in);

int n=obj.nextInt();

int arr[]=new int[n];

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

arr[i]=obj.nextInt();

System.out.println("The Factorial values are: \n");

for(int i=0;i<n;i++){

if(arr[i]<=10)

System.out.println(new Main().fact(arr[i]));

}
4. Company Employee

import java.util.*;

import java.lang.String.*;

public class Main{

public static void main(String args[])

Scanner obj = new Scanner(System.in);

String n = obj.nextLine();

int cost=0;

String[] strarr = null;

strarr = n.split(" ");

String Keywords[]={"if","case","break","continue","for","class","public"};

for(String x : strarr){

for(String y:Keywords){

if(x.equals(y))

cost+=2000;

}
System.out.println("The cost is = "+cost);

You might also like