-
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.
Done few exercise at home , will do more tomorrow
- Loading branch information
1 parent
e78697b
commit 6233791
Showing
3 changed files
with
54 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,17 @@ | ||
/** | ||
* Write a recursive static method that computes the value of ln (N !) | ||
*/ | ||
public class FactorialLogarithm { | ||
public static double lnFactorial(int N) { | ||
if (N <= 1) { | ||
return 0; | ||
} else { | ||
return Math.log(N) + lnFactorial(N - 1); | ||
} | ||
} | ||
|
||
public static void main(String[] args) { | ||
int N = 5; | ||
System.out.println("Log of "+ N + " is: " + lnFactorial(N)); | ||
} | ||
} |
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,36 @@ | ||
import java.util.Scanner; | ||
|
||
/** | ||
* Write a program that reads in lines from standard input with each line containing | ||
* a name and two integers and then uses printf() to print a table with a column of | ||
* the names, the integers, and the result of dividing the first by the second, accurate to | ||
* three decimal places. You could use a program like this to tabulate batting averages for | ||
* baseball players or grades for students. | ||
*/ | ||
public class Print1121 { | ||
public static void printDetails() { | ||
|
||
System.out.println("Enter name and two integers (separated by spaces):"); | ||
Scanner sc = new Scanner(System.in); | ||
|
||
String input = sc.nextLine(); | ||
|
||
String[] parts = input.split(" "); | ||
|
||
if (parts.length != 3) { | ||
System.out.println("Invalid input format, please enter name and two integers (separated by spaces)"); | ||
} | ||
|
||
String name = parts[0]; | ||
int integer1 = Integer.parseInt(parts[1]); | ||
int integer2 = Integer.parseInt(parts[2]); | ||
|
||
double division = (double) integer1 / integer2; | ||
|
||
System.out.printf("%-15s %-10d %-10d %-10.3f%n", name, integer1, integer2, division); | ||
} | ||
|
||
public static void main(String[] args) { | ||
printDetails(); | ||
} | ||
} |