diff --git a/Area&CircumfrenceofCircle b/Area&CircumfrenceofCircle new file mode 100644 index 0000000..2a96580 --- /dev/null +++ b/Area&CircumfrenceofCircle @@ -0,0 +1,19 @@ +import java.util.Scanner; +class CircleDemo +{ + static Scanner sc = new Scanner(System.in); + public static void main(String args[]) + { + System.out.print("Enter the radius: "); + /*We are storing the entered radius in double + * because a user can enter radius in decimals + */ + double radius = sc.nextDouble(); + //Area = PI*radius*radius + double area = Math.PI * (radius * radius); + System.out.println("The area of circle is: " + area); + //Circumference = 2*PI*radius + double circumference= Math.PI * 2*radius; + System.out.println( "The circumference of the circle is:"+circumference) ; + } +} diff --git a/CheckPrimeNumber b/CheckPrimeNumber new file mode 100644 index 0000000..f7f0b9e --- /dev/null +++ b/CheckPrimeNumber @@ -0,0 +1,19 @@ +public class PrimeExample{ + public static void main(String args[]){ + int i,m=0,flag=0; + int n=3;//it is the number to be checked + m=n/2; + if(n==0||n==1){ + System.out.println(n+" is not prime number"); + }else{ + for(i=2;i<=m;i++){ + if(n%i==0){ + System.out.println(n+" is not prime number"); + flag=1; + break; + } + } + if(flag==0) { System.out.println(n+" is prime number"); } + }//end of else +} +} diff --git a/Factorial b/Factorial new file mode 100644 index 0000000..6b6ee15 --- /dev/null +++ b/Factorial @@ -0,0 +1,13 @@ +//https://www.facebook.com/srishti.agrawal.714/posts/162113345582696 +//Subscribed by Srishti Agrawal +public class Factorial +{ + public static void main(String[] args) + { + int n=Integer.parseInt(args[0]); + int f=1; + for(int i=1;i<=n;i++) + f*=i; + System.out.println("Factorial is "+ f); + } +} diff --git a/FactorialProgram b/FactorialProgram new file mode 100644 index 0000000..335fbca --- /dev/null +++ b/FactorialProgram @@ -0,0 +1,10 @@ +class FactorialExample{ + public static void main(String args[]){ + int i,fact=1; + int number=5;//It is the number to calculate factorial + for(i=1;i<=number;i++){ + fact=fact*i; + } + System.out.println("Factorial of "+number+" is: "+fact); + } +} diff --git a/Fibonacci b/Fibonacci new file mode 100644 index 0000000..52aa8eb --- /dev/null +++ b/Fibonacci @@ -0,0 +1,19 @@ +public class FibonacciSeries { + + public static void main(String[] args) { + printFibonacciSeries(10); + } + + public static void printFibonacciSeries(int count) { + int a = 0; + int b = 1; + int c = 1; + for (int i = 1; i <= count; i++) { + System.out.print(a + ", "); + a = b; + b = c; + c = a + b; + } + + } +} diff --git a/Fibonacci Series b/Fibonacci Series new file mode 100644 index 0000000..e0f0779 --- /dev/null +++ b/Fibonacci Series @@ -0,0 +1,17 @@ +public class Fibonacci { + + public static void main(String[] args) { + + int n = 10, t1 = 0, t2 = 1; + System.out.print("First " + n + " terms: "); + + for (int i = 1; i <= n; ++i) + { + System.out.print(t1 + " + "); + + int sum = t1 + t2; + t1 = t2; + t2 = sum; + } + } +} diff --git a/HelloWorld b/HelloWorld new file mode 100644 index 0000000..e1a0fdb --- /dev/null +++ b/HelloWorld @@ -0,0 +1,5 @@ +class HelloWorld { + public static void main(String[] args) { + System.out.println("Hello, World!"); + } +} diff --git a/MyHelloWorld b/MyHelloWorld new file mode 100644 index 0000000..e1a0fdb --- /dev/null +++ b/MyHelloWorld @@ -0,0 +1,5 @@ +class HelloWorld { + public static void main(String[] args) { + System.out.println("Hello, World!"); + } +} diff --git a/Palindrome b/Palindrome new file mode 100644 index 0000000..00f167d --- /dev/null +++ b/Palindrome @@ -0,0 +1,21 @@ +//https://www.facebook.com/srishti.agrawal.714/posts/162113345582696 +//Subscribed by Code House +import java.util.Scanner; +class Palindrome { + public static void main(String args[]) { + Scanner input=new Scanner(System.in); + int rem,sum=0,rev; + int n=input.nextInt();//It is the number variable to be checked for palindrome + + rev=n; + while(n>0) { + rem=n%10; //getting remainder + sum=(sum*10)+rem; + n=n/10; + } + if(rev==sum) + System.out.println("It is a palindrome number "); + else + System.out.println("It is not a palindrome number"); +} +} diff --git a/Postordertraversal.java b/Postordertraversal.java new file mode 100644 index 0000000..2ecdd71 --- /dev/null +++ b/Postordertraversal.java @@ -0,0 +1,54 @@ +# https://www.facebook.com/dikshit.kaushal.564/posts/103324861581146 +# Subscribed By Dikshit Kaushal + +class Node { + int item; + Node left, right; + + public Node(int key) { + item = key; + left = right = null; + } +} + +class Tree { + // Root of Binary Tree + Node root; + + Tree() { + root = null; + } + + void postorder(Node node) { + if (node == null) + return; + + // traverse the left child + postorder(node.left); + + // traverse the right child + postorder(node.right); + + // traverse the root node + System.out.print(node.item + "->"); + } + + public static void main(String[] args) { + + // create an object of Tree + Tree tree = new Tree(); + + // create nodes of the tree + tree.root = new Node(1); + tree.root.left = new Node(12); + tree.root.right = new Node(9); + + // child nodes of left child + tree.root.left.left = new Node(5); + tree.root.left.right = new Node(6); + + // postorder tree traversal + System.out.println("Postorder traversal"); + tree.postorder(tree.root); + } +} diff --git a/Reverse b/Reverse new file mode 100644 index 0000000..bbaaa75 --- /dev/null +++ b/Reverse @@ -0,0 +1,21 @@ +public class JavaReverseString { + + public static void main(String[] args) { + System.out.println(reverseString("abc")); + System.out.println(reverseString("123!@#098*")); + } + + public static String reverseString(String in) { + if (in == null) + return null; + StringBuilder out = new StringBuilder(); + + int length = in.length(); + + for (int i = length - 1; i >= 0; i--) { + out.append(in.charAt(i)); + } + + return out.toString(); + } +} diff --git a/arpit tripathi.md b/arpit tripathi.md new file mode 100644 index 0000000..11b2295 --- /dev/null +++ b/arpit tripathi.md @@ -0,0 +1,22 @@ +public class Main { + + public static void main(String[] args) { + + int num = 29; + boolean flag = false; + for(int i = 2; i <= num/2; ++i) + { + // condition for nonprime number + if(num % i == 0) + { + flag = true; + break; + } + } + + if (!flag) + System.out.println(num + " is a prime number."); + else + System.out.println(num + " is not a prime number."); + } +} diff --git a/arpit.tripathi.md b/arpit.tripathi.md new file mode 100644 index 0000000..4038bfd --- /dev/null +++ b/arpit.tripathi.md @@ -0,0 +1,25 @@ +public class Test { + + public static void main(String args[]) { + // char grade = args[0].charAt(0); + char grade = 'C'; + + switch(grade) { + case 'A' : + System.out.println("Excellent!"); + break; + case 'B' : + case 'C' : + System.out.println("Well done"); + break; + case 'D' : + System.out.println("You passed"); + case 'F' : + System.out.println("Better try again"); + break; + default : + System.out.println("Invalid grade"); + } + System.out.println("Your grade is " + grade); + } +} diff --git a/arpittripathi.md b/arpittripathi.md new file mode 100644 index 0000000..6079da2 --- /dev/null +++ b/arpittripathi.md @@ -0,0 +1,22 @@ +package MyPackage; + +public class Armstrong { + public static void main(String[] args) { + int number = 9474, originalNumber, remainder, result = 0, n = 0; + originalNumber = number; + for (;originalNumber != 0; originalNumber /= 10) + { + n++; + } + originalNumber = number; + for (;originalNumber != 0; originalNumber /= 10) + { + remainder = originalNumber % 10; + result += Math.pow(remainder, n); + } + if(result == number) + System.out.println(number + " is an Armstrong number."); + else + System.out.println(number + " is not an Armstrong number."); + } +} diff --git a/complex_number.java b/complex_number.java new file mode 100644 index 0000000..a4391fd --- /dev/null +++ b/complex_number.java @@ -0,0 +1,31 @@ +#https://www.facebook.com/shruti.buchha.7/posts/3341900509242443 +#subscribed by shruti buchha +import java.util.*; +import java.lang.*; +import java.io.*; +public class ComplexNumber{ + + double real, img; + + ComplexNumber(double r, double i){ + this.real = r; + this.img = i; + } + + public static ComplexNumber sum(ComplexNumber c1, ComplexNumber c2) + { + + ComplexNumber temp = new ComplexNumber(0, 0); + + temp.real = c1.real + c2.real; + temp.img = c1.img + c2.img; + + return temp; + } + public static void main(String args[]) { + ComplexNumber c1 = new ComplexNumber(5.5, 4); + ComplexNumber c2 = new ComplexNumber(1.2, 3.5); + ComplexNumber temp = sum(c1, c2); + System.out.printf("Sum is: "+ temp.real+" + "+ temp.img +"i"); + } +} diff --git a/palindrome-checker.java b/palindrome-checker.java new file mode 100644 index 0000000..705ce89 --- /dev/null +++ b/palindrome-checker.java @@ -0,0 +1,24 @@ +import java.util.Scanner; +class PalindromeExample +{ + public static void main(String args[]) + { + int r,sum=0,temp; + int n; + + Scanner sc = new Scanner(System.in); + System.out.println("Enter the number:"); + n = sc.nextInt(); + temp=n; + while(n>0) + { + r=n%10; + sum=(sum*10)+r; + n=n/10; + } + if(temp==sum) + System.out.println("palindrome number "); + else + System.out.println("not palindrome"); + } +} diff --git a/wordshash.java b/wordshash.java new file mode 100644 index 0000000..2a47064 --- /dev/null +++ b/wordshash.java @@ -0,0 +1,22 @@ +import java.util.HashMap; + +public class FinalCountWords { + + public static void main(String[] args) { + String str = "This this is is done by Saket Saket"; + String[] split = str.split(" "); + + HashMap map = new HashMap(); + for (int i=0; i