diff --git a/Programs/AllTraversal.java b/Programs/Java/AllTraversal.java similarity index 100% rename from Programs/AllTraversal.java rename to Programs/Java/AllTraversal.java diff --git a/Programs/Java/AverageSum.java b/Programs/Java/AverageSum.java new file mode 100644 index 0000000..3770a6d --- /dev/null +++ b/Programs/Java/AverageSum.java @@ -0,0 +1,24 @@ +import java.util.Scanner; + +public class AverageSum { + public static void main(String[] args) { + Scanner input = new Scanner(System.in); + System.out.print("Enter n numbers to get Average "); + int n = input.nextInt(); + int count = 0; + int sum = 0; + int rem = 1; + if (n==0) { + System.out.println("Please Enter value greater than 0"); + System.exit(0); + + } + while(n>0){ + rem = n%10; + sum = sum+rem; + count+=1; + n=n/10; + } + System.out.println("Average is "+sum/count); + } +} diff --git a/Programs/BalanceBrackets.java b/Programs/Java/BalanceBrackets.java similarity index 100% rename from Programs/BalanceBrackets.java rename to Programs/Java/BalanceBrackets.java diff --git a/Programs/Breadthfirstsearch.java b/Programs/Java/Breadthfirstsearch.java similarity index 100% rename from Programs/Breadthfirstsearch.java rename to Programs/Java/Breadthfirstsearch.java diff --git a/Programs/DFS.java b/Programs/Java/DFS.java similarity index 96% rename from Programs/DFS.java rename to Programs/Java/DFS.java index cb675a3..19b4bec 100644 --- a/Programs/DFS.java +++ b/Programs/Java/DFS.java @@ -229,4 +229,4 @@ public static void main(String[] args) //passing the starting vertex to the function g.DFS(2); } -} \ No newline at end of file +} diff --git a/Programs/DetectLoop.java b/Programs/Java/DetectLoop.java similarity index 100% rename from Programs/DetectLoop.java rename to Programs/Java/DetectLoop.java diff --git a/Programs/Java/Factor.java b/Programs/Java/Factor.java new file mode 100644 index 0000000..e0b5e62 --- /dev/null +++ b/Programs/Java/Factor.java @@ -0,0 +1,17 @@ +import java.util.Scanner; + +public class Factor{ + public static void main(String[] args) { + Scanner input = new Scanner(System.in); + System.out.println("------------------Program to print factor of n numbers------------------"); + System.out.print("Enter N number "); + int n = input.nextInt(); + System.out.print("Factor of "+n+" is: "); + for (int i = 1;i<=n;i+=1 ) { + if (n%i==0) { + System.out.print(" "+i+" "); + } + + } + } +} diff --git a/Programs/Java/Factorial.java b/Programs/Java/Factorial.java new file mode 100644 index 0000000..b357cf9 --- /dev/null +++ b/Programs/Java/Factorial.java @@ -0,0 +1,15 @@ +import java.util.Scanner; + +public class Factorial { + public static void main(String[] args) { + Scanner input = new Scanner(System.in); + System.out.print("Enter a number to get factorial of it "); + int n = input.nextInt(); + int m = 1; + while(n>0){ + m = m*n; + n-=1; + } + System.out.println("Fortorial is "+m); + } +} diff --git a/Programs/Longest substring without repeating character.java b/Programs/Java/Longest substring without repeating character.java similarity index 95% rename from Programs/Longest substring without repeating character.java rename to Programs/Java/Longest substring without repeating character.java index 090e763..35cee17 100644 --- a/Programs/Longest substring without repeating character.java +++ b/Programs/Java/Longest substring without repeating character.java @@ -29,4 +29,4 @@ public static void main(String[] args) int result = lengthOfLongestSubstring(s); System.out.println(res); } -} \ No newline at end of file +} diff --git a/Programs/Recursive_binarysearch.java b/Programs/Java/Recursive_binarysearch.java similarity index 100% rename from Programs/Recursive_binarysearch.java rename to Programs/Java/Recursive_binarysearch.java diff --git a/Programs/ReverseLinkedList.java b/Programs/Java/ReverseLinkedList.java similarity index 100% rename from Programs/ReverseLinkedList.java rename to Programs/Java/ReverseLinkedList.java diff --git a/Programs/String to LowerCase.java b/Programs/Java/String to LowerCase.java similarity index 95% rename from Programs/String to LowerCase.java rename to Programs/Java/String to LowerCase.java index 31652f5..6ec56eb 100644 --- a/Programs/String to LowerCase.java +++ b/Programs/Java/String to LowerCase.java @@ -29,4 +29,4 @@ static String toLower(String S) { return S1; } -} \ No newline at end of file +} diff --git a/Programs/frequency_sort.java b/Programs/Java/frequency_sort.java similarity index 100% rename from Programs/frequency_sort.java rename to Programs/Java/frequency_sort.java diff --git a/Programs/jatin_game.java b/Programs/Java/jatin_game.java similarity index 100% rename from Programs/jatin_game.java rename to Programs/Java/jatin_game.java diff --git a/Programs/number_diamond.java b/Programs/Java/number_diamond.java similarity index 96% rename from Programs/number_diamond.java rename to Programs/Java/number_diamond.java index d09e164..7eff24f 100644 --- a/Programs/number_diamond.java +++ b/Programs/Java/number_diamond.java @@ -34,4 +34,4 @@ public static void main(String[] args) { } } -} \ No newline at end of file +} diff --git a/Programs/stringReverse.java b/Programs/Java/stringReverse.java similarity index 100% rename from Programs/stringReverse.java rename to Programs/Java/stringReverse.java diff --git a/Programs/zigzagPattern.java b/Programs/Java/zigzagPattern.java similarity index 94% rename from Programs/zigzagPattern.java rename to Programs/Java/zigzagPattern.java index 5acaf31..0db399b 100644 --- a/Programs/zigzagPattern.java +++ b/Programs/Java/zigzagPattern.java @@ -56,4 +56,4 @@ public static void zigzag(int [][] a, int r, int c){ } } -} \ No newline at end of file +}