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/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/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"); + } +}