Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0313e94

Browse files
committed
splitting functions into small blocks
1 parent bdb2470 commit 0313e94

File tree

2 files changed

+78
-48
lines changed

2 files changed

+78
-48
lines changed

src/binod/AreaSquare.java

Lines changed: 0 additions & 48 deletions
This file was deleted.

src/binod/FunctionDemo.java

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
package binod;
2+
public class FunctionDemo {
3+
public static void printHelloWorld() {
4+
System.out.println("Hello World");
5+
}
6+
7+
public static double calculateSquare(double side) {
8+
double area = side * side;
9+
return area;
10+
}
11+
12+
public static void swap(int a, int b) {
13+
//swap
14+
int temp = a;
15+
a = b;
16+
b = temp;
17+
System.out.println("a=" + a);
18+
System.out.println("b=" + b);
19+
}
20+
21+
public static int findProduct(int a, int b) {
22+
int product = a * b;
23+
return product;
24+
}
25+
26+
public static int findFactorial(int n) {
27+
int fact = 1;
28+
for (int i = 1; i <= n; i++) {
29+
fact *= i;
30+
}
31+
return fact;
32+
}
33+
34+
public static double findBinomialCoefficient(int n, int r) {
35+
double nfac = findFactorial(n);
36+
double rfac = findFactorial(r);
37+
double nrfac = findFactorial(n - 1);
38+
double bc = nfac / (rfac * nrfac);
39+
return bc;
40+
}
41+
42+
public static boolean isPrime(int n) {
43+
//1 is neither composite nor prime
44+
//checking for 2
45+
if (n == 2) {
46+
return true;
47+
}
48+
for (int i = 2; i <= Math.sqrt(n); i++) {
49+
if (n % i == 0) {
50+
return false;
51+
}
52+
}
53+
return true;
54+
}
55+
56+
public static void printPrime(int range) {
57+
for (int i = 2; i <= range; i++) {
58+
if (isPrime(i) == true) {
59+
System.out.println(i);
60+
}
61+
}
62+
}
63+
64+
public static void main(String[] args) {
65+
// Scanner scanner = new Scanner(System.in);
66+
// System.out.println("Enter side of a square");
67+
// double side = scanner.nextDouble();
68+
// printHelloWorld();
69+
// double area = calculateSquare(side);
70+
// System.out.println("The area of square is: " + area);
71+
// swap(1, 2);
72+
// System.out.println(findProduct(2, 3));
73+
// System.out.println(findFactorial(3));
74+
// System.out.println(findBinomialCoefficient(4, 2));
75+
// System.out.println(isPrime(12));
76+
printPrime(10);
77+
}
78+
}

0 commit comments

Comments
 (0)