Skip to content

Commit

Permalink
Done few exercise at home , will do more tomorrow
Browse files Browse the repository at this point in the history
  • Loading branch information
jaypatel208 committed Nov 25, 2023
1 parent e78697b commit 6233791
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions src/FactorialLogarithm.java
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));
}
}
36 changes: 36 additions & 0 deletions src/Print1121.java
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();
}
}

0 comments on commit 6233791

Please sign in to comment.