Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added code to Java Tutorial Programs #232

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions Java Tutorial Program/FactorialRecursion.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import java.io.*;
import java.util.*;

public class FactorialRecursion {

public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
int f = factorial(n);
System.out.println(f);
}

public static int factorial(int n) {
if(n == 0){
return 1;
}
int fm1 = factorial(n - 1);
int f = fm1 * n;
return f;
}

}




28 changes: 28 additions & 0 deletions Java Tutorial Program/ZigZag.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import java.io.*;
import java.util.*;

public class ZigZag {

public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
pzz(n);
}

public static void pzz(int n) {
if(n == 0){
return;
}

System.out.print(n + " ");
pzz(n - 1);
System.out.print(n + " ");
pzz(n - 1);
System.out.print(n + " ");
}

}