0% found this document useful (0 votes)
11 views5 pages

Bka BK AN

kbkjbs'jc

Uploaded by

Nusrat Rahman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views5 pages

Bka BK AN

kbkjbs'jc

Uploaded by

Nusrat Rahman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 5

Method

////Task 01(A)

public class T1 {
public static void numChecker(int num) {
if (num % 2 == 0) {
System.out.println("Even!!");
} else {
System.out.println("Odd!!");
}
}

public static void main(String[] args) {


numChecker(10);
numChecker(17);
}
}

/////Task 01(B)

public class T2 {
public static boolean even(int num) {
return num % 2 == 0;
}

public static void main(String[] args) {


boolean res1 = even(10);
System.out.println(res1);

boolean res2 = even(17);


System.out.println(res2);
}
}

///Task 01(C)

public class T3{


public static boolean isPos(int num) {
return num > 0;
}

public static void main(String[] args) {


boolean res1 = isPos(-5);
System.out.println(res1);

boolean res2 = isPos(12);


System.out.println(res2);
}
}

////Task 01(D)

public class T4 {
public static boolean even(int num) {
return num % 2 == 0;
}

public static boolean pos(int num) {


return num > 0;
}

public static void seq(int n) {


if (pos(n)) {
for (int i = 0; i <= n; i++) {
if (even(i)) {
System.out.print(i + " ");
}
}
} else {
for (int i = n; i < 0; i++) {
if (!even(i)) {
System.out.print(i + " ");
}
}
}
System.out.println();
}

public static void main(String[] args) {


seq(10);
seq(-7);
seq(7);
seq(-8);
}
}

//////Task 02(A)

public class T1{

public static double area(int rad) {


return Math.PI * Math.pow(rad, 2);
}

public static void main(String[] args) {


double area = area(5);
System.out.println(area);
}
}

/////Task 02(B)

public class T2 {
public static double sphereVol(int rad) {
return (4.0 / 3.0) * Math.PI * Math.pow(rad, 3);
}

public static void main(String[] args) {


double volume = sphereVol(5);
System.out.println(volume);
}
}

/////Task 02(C)

public class T3 {

public static double circleArea(int rad) {


return Math.PI * Math.pow(rad, 2);
}

public static double sphereVolume(int rad) {


return (4.0 / 3.0) * Math.PI * Math.pow(rad, 3);
}

public static void findSpace(int dia, String type) {


int rad = dia/ 2;

if (type.equalsIgnoreCase("circle")) {

double area = circleArea(rad);


System.out.println(area);
} else if (type.equalsIgnoreCase("sphere")) {

double volume = sphereVolume(rad);


System.out.println(volume);
} else {

System.out.println("Wrong Parameter");
}
}

public static void main(String[] args) {


findSpace(10, "circle");
findSpace(5, "sphere");
findSpace(10, "square");
}
}

////Task 03

public class T3{

public static boolean isPrime(int num) {


if (num <= 1) {
return false;
}

for (int i = 2; i <= Math.sqrt(num); i++) {


if (num % i == 0) {
return false;
}
}

return true;
}

public static void main(String[] args) {


boolean c1 = isPrime(7);
System.out.println(c1);

boolean c2 = isPrime(15);
System.out.println(c2);
}
}

////Task 4

public class T4 {

public static boolean isPerfect(int num) {

if (num < 2) {
return false;
}

int s = 0;

for (int j = 1; j <= num / 2; j++) {


if (num % j == 0) {
s += j;
}
}

return s == num;
}

public static void main(String[] args) {


boolean c1 = isPerfect(6);
System.out.println(c1);

boolean c2 = isPerfect(33);
System.out.println(c2);
}
}
////Task 05

public class T5 {

public static double calcTax(int age, double sal) {

if (age < 18 || sal < 10000) {


return 0.0;
}

if (sal >= 10000 && sal<= 20000) {


return sal * 0.07;
}

if (sal > 20000) {


return sal * 0.14;
}

return 0.0;
}

public static void main(String[] args) {


double t11 = calcTax(16, 20000);
System.out.println(t11);

double t22 = calcTax(20, 18000);


System.out.println(t22);

double t32 = calcTax(25, 25000);


System.out.println(t32);
}
}

You might also like