-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
761e185
commit c429ac7
Showing
5 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
public class HarmonicNumber { | ||
|
||
public static double har(int N) { | ||
double sum = 0.0; | ||
for (int i = 0; i <= N; i++) { | ||
sum += 1.0 / i; | ||
} | ||
return sum; | ||
} | ||
|
||
public static void main(String[] args) { | ||
System.out.println("Harmonic of given number is: "+har(15)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
public class Hypotenuse { | ||
public static double hypotenuse(double a, double b) { | ||
return Math.sqrt(a * a + b * b); | ||
} | ||
|
||
public static void main(String[] args) { | ||
System.out.println("Hypotenuse of given triangle is "+ hypotenuse(6,8)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
public class PrimeTest { | ||
public static boolean isPrime(int N) { | ||
if (N < 2) return false; | ||
for (int i = 2; i * i <= N; i++) { | ||
if (N % i == 0) return false; | ||
} | ||
return true; | ||
} | ||
|
||
public static void main(String[] args) { | ||
System.out.println("Is Given Number Is Prime: " + isPrime(511)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
public class SquareRoot { | ||
|
||
public static double sqrt(double c) { | ||
if (c <= 0) return Double.NaN; | ||
double err = 1e-15; | ||
double t = c; | ||
while (Math.abs(t - c / t) > err * t) { | ||
t = (c / t + t) / 2.0; | ||
} | ||
return t; | ||
} | ||
|
||
public static void main(String[] args) { | ||
System.out.println("Square root of given number is: "+ sqrt(144)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import java.util.Scanner; | ||
|
||
public class StaticExamples { | ||
public static int abs(int x) { | ||
if (x < 0) return -x; | ||
else return x; | ||
} | ||
|
||
public static double abs(double y) { | ||
if (y < 0.0) return -y; | ||
else return y; | ||
} | ||
|
||
public static void main(String[] args) { | ||
Scanner sc = new Scanner(System.in); | ||
System.out.println("Enter a Number(INT): "); | ||
int x = sc.nextInt(); | ||
|
||
int resultX = abs(x); | ||
System.out.println("The absolute value of " + x + " is " + resultX); | ||
|
||
System.out.println("Enter a Number(DOUBLE): "); | ||
double y = sc.nextDouble(); | ||
|
||
double resultY = abs(y); | ||
System.out.println("The absolute value of " + y + " is " + resultY); | ||
} | ||
} |