diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..73f69e0 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/.idea/javaprogram.iml b/.idea/javaprogram.iml new file mode 100644 index 0000000..d6ebd48 --- /dev/null +++ b/.idea/javaprogram.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..3a37236 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..2b2e60d --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/0 1 Knapsack b/0 1 Knapsack new file mode 100644 index 0000000..f0d27c4 --- /dev/null +++ b/0 1 Knapsack @@ -0,0 +1,35 @@ +public class Solution { + + + static int max(int a, int b) { return (a > b)? a : b; } + + + public static int knapsack(int[] weight,int value[],int maxWeight, int n){ + /* Your class should be named Solution. + * Don't write main() function. + * Don't read input, it is passed as function argument. + * Return output and don't print it. + * Taking input and printing output is handled automatically. + */ + + int i, w; + int K[][] = new int[n+1][maxWeight+1]; + + // Build table K[][] in bottom up manner + for (i = 0; i <= n; i++) + { + for (w = 0; w <= maxWeight; w++) + { + if (i==0 || w==0) + K[i][w] = 0; + else if (weight[i-1] <= w) + K[i][w] = max(value[i-1] + K[i-1][w-weight[i-1]], K[i-1][w]); + else + K[i][w] = K[i-1][w]; + } + } + + return K[n][maxWeight]; + + } +} diff --git a/AGE CALCULATER b/AGE CALCULATER new file mode 100644 index 0000000..53f4dba --- /dev/null +++ b/AGE CALCULATER @@ -0,0 +1,33 @@ +package com.candidjava.time; + +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.time.LocalDate; +import java.time.Period; +import java.util.Calendar; +import java.util.Date; + +public class DobConversion { + public static void main(String[] args) throws ParseException { + //direct age calculation + LocalDate l = LocalDate.of(1998, 04, 23); //specify year, month, date directly + LocalDate now = LocalDate.now(); //gets localDate + Period diff = Period.between(l, now); //difference between the dates is calculated + System.out.println(diff.getYears() + "years" + diff.getMonths() + "months" + diff.getDays() + "days"); + + //using Calendar Object + String s = "1994/06/23"; + SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd"); + Date d = sdf.parse(s); + Calendar c = Calendar.getInstance(); + c.setTime(d); + int year = c.get(Calendar.YEAR); + int month = c.get(Calendar.MONTH) + 1; + int date = c.get(Calendar.DATE); + LocalDate l1 = LocalDate.of(year, month, date); + LocalDate now1 = LocalDate.now(); + Period diff1 = Period.between(l1, now1); + System.out.println("age:" + diff1.getYears() + "years"); + } +} +//PLEASE SEE MY CODE.HOW IS IT. diff --git a/AVL Tree.java b/AVL Tree.java new file mode 100644 index 0000000..60a9133 --- /dev/null +++ b/AVL Tree.java @@ -0,0 +1,189 @@ +class Node { + int item, height; + Node left, right; + + Node(int d) { + item = d; + height = 1; + } +} + +// Tree class +class AVLTree { + Node root; + + int height(Node N) { + if (N == null) + return 0; + return N.height; + } + + int max(int a, int b) { + return (a > b) ? a : b; + } + + Node rightRotate(Node y) { + Node x = y.left; + Node T2 = x.right; + x.right = y; + y.left = T2; + y.height = max(height(y.left), height(y.right)) + 1; + x.height = max(height(x.left), height(x.right)) + 1; + return x; + } + + Node leftRotate(Node x) { + Node y = x.right; + Node T2 = y.left; + y.left = x; + x.right = T2; + x.height = max(height(x.left), height(x.right)) + 1; + y.height = max(height(y.left), height(y.right)) + 1; + return y; + } + + // Get balance factor of a node + int getBalanceFactor(Node N) { + if (N == null) + return 0; + return height(N.left) - height(N.right); + } + + // Insert a node + Node insertNode(Node node, int item) { + + // Find the position and insert the node + if (node == null) + return (new Node(item)); + if (item < node.item) + node.left = insertNode(node.left, item); + else if (item > node.item) + node.right = insertNode(node.right, item); + else + return node; + + // Update the balance factor of each node + // And, balance the tree + node.height = 1 + max(height(node.left), height(node.right)); + int balanceFactor = getBalanceFactor(node); + if (balanceFactor > 1) { + if (item < node.left.item) { + return rightRotate(node); + } else if (item > node.left.item) { + node.left = leftRotate(node.left); + return rightRotate(node); + } + } + if (balanceFactor < -1) { + if (item > node.right.item) { + return leftRotate(node); + } else if (item < node.right.item) { + node.left = rightRotate(node.left); + return leftRotate(node); + } + } + return node; + } + + Node nodeWithMimumValue(Node node) { + Node current = node; + while (current.left != null) + current = current.left; + return current; + } + + // Delete a node + Node deleteNode(Node root, int item) { + + // Find the node to be deleted and remove it + if (root == null) + return root; + if (item < root.item) + root.left = deleteNode(root.left, item); + else if (item > root.item) + root.right = deleteNode(root.right, item); + else { + if ((root.left == null) || (root.right == null)) { + Node temp = null; + if (temp == root.left) + temp = root.right; + else + temp = root.left; + if (temp == null) { + temp = root; + root = null; + } else + root = temp; + } else { + Node temp = nodeWithMimumValue(root.right); + root.item = temp.item; + root.right = deleteNode(root.right, temp.item); + } + } + if (root == null) + return root; + + // Update the balance factor of each node and balance the tree + root.height = max(height(root.left), height(root.right)) + 1; + int balanceFactor = getBalanceFactor(root); + if (balanceFactor > 1) { + if (getBalanceFactor(root.left) >= 0) { + return rightRotate(root); + } else { + root.left = leftRotate(root.left); + return rightRotate(root); + } + } + if (balanceFactor < -1) { + if (getBalanceFactor(root.right) <= 0) { + return leftRotate(root); + } else { + root.right = rightRotate(root.right); + return leftRotate(root); + } + } + return root; + } + + void preOrder(Node node) { + if (node != null) { + System.out.print(node.item + " "); + preOrder(node.left); + preOrder(node.right); + } + } + + // Print the tree + private void printTree(Node currPtr, String indent, boolean last) { + if (currPtr != null) { + System.out.print(indent); + if (last) { + System.out.print("R----"); + indent += " "; + } else { + System.out.print("L----"); + indent += "| "; + } + System.out.println(currPtr.item); + printTree(currPtr.left, indent, false); + printTree(currPtr.right, indent, true); + } + } + + // Driver code + public static void main(String[] args) { + AVLTree tree = new AVLTree(); + tree.root = tree.insertNode(tree.root, 33); + tree.root = tree.insertNode(tree.root, 13); + tree.root = tree.insertNode(tree.root, 53); + tree.root = tree.insertNode(tree.root, 9); + tree.root = tree.insertNode(tree.root, 21); + tree.root = tree.insertNode(tree.root, 61); + tree.root = tree.insertNode(tree.root, 8); + tree.root = tree.insertNode(tree.root, 11); + tree.printTree(tree.root, "", true); + tree.root = tree.deleteNode(tree.root, 13); + System.out.println("After Deletion: "); + tree.printTree(tree.root, "", true); + } +} diff --git a/AWT_by_Association_in_java b/AWT_by_Association_in_java new file mode 100644 index 0000000..3b39fb4 --- /dev/null +++ b/AWT_by_Association_in_java @@ -0,0 +1,14 @@ +import java.awt.*; +class First2{ +First2(){ +Frame f=new Frame(); +Button b=new Button("click me"); +b.setBounds(30,50,80,30); +f.add(b); +f.setSize(300,300); +f.setLayout(null); +f.setVisible(true); +} +public static void main(String args[]){ +First2 f=new First2(); +}} diff --git a/Add two number in JAVA b/Add two number in JAVA new file mode 100644 index 0000000..db65235 --- /dev/null +++ b/Add two number in JAVA @@ -0,0 +1,10 @@ +public class AddTwoNumbers { + + public static void main(String[] args) { + + int num1 = 5, num2 = 15, sum; + sum = num1 + num2; + + System.out.println("Sum of these numbers: "+sum); + } +} diff --git a/Add two number with user input b/Add two number with user input new file mode 100644 index 0000000..249d9e7 --- /dev/null +++ b/Add two number with user input @@ -0,0 +1,16 @@ +import java.util.Scanner; + +class MyClass { + public static void main(String[] args) { + int x, y, sum; + Scanner myObj = new Scanner(System.in); + System.out.println("Type a number:"); + x = myObj.nextInt(); + + System.out.println("Type another number:"); + y = myObj.nextInt(); + + sum = x + y; // Calculate the sum of x + y + System.out.println("Sum is: " + sum); + } +} diff --git a/Area of Circle b/Area of Circle new file mode 100644 index 0000000..199805b --- /dev/null +++ b/Area of Circle @@ -0,0 +1,12 @@ +import java.util.Scanner; +public class AreaOfCircle { + public static void main(String args[]){ + int radius; + double area; + Scanner sc = new Scanner(System.in); + System.out.println("Enter the radius of the circle ::"); + radius = sc.nextInt(); + area = (radius*radius)*Math.PI; + System.out.println("Area of the circle is ::"+area); + } +} diff --git a/Arithmetic Operator b/Arithmetic Operator new file mode 100644 index 0000000..afd5ce7 --- /dev/null +++ b/Arithmetic Operator @@ -0,0 +1,26 @@ +class ArithmeticOperator { + public static void main(String[] args) { + + double number1 = 12.5, number2 = 3.5, result; + + // Using addition operator + result = number1 + number2; + System.out.println("number1 + number2 = " + result); + + // Using subtraction operator + result = number1 - number2; + System.out.println("number1 - number2 = " + result); + + // Using multiplication operator + result = number1 * number2; + System.out.println("number1 * number2 = " + result); + + // Using division operator + result = number1 / number2; + System.out.println("number1 / number2 = " + result); + + // Using remainder operator + result = number1 % number2; + System.out.println("number1 % number2 = " + result); + } +} diff --git a/Armstrong.java b/Armstrong.java new file mode 100644 index 0000000..b3f9f8e --- /dev/null +++ b/Armstrong.java @@ -0,0 +1,21 @@ +import java.util.Scanner; +class Armstrong +{ +public static void main(String[] args) +{ +Scanner scan=new Scanner(System.in); +System.out.println("Enter a real no:"); +int x=scan.nextInt(); +int temp=x,A=0,r; +while(x!=0) +{ +r=x%10; +A+=r*r*r; +x=x/10; +} +if(temp==A) +System.out.println("Armstrong no"); +else +System.out.println("not an Armstrong no"); +} +} diff --git a/Arrange array of strings in ascending order. b/Arrange array of strings in ascending order. new file mode 100644 index 0000000..89da2d0 --- /dev/null +++ b/Arrange array of strings in ascending order. @@ -0,0 +1,27 @@ +import java.util.Scanner; +class Main{ + public static void main(String args[]){ + Scanner sc = new Scanner(System.in); + System.out.println("Enter String array size: "); + int n = sc.nextInt(); + String arr[] = new String[n]; + Scanner s = new Scanner(System.in); + System.out.println("Enter Strings: "); + for(int i=0;i0) { + String temp = arr[i]; + arr[i] = arr[j]; + arr[j] = temp; + } + } + } + System.out.print("Strings in Sorted Order:"); + for (int i = 0; i < n ; i++) { + System.out.print(arr[i] +" "); + } + } +} diff --git a/Array b/Array new file mode 100644 index 0000000..0e02881 --- /dev/null +++ b/Array @@ -0,0 +1,12 @@ +class Testarray{ +public static void main(String args[]){ +int a[]=new int[5];//declaration and instantiation +a[0]=10;//initialization +a[1]=20; +a[2]=70; +a[3]=40; +a[4]=50; +//traversing array +for(int i=0;i userBalance) { + System.out.println("Insufficient Balance. Please Try Again"); + } else { + userBalance -= withdrawAmount; + System.out.println("You have successfully withdraw " + withdrawAmount + + " \nNow your balnce is " + userBalance); + } + } + + } + + } + +} + diff --git a/BatteryPercentage b/BatteryPercentage new file mode 100644 index 0000000..441e49d --- /dev/null +++ b/BatteryPercentage @@ -0,0 +1,35 @@ +//program on battery pecentage using if..else..if..... + + +import java.util.*; +class Battery +{ + public static void main(String args[]) +{ + Scanner sc = new Scanner(System.in); + System.out.println("enter battery percentage = "); + int battery = sc.nextInt(); + + if(battery == 100) + { + System.out.println("battery fully Charged***"); + } + else if(battery == 0) + { + System.out.println("switch off!!!"); + } + else if(battery > 20) + { + System.out.println("battery colour is green at %" +battery); + } + else if(20 >= battery && battery > 15) + { + System.out.println("battery colour is orange at %" +battery); + } + else if(battery <= 15) + { + System.out.println("battery colour is red at %" +battery); + } +} +} + diff --git a/Biggest no 3 b/Biggest no 3 new file mode 100644 index 0000000..9c538a0 --- /dev/null +++ b/Biggest no 3 @@ -0,0 +1,28 @@ +import java.util.Scanner; +public class Biggest_Number +{ + public static void main(String[] args) + { + int x, y, z; + Scanner s = new Scanner(System.in); + System.out.print("Enter the first number:"); + x = s.nextInt(); + System.out.print("Enter the second number:"); + y = s.nextInt(); + System.out.print("Enter the third number:"); + z = s.nextInt(); + if(x > y && x > z) + { + System.out.println("Largest number is:"+x); + } + else if(y > z) + { + System.out.println("Largest number is:"+y); + } + else + { + System.out.println("Largest number is:"+z); + } + + } +} diff --git a/Binary search b/Binary search new file mode 100644 index 0000000..421f93b --- /dev/null +++ b/Binary search @@ -0,0 +1,25 @@ +class BinarySearchExample{ + public static void binarySearch(int arr[], int first, int last, int key){ + int mid = (first + last)/2; + while( first <= last ){ + if ( arr[mid] < key ){ + first = mid + 1; + }else if ( arr[mid] == key ){ + System.out.println("Element is found at index: " + mid); + break; + }else{ + last = mid - 1; + } + mid = (first + last)/2; + } + if ( first > last ){ + System.out.println("Element is not found!"); + } + } + public static void main(String args[]){ + int arr[] = {10,20,30,40,50}; + int key = 30; + int last=arr.length-1; + binarySearch(arr,0,last,key); + } +} diff --git a/BubbleSort.java b/BubbleSort.java new file mode 100644 index 0000000..5c9917a --- /dev/null +++ b/BubbleSort.java @@ -0,0 +1,38 @@ +import java.util.Scanner; + +public class BubbleSort { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + int n = sc.nextInt(); + int[] arr = new int[n]; + for (int i = 0; i < n; i++) + arr[i] = sc.nextInt(); + bubble(arr); + for (int i : arr) { + System.out.print(i + " "); + } + sc.close(); + } + + public static void bubble(int[] arr) { + for (int i = 1; i <= arr.length - 1; i++) + for (int j = 0; j < arr.length - i; j++) + if (isSmaller(arr, j + 1, j)) + swap(arr, j + 1, j); + } + + public static boolean isSmaller(int[] arr, int i, int j) { + System.out.println("Comparing " + arr[i] + " with " + arr[j]); + if (arr[i] < arr[j]) + return true; + else + return false; + } + + public static void swap(int[] arr, int i, int j) { + System.out.println("Swapping " + arr[i] + " and " + arr[j]); + int temp = arr[i]; + arr[i] = arr[j]; + arr[j] = temp; + } +} diff --git a/Calculate volume by Java Programe b/Calculate volume by Java Programe new file mode 100644 index 0000000..74d9f1c --- /dev/null +++ b/Calculate volume by Java Programe @@ -0,0 +1,21 @@ +class VolumeOfCylinder +{ + public static void main(String args[]) + { + + Scanner s= new Scanner(System.in); + + System.out.println("Enter the radius:"); + double r=s.nextDouble(); + System.out.println("Enter the height:"); + double h=s.nextDouble(); + + double volume=((22*r*r*h)/7); + + System.out.println("volume of Cylinder is: " +volume); + + + + + } +} diff --git a/Calculator b/Calculator new file mode 100644 index 0000000..023b618 --- /dev/null +++ b/Calculator @@ -0,0 +1,73 @@ +ve the knowledge of the following Java programming topics: + +Java switch Statement + +Java Scanner Class + +Example: Simple Calculator using switch Statement + +import java.util.Scanner; + +public class Calculator { + + public static void main(String[] args) { + + Scanner reader = new Scanner(System.in); + + System.out.print("Enter two numbers: "); + + // nextDouble() reads the next double from the keyboard + + double first = reader.nextDouble(); + + double second = reader.nextDouble(); + + System.out.print("Enter an operator (+, -, *, /): "); + + char operator = reader.next().charAt(0); + + double result; + + switch(operator) + + { + + case '+': + + result = first + second; + + break; + + case '-': + + result = first - second; + + break; + + case '*': + + result = first * second; + + break; + + case '/': + + result = first / second; + + break; + + // operator doesn't match any case constant (+, -, *, /) + + default: + + System.out.printf("Error! operator is not correct"); + + return; + + } + + System.out.printf("%.1f %c %.1f = %.1f", first, operator, second, result); + + } + +} diff --git a/Check a leap year in java b/Check a leap year in java new file mode 100644 index 0000000..576c7a9 --- /dev/null +++ b/Check a leap year in java @@ -0,0 +1,49 @@ +public class LeapYear { + + public static void main(String[] args) { + + int year = 1900; + + boolean leap = false; + + if(year % 4 == 0) + + { + + if( year % 100 == 0) + + { + + // year is divisible by 400, hence the year is a leap year + + if ( year % 400 == 0) + + leap = true; + + else + + leap = false; + + } + + else + + leap = true; + + } + + else + + leap = false; + + if(leap) + + System.out.println(year + " is a leap year."); + + else + + System.out.println(year + " is not a leap year."); + + } + +} diff --git a/Check this string is anagram or not b/Check this string is anagram or not new file mode 100644 index 0000000..86392ef --- /dev/null +++ b/Check this string is anagram or not @@ -0,0 +1,35 @@ +import java.util.Arrays; + +class Main { + public static void main(String[] args) { + String str1 = "java"; + String str2 = "vaaj"; + + + if(str1.length() == str2.length()) { + + + char[] charArray1 = str1.toCharArray(); + char[] charArray2 = str2.toCharArray(); + + + Arrays.sort(charArray1); + Arrays.sort(charArray2); + + + boolean result = Arrays.equals(charArray1, charArray2); + + if(result) { + System.out.println(str1 + " and " + str2 + " are anagram."); + } + else { + System.out.println(str1 + " and " + str2 + " are not anagram."); + } + } + else { + System.out.println(str1 + " and " + str2 + " are not anagram."); + } + } +} + + diff --git a/Convert to ASCII b/Convert to ASCII new file mode 100644 index 0000000..424ced3 --- /dev/null +++ b/Convert to ASCII @@ -0,0 +1,12 @@ +import java.util.Scanner; +public class PrintAsciiValueExample4 +{ +public static void main(String args[]) +{ +System.out.print("Enter a character: "); +Scanner sc = new Scanner(System.in); +char chr = sc.next().charAt(0); +int asciiValue = chr; +System.out.println("ASCII value of " +chr+ " is: "+asciiValue); +} +} diff --git a/CopyArray b/CopyArray new file mode 100644 index 0000000..f8a6cdb --- /dev/null +++ b/CopyArray @@ -0,0 +1,25 @@ +public class CopyArray { + public static void main(String[] args) { + //Initialize array + int [] arr1 = new int [] {1, 2, 3, 4, 5}; + //Create another array arr2 with size of arr1 + int arr2[] = new int[arr1.length]; + //Copying all elements of one array into another + for (int i = 0; i < arr1.length; i++) { + arr2[i] = arr1[i]; + } + //Displaying elements of array arr1 + System.out.println("Elements of original array: "); + for (int i = 0; i < arr1.length; i++) { + System.out.print(arr1[i] + " "); + } + + System.out.println(); + + //Displaying elements of array arr2 + System.out.println("Elements of new array: "); + for (int i = 0; i < arr2.length; i++) { + System.out.print(arr2[i] + " "); + } + } +} diff --git a/Count the number of words that start with a capital letter. b/Count the number of words that start with a capital letter. new file mode 100644 index 0000000..5545016 --- /dev/null +++ b/Count the number of words that start with a capital letter. @@ -0,0 +1,22 @@ +import java.util.Scanner; +class Main +{ + public static void main(String args[]) + { + Scanner sc = new Scanner(System.in); + String str = new String(); + System.out.println("Enter your Str: "); + str = sc.nextLine(); + //char c; + int count=0; + for(int i=0;i= 7 &&noOfDays<= 14) { +General = 0.0450; +SCitizen = 0.0500; } +elseif (noOfDays>= 15 &&noOfDays<= 29) { +General = 0.0470; +SCitizen = 0.0525; + } elseif (noOfDays>= 30 &&noOfDays<= 45) { +General = 0.0550; +SCitizen = 0.0600; + } elseif (noOfDays>= 45 &&noOfDays<= 60) { +General = 0.0700; +SCitizen = 0.0750; + } elseif (noOfDays>= 61 &&noOfDays<= 184) { +General = 0.0750; +SCitizen = 0.0800; + } elseif (noOfDays>= 185 &&noOfDays<= 365) { +General = 0.0800; +SCitizen = 0.0850; + } +FDinterestRate = (ageOfACHolder< 50) ?General :SCitizen; + } else { +if (noOfDays>= 7 &&noOfDays<= 14) { +interestRate = 0.065; + } elseif (noOfDays>= 15 &&noOfDays<= 29) { +interestRate = 0.0675; + } elseif (noOfDays>= 30 &&noOfDays<= 45) { +interestRate = 0.00675; + } elseif (noOfDays>= 45 &&noOfDays<= 60) { +interestRate = 0.080; + } elseif (noOfDays>= 61 &&noOfDays<= 184) { +interestRate = 0.0850; + } elseif (noOfDays>= 185 &&noOfDays<= 365) { +interestRate = 0.10; + } + } + +returnFDAmount * FDinterestRate; + } +} +classInvalidAgeExceptionextendsException{} + +classInvalidAmountExceptionextendsException{} + +classInvalidDaysExceptionextendsException{} + +classInvalidMonthsExceptionextendsException{} + +classRDaccountextends Account { + +doubleRDInterestRate; +doubleRDamount; +intnoOfMonths; +doublemonthlyAmount; +doubleGeneral, SCitizen; + Scanner RDScanner = newScanner(System.in); + + +doublecalculateInterest(doubleRamount) throwsInvalidMonthsException,InvalidAmountException ,InvalidAgeException { +this.RDamount = Ramount; +System.out.println("Enter RD months"); +noOfMonths = RDScanner.nextInt(); +System.out.println("Enter RD holder age"); +intage = RDScanner.nextInt(); +if (RDamount< 0) { +thrownewInvalidAmountException(); + } +if(noOfMonths<0){ +thrownewInvalidMonthsException(); + } +if(age<0){ +thrownewInvalidAgeException(); + } +if (noOfMonths>= 0 &&noOfMonths<= 6) { +General = .0750; +SCitizen = 0.080; + } elseif (noOfMonths>= 7 &&noOfMonths<= 9) { +General = .0775; +SCitizen = 0.0825; + } elseif (noOfMonths>= 10 &&noOfMonths<= 12) { +General = .0800; +SCitizen = 0.0850; + } elseif (noOfMonths>= 13 &&noOfMonths<= 15) { +General = .0825; +SCitizen = 0.0875; + } elseif (noOfMonths>= 16 &&noOfMonths<= 18) { +General = .0850; +SCitizen = 0.0900; + } elseif (noOfMonths>= 22) { +General = .0875; +SCitizen = 0.0925; + } +RDInterestRate = (age< 50) ?General :SCitizen; +returnRDamount * RDInterestRate; + + } + +} +classSBaccountextends Account { +doubleSBamount ,SbInterestRate, interest; + Scanner SBScanner = newScanner(System.in); + + +Double calculateInterest(double amount) throws Invalid AmountException{ +this.SBamount = amount; +if(SBamount< 0 ){ +thrownew Invalid AmountException(); + } +System.out.println("Select account type \n1. NRI \n2. Normal "); +Int account Choice = SBScanner.nextInt(); +switch (account Choice) { +case 1: +SbInterestRate = .06; +break; +case 2: +SbInterestRate = .04; +break; +default: +System.out.println("Please choose right account again"); + + } +return amount * SbInterestRate; +}} diff --git a/Display Fibonacci series b/Display Fibonacci series new file mode 100644 index 0000000..e0f0779 --- /dev/null +++ b/Display 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/Divisibility of Repeated String b/Divisibility of Repeated String new file mode 100644 index 0000000..14d4382 --- /dev/null +++ b/Divisibility of Repeated String @@ -0,0 +1,65 @@ +import java.io.*; +import java.util.*; + +public class Solution { + public static void main(String[] args) throws IOException { + Scanner bufferedReader = new Scanner(System.in); + System.out.println("Enter dividend string"); + String s = bufferedReader.nextLine(); + + System.out.println("Enter divisor string"); + String t = bufferedReader.nextLine(); + + + + int result = Result.findSmallestDivisor(s, t); + System.out.println(result); + } +} + + +class Result { + + /* + * Complete the 'findSmallestDivisor' function below. + * + * The function is expected to return an INTEGER. + * The function accepts following parameters: + * 1. STRING s + * 2. STRING t + */ + + public static int findSmallestDivisor(String s, String t) { + + if(s.length() % t.length() > 0) + return -1; + StringBuilder sb = new StringBuilder(); + for(int i=0;i*t.length() < s.length();i++) { + sb.append(t); + } + if(!sb.toString().equals(s)) + return -1; + + int divisible = 1; + + for(int i=1;i<=t.length();i++) { + + //optimized solution for skipping a few unrequired iterations + if(t.length()%divisible++ != 0) { + continue; + } + + + sb = new StringBuilder(); + String subStr = t.substring(0, i); + while(sb.length() < t.length()) { + sb.append(subStr); + } + if(sb.toString().equals(t)) + return i; + } + return -1; + + } + +} diff --git a/Dudeney-number b/Dudeney-number new file mode 100644 index 0000000..7aa53c2 --- /dev/null +++ b/Dudeney-number @@ -0,0 +1,23 @@ +import java.util.*; +public class Dudeney +{ +public static void main(String args[]) +{ +Scanner sc=new Scanner(System.in); +System.out.println("enter a number to check whether it is a Dudeney number or not :"); +int a=sc.nextInt(); +int s=a; +int q=0,d=0; +while(a>0) +{ +q=a%10; +d=d+q; +a=a/10; +} +int f=d*d*d; +if(f==s) +System.out.println(s+ " is a Dudeney number"); +else +System.out.println(s+ " is not a Dudeney number"); +} +} diff --git a/Duplicate Element in an Array b/Duplicate Element in an Array new file mode 100644 index 0000000..47acec8 --- /dev/null +++ b/Duplicate Element in an Array @@ -0,0 +1,28 @@ +import java.util.*; +class Solution +{ + static int findDuplicate(int[] nums) + { + int arr[] = new int[nums.length + 1]; + for(int i = 0; i < nums.length; i++) + { + arr[nums[i]]++; + if(arr[nums[i]] >= 2) + { + return nums[i]; + } + } + return -1; + } + public static void main(String[] args) + { + Scanner sc = new Scanner(System.in); + int n = sc.nextInt(); + int arr[] = new int[n]; + for(int i = 0; i < n; i++) + { + arr[i] = sc.nextInt(); + } + System.out.println(findDuplicate(arr)); + } +} diff --git a/DuplicateElement.java b/DuplicateElement.java new file mode 100644 index 0000000..7fd050d --- /dev/null +++ b/DuplicateElement.java @@ -0,0 +1,14 @@ +public class DuplicateElement { +public static void main(String[] args) { + //Initialize array + int [] arr = new int [] {1, 2, 3, 4, 2, 7, 8, 8, 3}; + System.out.println("Duplicate elements in given array: "); + //Searches for duplicate element + for(int i = 0; i < arr.length; i++) { + for(int j = i + 1; j < arr.length; j++) { + if(arr[i] == arr[j]) + System.out.println(arr[j]); + } + } + } +} diff --git a/ExceptionHandling b/ExceptionHandling new file mode 100644 index 0000000..e684ba1 --- /dev/null +++ b/ExceptionHandling @@ -0,0 +1,19 @@ +public class ExceptionHandling { + + public static void main(String args[]) { + int a[] = new int[3]; + try { + System.out.println("Access element three :" + a[4]); + } catch (ArrayIndexOutOfBoundsException e) { + System.out.println("Exception thrown :" + e); + }finally { + a[0] = 6; + a[1] = 7; + a[2] = 8; + for(int i=0; i < a.length; i++ ){ + System.out.println("The element value at index " + i + " is: " + a[i]); + } + System.out.println("The finally statement is executed"); + } + } +} diff --git a/Factorial b/Factorial new file mode 100644 index 0000000..aa831f2 --- /dev/null +++ b/Factorial @@ -0,0 +1,36 @@ +// Java implementation of the approach +class GFG { + + // Function to return the factorial of n + static int factorial(int n) + { + int f = 1; + for (int i = 1; i <= n; i++) { + f *= i; + } + return f; + } + + // Function to return the sum of + // factorials of the array elements + static int sumFactorial(int[] arr, int n) + { + + // To store the required sum + int s = 0; + for (int i = 0; i < n; i++) { + + // Add factorial of all the elements + s += factorial(arr[i]); + } + return s; + } + + // Driver Code + public static void main(String[] args) + { + int[] arr = { 7, 3, 5, 4, 8 }; + int n = arr.length; + System.out.println(sumFactorial(arr, n)); + } +} diff --git a/Factorial using recursion b/Factorial using recursion new file mode 100644 index 0000000..722f654 --- /dev/null +++ b/Factorial using recursion @@ -0,0 +1,14 @@ +class FactorialExample2{ + static int factorial(int n){ + if (n == 0) + return 1; + else + return(n * factorial(n-1)); + } + public static void main(String args[]){ + int i,fact=1; + int number=4;//It is the number to calculate factorial + fact = factorial(number); + System.out.println("Factorial of "+number+" is: "+fact); + } +} diff --git a/Fibonacci Series b/Fibonacci Series new file mode 100644 index 0000000..7326348 --- /dev/null +++ b/Fibonacci Series @@ -0,0 +1,15 @@ +class FibonacciExample1{ +public static void main(String args[]) +{ + int n1=0,n2=1,n3,i,count=10; + System.out.print(n1+" "+n2);//printing 0 and 1 + + for(i=2;i 0) { + missing = i + 1; + break; + } + } + System.out.println(duplicate + " " + missing); + } + } +} \ No newline at end of file diff --git a/Floyd's triangle b/Floyd's triangle new file mode 100644 index 0000000..b10ff07 --- /dev/null +++ b/Floyd's triangle @@ -0,0 +1,29 @@ +// Java program to print +// Floyd's triangle + +class Test +{ + static float findArea(float a, float b, float c) + { + // Length of sides must be positive and sum of any two sides + // must be smaller than third side. + if (a < 0 || b < 0 || c <0 || (a+b <= c) || + a+c <=b || b+c <=a) + { + System.out.println("Not a valid triangle"); + System.exit(0); + } + float s = (a+b+c)/2; + return (float)Math.sqrt(s*(s-a)*(s-b)*(s-c)); + } + + // Driver method + public static void main(String[] args) + { + float a = 3.0f; + float b = 4.0f; + float c = 5.0f; + + System.out.println("Area is " + findArea(a, b, c)); + } +} diff --git a/Frequency.java b/Frequency.java new file mode 100644 index 0000000..2e7063d --- /dev/null +++ b/Frequency.java @@ -0,0 +1,30 @@ +public class Frequency { + public static void main(String[] args) { + //Initialize array + int [] arr = new int [] {1, 2, 8, 3, 2, 2, 2, 5, 1}; + //Array fr will store frequencies of element + int [] fr = new int [arr.length]; + int visited = -1; + for(int i = 0; i < arr.length; i++){ + int count = 1; + for(int j = i+1; j < arr.length; j++){ + if(arr[i] == arr[j]){ + count++; + //To avoid counting same element again + fr[j] = visited; + } + } + if(fr[i] != visited) + fr[i] = count; + } + + //Displays the frequency of each element present in array + System.out.println("---------------------------------------"); + System.out.println(" Element | Frequency"); + System.out.println("---------------------------------------"); + for(int i = 0; i < fr.length; i++){ + if(fr[i] != visited) + System.out.println(" " + arr[i] + " | " + fr[i]); + } + System.out.println("----------------------------------------"); + }} diff --git a/Greater number b/Greater number new file mode 100644 index 0000000..a1a8f6d --- /dev/null +++ b/Greater number @@ -0,0 +1,29 @@ +import java.util.Scanner; + +public class LargestofTwo { + private static Scanner sc; + public static void main(String[] args) + { + int number1, number2; + sc = new Scanner(System.in); + + System.out.print(" Please Enter the First Number : "); + number1 = sc.nextInt(); + + System.out.print(" Please Enter the Second Number : "); + number2 = sc.nextInt(); + + if(number1 > number2) + { + System.out.println("\n The Largest Number = " + number1); + } + else if (number2 > number1) + { + System.out.println("\n The Largest Number = " + number2); + } + else + { + System.out.println("\n Both are Equal"); + } + } +} diff --git a/Hamiltonian and Lagrangian b/Hamiltonian and Lagrangian new file mode 100644 index 0000000..8dd816a --- /dev/null +++ b/Hamiltonian and Lagrangian @@ -0,0 +1,46 @@ + import java.util.*; + import java.lang.*; + import java.io.*; + + // HackerEarth + + public class TestClass + { + public static void main (String[] ar) + { + try + { + InputStreamReader isr = new InputStreamReader(System.in); + BufferedReader br = new BufferedReader(isr); + + int n = Integer.parseInt(br.readLine()); + int a[] = new int[n]; + + String x[] = br.readLine().trim().split(" "); + + for(int i=0;ia[j]) + count++; + } + if(count == (n-1-i)) + System.out.print(a[i] + " "); + } + + br.close(); + isr.close(); + } + + catch(Exception e) + { + + } + } + } diff --git a/Hello_Name b/Hello_Name new file mode 100644 index 0000000..681b9a6 --- /dev/null +++ b/Hello_Name @@ -0,0 +1,10 @@ +import java.util.*; +class Hello +{ +public static void main(String args[]) +{ +Scannner sc=new Scanner(System.in); +Stirng s=sc.next(); +System.out.println("Hello"+" "+s+" "+"to java world"); +} +} diff --git a/Image Processing b/Image Processing new file mode 100644 index 0000000..7267265 --- /dev/null +++ b/Image Processing @@ -0,0 +1,56 @@ +// Java program to demonstrate read and write of image +import java.io.File; +import java.io.IOException; +import java.awt.image.BufferedImage; +import javax.imageio.ImageIO; + +public class MyImage +{ + public static void main(String args[])throws IOException + { + int width = 963; //width of the image + int height = 640; //height of the image + + // For storing image in RAM + BufferedImage image = null; + + // READ IMAGE + try + { + File input_file = new File("G:\\Inp.jpg"); //image file path + + /* create an object of BufferedImage type and pass + as parameter the width, height and image int + type.TYPE_INT_ARGB means that we are representing + the Alpha, Red, Green and Blue component of the + image pixel using 8 bit integer value. */ + image = new BufferedImage(width, height, + BufferedImage.TYPE_INT_ARGB); + + // Reading input file + image = ImageIO.read(input_file); + + System.out.println("Reading complete."); + } + catch(IOException e) + { + System.out.println("Error: "+e); + } + + // WRITE IMAGE + try + { + // Output file path + File output_file = new File("D:\\Out.jpg"); + + // Writing to file taking type and path as + ImageIO.write(image, "jpg", output_file); + + System.out.println("Writing complete."); + } + catch(IOException e) + { + System.out.println("Error: "+e); + } + }//main() ends here +}//class ends here diff --git a/Inheritance b/Inheritance new file mode 100644 index 0000000..550e65b --- /dev/null +++ b/Inheritance @@ -0,0 +1,86 @@ + +edit +play_arrow + +brightness_5 +//Java program to illustrate the +// concept of inheritance + +// base class +class Bicycle +{ + // the Bicycle class has two fields + public int gear; + public int speed; + + // the Bicycle class has one constructor + public Bicycle(int gear, int speed) + { + this.gear = gear; + this.speed = speed; + } + + // the Bicycle class has three methods + public void applyBrake(int decrement) + { + speed -= decrement; + } + + public void speedUp(int increment) + { + speed += increment; + } + + // toString() method to print info of Bicycle + public String toString() + { + return("No of gears are "+gear + +"\n" + + "speed of bicycle is "+speed); + } +} + +// derived class +class MountainBike extends Bicycle +{ + + // the MountainBike subclass adds one more field + public int seatHeight; + + // the MountainBike subclass has one constructor + public MountainBike(int gear,int speed, + int startHeight) + { + // invoking base-class(Bicycle) constructor + super(gear, speed); + seatHeight = startHeight; + } + + // the MountainBike subclass adds one more method + public void setHeight(int newValue) + { + seatHeight = newValue; + } + + // overriding toString() method + // of Bicycle to print more info + @Override + public String toString() + { + return (super.toString()+ + "\nseat height is "+seatHeight); + } + +} + +// driver class +public class Test +{ + public static void main(String args[]) + { + + MountainBike mb = new MountainBike(3, 100, 25); + System.out.println(mb.toString()); + + } +} diff --git a/InputNumberIsIntOrNot b/InputNumberIsIntOrNot new file mode 100644 index 0000000..e6c6312 --- /dev/null +++ b/InputNumberIsIntOrNot @@ -0,0 +1,15 @@ + +package com.company; + +import java.util.Scanner; + +public class Main { + public Main() { + } + + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + System.out.println("Enter your number : "); + System.out.print(sc.hasNextInt()); + } +} diff --git a/Integer Palindrome b/Integer Palindrome new file mode 100644 index 0000000..b939697 --- /dev/null +++ b/Integer Palindrome @@ -0,0 +1,35 @@ +public static void main(String args[]){ + + System.out.println("Please Enter a number : "); + int palindrome = new Scanner(System.in).nextInt(); + + if(isPalindrome(palindrome)){ + System.out.println("Number : " + palindrome + " is a palindrome"); + }else{ + System.out.println("Number : " + palindrome + " is not a palindrome"); + } + + } + + /* + * Java method to check if a number is palindrome or not + */ + public static boolean isPalindrome(int number) { + int palindrome = number; // copied number into variable + int reverse = 0; + + while (palindrome != 0) { + int remainder = palindrome % 10; + reverse = reverse * 10 + remainder; + palindrome = palindrome / 10; + } + + // if original and reverse of number is equal means + // number is palindrome in Java + if (number == reverse) { + return true; + } + return false; + } + +} diff --git a/Java Array Exercises: Sort a numeric array and a string array b/Java Array Exercises: Sort a numeric array and a string array new file mode 100644 index 0000000..d24802a --- /dev/null +++ b/Java Array Exercises: Sort a numeric array and a string array @@ -0,0 +1,27 @@ +import java.util.Arrays; +public class Exercise1 { +public static void main(String[] args){ + + int[] my_array1 = { + 1789, 2035, 1899, 1456, 2013, + 1458, 2458, 1254, 1472, 2365, + 1456, 2165, 1457, 2456}; + + String[] my_array2 = { + "Java", + + "Python", + "PHP", + "C#", + "C Programming", + "C++" + }; + System.out.println("Original numeric array : "+Arrays.toString(my_array1)); + Arrays.sort(my_array1); + System.out.println("Sorted numeric array : "+Arrays.toString(my_array1)); + + System.out.println("Original string array : "+Arrays.toString(my_array2)); + Arrays.sort(my_array2); + System.out.println("Sorted string array : "+Arrays.toString(my_array2)); + } +} diff --git a/Java Program to Add two Binary Numbers b/Java Program to Add two Binary Numbers new file mode 100644 index 0000000..bd20805 --- /dev/null +++ b/Java Program to Add two Binary Numbers @@ -0,0 +1,41 @@ +import java.util.Scanner; +public class JavaExample { + public static void main(String[] args) + { + //Two variables to hold two input binary numbers + long b1, b2; + int i = 0, carry = 0; + + //This is to hold the output binary number + int[] sum = new int[10]; + + //To read the input binary numbers entered by user + Scanner scanner = new Scanner(System.in); + + //getting first binary number from user + System.out.print("Enter first binary number: "); + b1 = scanner.nextLong(); + //getting second binary number from user + System.out.print("Enter second binary number: "); + b2 = scanner.nextLong(); + + //closing scanner after use to avoid memory leak + scanner.close(); + while (b1 != 0 || b2 != 0) + { + sum[i++] = (int)((b1 % 10 + b2 % 10 + carry) % 2); + carry = (int)((b1 % 10 + b2 % 10 + carry) / 2); + b1 = b1 / 10; + b2 = b2 / 10; + } + if (carry != 0) { + sum[i++] = carry; + } + --i; + System.out.print("Output: "); + while (i >= 0) { + System.out.print(sum[i--]); + } + System.out.print("\n"); + } +} diff --git a/Java Program to Multiply two Floating Point Numbers b/Java Program to Multiply two Floating Point Numbers new file mode 100644 index 0000000..02d5174 --- /dev/null +++ b/Java Program to Multiply two Floating Point Numbers @@ -0,0 +1,12 @@ +public class MultiplyTwoNumbers { + + public static void main(String[] args) { + + float first = 1.5f; + float second = 2.0f; + + float product = first * second; + + System.out.println("The product is: " + product); + } +} diff --git a/Java Program to find Largest Number in an Array b/Java Program to find Largest Number in an Array new file mode 100644 index 0000000..4425944 --- /dev/null +++ b/Java Program to find Largest Number in an Array @@ -0,0 +1,23 @@ +public class LargestInArrayExample{ +public static int getLargest(int[] a, int total){ +int temp; +for (int i = 0; i < total; i++) + { + for (int j = i + 1; j < total; j++) + { + if (a[i] > a[j]) + { + temp = a[i]; + a[i] = a[j]; + a[j] = temp; + } + } + } + return a[total-1]; +} +public static void main(String args[]){ +int a[]={1,2,5,6,3,2}; +int b[]={44,66,99,77,33,22,55}; +System.out.println("Largest: "+getLargest(a,6)); +System.out.println("Largest: "+getLargest(b,7)); +}} diff --git a/Java program to check Armstrong number b/Java program to check Armstrong number new file mode 100644 index 0000000..b59c97f --- /dev/null +++ b/Java program to check Armstrong number @@ -0,0 +1,17 @@ +class ArmstrongExample{ + public static void main(String[] args) { + int c=0,a,temp; + int n=153;//It is the number to check armstrong + temp=n; + while(n>0) + { + a=n%10; + n=n/10; + c=c+(a*a*a); + } + if(temp==c) + System.out.println("armstrong number"); + else + System.out.println("Not armstrong number"); + } +} diff --git a/Java program to insert a new node at the beginning of the Circular Linked List b/Java program to insert a new node at the beginning of the Circular Linked List new file mode 100644 index 0000000..ca38cb3 --- /dev/null +++ b/Java program to insert a new node at the beginning of the Circular Linked List @@ -0,0 +1,71 @@ +public class InsertAtStart { + //Represents the node of list. + public class Node{ + int data; + Node next; + public Node(int data) { + this.data = data; + } + } + + //Declaring head and tail pointer as null. + public Node head = null; + public Node tail = null; + + //This function will add the new node at the end of the list. + public void addAtStart(int data){ + //Create new node + Node newNode = new Node(data); + //Checks if the list is empty. + if(head == null) { + //If list is empty, both head and tail would point to new node. + head = newNode; + tail = newNode; + newNode.next = head; + } + else { + //Store data into temporary node + Node temp = head; + //New node will point to temp as next node + newNode.next = temp; + //New node will be the head node + head = newNode; + //Since, it is circular linked list tail will point to head. + tail.next = head; + } + } + + //Displays all the nodes in the list + public void display() { + Node current = head; + if(head == null) { + System.out.println("List is empty"); + } + else { + System.out.println("Adding nodes to the start of the list: "); + do{ + //Prints each node by incrementing pointer. + System.out.print(" "+ current.data); + current = current.next; + }while(current != head); + System.out.println(); + } + } + + public static void main(String[] args) { + InsertAtStart cl = new InsertAtStart(); + + //Adding 1 to the list + cl.addAtStart(1); + cl.display(); + //Adding 2 to the list + cl.addAtStart(2); + cl.display(); + //Adding 3 to the list + cl.addAtStart(3); + cl.display(); + //Adding 4 to the list + cl.addAtStart(4); + cl.display(); + } +} diff --git a/Javaprimenu b/Javaprimenu new file mode 100644 index 0000000..11b2295 --- /dev/null +++ b/Javaprimenu @@ -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/Kth largest number b/Kth largest number new file mode 100644 index 0000000..19a2264 --- /dev/null +++ b/Kth largest number @@ -0,0 +1,42 @@ +import java.util.*; + +class Main{ + +static int kthLargest(int arr[], int size, int k) +{ + int temp = 0; + int result =0; + for(int i=0;iarr[j]) + { + temp = arr[i]; + arr[i] = arr[j]; + arr[j] = temp; + } + } + } + for(int i=0;i n2) ? n1 : n2; + + // Always true + while(true) { + if( lcm % n1 == 0 && lcm % n2 == 0 ) { + System.out.printf("The LCM of %d and %d is %d.", n1, n2, lcm); + break; + } + ++lcm; + } + } +} diff --git a/Largest.java b/Largest.java new file mode 100644 index 0000000..f507919 --- /dev/null +++ b/Largest.java @@ -0,0 +1,16 @@ +public class Largest { + + public static void main(String[] args) { + + double n1 = -4.5, n2 = 3.9, n3 = 2.5; + + if( n1 >= n2 && n1 >= n3) + System.out.println(n1 + " is the largest number."); + + else if (n2 >= n1 && n2 >= n3) + System.out.println(n2 + " is the largest number."); + + else + System.out.println(n3 + " is the largest number."); + } +} diff --git a/LargestElement_array.java b/LargestElement_array.java new file mode 100644 index 0000000..012b717 --- /dev/null +++ b/LargestElement_array.java @@ -0,0 +1,16 @@ +public class LargestElement_array { + public static void main(String[] args) { + + //Initialize array + int [] arr = new int [] {25, 11, 7, 75, 56}; + //Initialize max with first element of array. + int max = arr[0]; + //Loop through the array + for (int i = 0; i < arr.length; i++) { + //Compare elements of array with max + if(arr[i] > max) + max = arr[i]; + } + System.out.println("Largest element present in given array: " + max); + } +} diff --git a/Leap_Year b/Leap_Year new file mode 100644 index 0000000..5ff28f6 --- /dev/null +++ b/Leap_Year @@ -0,0 +1,30 @@ +import java.util.*; +public class Leap_Year { + public static void main(String args[]) + { + int n; + Scanner sc=new Scanner(System.in); + System.out.println("Enter the year : "); + n=sc.nextInt(); + if(n%4==0) + { + if(n%100==0) + + if(n%400==0) + + System.out.println("Yes Its Leap Year ****"); + + else + System.out.println("Its not Leap Year"); + else + System.out.println("Its Not Leap Year"); + + + } + else + { + System.out.println("Its not Leap Year "); + } + } + +} diff --git a/Login page b/Login page new file mode 100644 index 0000000..e467c3c --- /dev/null +++ b/Login page @@ -0,0 +1,93 @@ + + Login Form + + + + + + +
+

E-mail or Phone
+

+ Password

+

+
+ Forgoten Password?

+ +

+ new user Registration +
+
+ + + diff --git a/Longest_Common_Subsequence b/Longest_Common_Subsequence new file mode 100644 index 0000000..ac7445a --- /dev/null +++ b/Longest_Common_Subsequence @@ -0,0 +1,47 @@ +import java.util.ArrayList; +import java.util.*; + +public class solution { + + public static ArrayList longestSubsequence(int[] arr){ + // Write your code here + + HashMap h=new HashMap<>(); + ArrayList ans=new ArrayList<>(); + int small=arr[0]; + int largest=arr[0]; + for (int i = 0; i largest-small||(tempLarge-tempsmall==largest-small&&h.get(tempsmall)1) { + return false; + } + return true; + } +public static void main(String[] args) { + Scanner o=new Scanner(System.in); + + int t=o.nextInt(); + while(t>0) { + String s=o.next(); + int swap=0; + if(!checkAna(s)) { + System.out.println(-1); + t--; + continue; + } + else { + char ar[]=s.toCharArray(); + int i=0; + int j=s.length()-1; + while(ii) { + i++; + j--; + } + else { + int k=j; + while(k>i&&ar[i]!=ar[k]) { + k--; + } + if(k==i) { + swapp(k,k+1,ar); + swap++; + i++; + j--; + } + else if(ar[i]==ar[k]) { + while(k + 4.0.0 + com.learn + Note_Taker + war + 0.0.1-SNAPSHOT + Note_Taker Maven Webapp + http://maven.apache.org + + + junit + junit + 3.8.1 + test + + + + + org.hibernate + hibernate-core + 5.4.5.Final + + + + + + mysql + mysql-connector-java + 5.1.48 + + + + + Note_Taker + + diff --git a/Note_Taker/src/main/java/com/enti/Note.java b/Note_Taker/src/main/java/com/enti/Note.java new file mode 100644 index 0000000..5f7fcee --- /dev/null +++ b/Note_Taker/src/main/java/com/enti/Note.java @@ -0,0 +1,83 @@ +package com.enti; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; + +@Entity +@Table +public class Note { + + @Id + /* + * @GeneratedValue //we can also used this statement for auto_increement but in + * this case the value is start from index 0; + */ + @GeneratedValue(strategy = GenerationType.IDENTITY) + private int id; + + private String title; + + @Column(length=1500) + private String content; + + private int rid; + + + + + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getContent() { + return content; + } + + public void setContent(String content) { + this.content = content; + } + + public int getRid() { + return rid; + } + + public void setRid(int rid) { + this.rid = rid; + } + + public Note() { + super(); + // TODO Auto-generated constructor stub + } + + public Note(String title, String content,int rid) { + super(); + //this.id = id; + this.title = title; + this.content = content; + this.rid = rid; + } + + @Override + public String toString() { + // TODO Auto-generated method stub + return super.toString(); + } +} diff --git a/Note_Taker/src/main/java/com/enti/Register_table.java b/Note_Taker/src/main/java/com/enti/Register_table.java new file mode 100644 index 0000000..d9fbab2 --- /dev/null +++ b/Note_Taker/src/main/java/com/enti/Register_table.java @@ -0,0 +1,73 @@ +package com.enti; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; + +@Entity +@Table +public class Register_table { + + @Id + /* + * @GeneratedValue //we can also used this statement for auto_increement but in + * this case the value is start from index 0; + */ + @GeneratedValue(strategy = GenerationType.IDENTITY) + private int id; + + @Column(length=50) + private String name; + + @Column(length=50) + private String email; + + @Column(length=50) + private String login_id; + + @Column(length=50) + private String password; + + + public String getName() { + return name; + } + public void setName(String name) { + this.name = name; + } + public String getEmail() { + return email; + } + public void setEmail(String email) { + this.email = email; + } + public String getLogin_id() { + return login_id; + } + public void setLogin_id(String login_id) { + this.login_id = login_id; + } + public String getPassword() { + return password; + } + public void setPassword(String password) { + this.password = password; + } + public Register_table() { + super(); + // TODO Auto-generated constructor stub + } + public Register_table(String name, String email, String login_id, String password) { + super(); + //this.id = new Random().nextInt(100); + this.name = name; + this.email = email; + this.login_id = login_id; + this.password = password; + } + + +} diff --git a/Note_Taker/src/main/java/com/helper/FactoryProvider.java b/Note_Taker/src/main/java/com/helper/FactoryProvider.java new file mode 100644 index 0000000..8838cc8 --- /dev/null +++ b/Note_Taker/src/main/java/com/helper/FactoryProvider.java @@ -0,0 +1,26 @@ +package com.helper; + +import org.hibernate.SessionFactory; +import org.hibernate.cfg.Configuration; + +public class FactoryProvider { + + public static SessionFactory factory; + + public static SessionFactory getfactory() + { + if(factory==null) + { + factory=new Configuration().configure("hibernate.cfg.xml").buildSessionFactory(); + } + + return factory; + } + public void closeFactory() + { + if(factory.isOpen()) + { + factory.close(); + } + } +} diff --git a/Note_Taker/src/main/java/com/servlets/DeleteServlet.java b/Note_Taker/src/main/java/com/servlets/DeleteServlet.java new file mode 100644 index 0000000..8ab822c --- /dev/null +++ b/Note_Taker/src/main/java/com/servlets/DeleteServlet.java @@ -0,0 +1,46 @@ +package com.servlets; + +import java.io.IOException; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.hibernate.Session; +import org.hibernate.Transaction; + +import com.enti.Note; +import com.helper.FactoryProvider; + +public class DeleteServlet extends HttpServlet { + private static final long serialVersionUID = 1L; + + public DeleteServlet() { + super(); + // TODO Auto-generated constructor stub + } + + protected void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + try { + + //out.println("This is delete page"); + int noteId=Integer.parseInt(request.getParameter("note_id").trim()); + + Session s=FactoryProvider.getfactory().openSession(); + Transaction tx=s.beginTransaction(); + Note note= (Note)s.get(Note.class,noteId); + s.delete(note); + tx.commit(); + s.close(); + response.sendRedirect("all_notes.jsp"); + + } + catch (Exception e) + { + e.printStackTrace(); + } + } +} diff --git a/Note_Taker/src/main/java/com/servlets/Forget.java b/Note_Taker/src/main/java/com/servlets/Forget.java new file mode 100644 index 0000000..534aca8 --- /dev/null +++ b/Note_Taker/src/main/java/com/servlets/Forget.java @@ -0,0 +1,17 @@ +package com.servlets; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +public class Forget extends HttpServlet { + private static final long serialVersionUID = 1L; + + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + + + + } +} diff --git a/Note_Taker/src/main/java/com/servlets/Jdbcconnection.java b/Note_Taker/src/main/java/com/servlets/Jdbcconnection.java new file mode 100644 index 0000000..a36e5f4 --- /dev/null +++ b/Note_Taker/src/main/java/com/servlets/Jdbcconnection.java @@ -0,0 +1,24 @@ +package com.servlets; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; + +public class Jdbcconnection{ + public static Connection initializeDatabase() + throws SQLException, ClassNotFoundException + { + String dbDriver = "com.mysql.jdbc.Driver"; + String dbURL = "jdbc:mysql://localhost:3306/"; + + // Database name to access + String dbName = "myhiber"; + String dbUsername = "root"; + + Class.forName(dbDriver); + Connection con=DriverManager.getConnection(dbURL+dbName,dbUsername,""); + + return con; + + } +} diff --git a/Note_Taker/src/main/java/com/servlets/Log_out.java b/Note_Taker/src/main/java/com/servlets/Log_out.java new file mode 100644 index 0000000..0742dab --- /dev/null +++ b/Note_Taker/src/main/java/com/servlets/Log_out.java @@ -0,0 +1,29 @@ +package com.servlets; + +import java.io.IOException; +import java.io.PrintWriter; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; + + +public class Log_out extends HttpServlet { + + private static final long serialVersionUID = 1L; + + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + + + HttpSession session=request.getSession(); + //session.setAttribute("message","You are successfully log out!!!"); + session.invalidate(); + response.sendRedirect("signin.jsp"); + + + + + } +} diff --git a/Note_Taker/src/main/java/com/servlets/SaveNoteServlet.java b/Note_Taker/src/main/java/com/servlets/SaveNoteServlet.java new file mode 100644 index 0000000..cb33464 --- /dev/null +++ b/Note_Taker/src/main/java/com/servlets/SaveNoteServlet.java @@ -0,0 +1,64 @@ +package com.servlets; + +import java.io.IOException; +import java.io.PrintWriter; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; + +import org.hibernate.Session; +import org.hibernate.Transaction; + +import com.enti.Note; +import com.helper.FactoryProvider; + +public class SaveNoteServlet extends HttpServlet { + private static final long serialVersionUID = 1L; + + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + + + try { + response.setContentType("text/html"); + PrintWriter out=response.getWriter(); + + //title,content fetch + HttpSession session1=request.getSession(false); + if(session1!=null) + { + String title= request.getParameter("title"); + String content=request.getParameter("content"); + int rid=(Integer) session1.getAttribute("id"); + /*Query q=s.createQuery("update Note set title=:t ,content=:c where login_id=:l and password=:p"); + q.setParameter("t",title); + q.setParameter("c",content); + q.setParameter("l",log); + q.setParameter("p",pass); + int r=q.executeUpdate(); + out.println("Objected updated");*/ + + Note note=new Note(title,content,rid); + + //hibernate:save() + Session s= FactoryProvider.getfactory().openSession(); + Transaction tx =s.beginTransaction(); + + + s.save(note); + tx.commit(); + s.close(); + response.sendRedirect("add_notes.jsp"); + } + else{ + out.print("Please login first"); + request.getRequestDispatcher("index.jsp").include(request, response); + } + + } catch (Exception e) { + e.printStackTrace(); + } + } +} diff --git a/Note_Taker/src/main/java/com/servlets/Signin.java b/Note_Taker/src/main/java/com/servlets/Signin.java new file mode 100644 index 0000000..d797f07 --- /dev/null +++ b/Note_Taker/src/main/java/com/servlets/Signin.java @@ -0,0 +1,65 @@ +package com.servlets; + +import java.io.IOException; +import java.io.PrintWriter; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; + +public class Signin extends HttpServlet { + private static final long serialVersionUID = 1L; + + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + + response.setContentType("text/html"); + PrintWriter out=response.getWriter(); + try { + Connection con = Jdbcconnection.initializeDatabase(); + String log=request.getParameter("loginid"); + String pass=request.getParameter("password"); + + PreparedStatement ps=(PreparedStatement) con.prepareStatement + ("select id,name,password from Register_table where Login_id=? and Password=?"); + /* + * (select Register_table.id,login_id,password from Register_table left join + * orders on Register_table.rid = Note.id;) + */ + + ps.setString(1,log); + ps.setString(2,pass); + ResultSet rs=ps.executeQuery(); + if(rs.next()) + { + int id=rs.getInt(1); + String name=rs.getString(2); + HttpSession session=request.getSession(); + session.setAttribute("login_id",log); + session.setAttribute("password",pass); + session.setAttribute("id",id); + session.setAttribute("current-user",name); + + response.sendRedirect("home.jsp"); + //request.getRequestDispatcher("navbar.jsp").include(request, response); + } + else + { + HttpSession session=request.getSession(); + session.setAttribute("message","Sorry,Please Enter valid username or password !!!"); + response.sendRedirect("index.jsp"); + return; + + + } + + } + catch (Exception e) {e.printStackTrace();}; + } + } + + diff --git a/Note_Taker/src/main/java/com/servlets/Signup.java b/Note_Taker/src/main/java/com/servlets/Signup.java new file mode 100644 index 0000000..32fa965 --- /dev/null +++ b/Note_Taker/src/main/java/com/servlets/Signup.java @@ -0,0 +1,43 @@ +package com.servlets; + +import java.io.IOException; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.hibernate.Session; +import org.hibernate.Transaction; + +import com.enti.Register_table; +import com.helper.FactoryProvider; + +public class Signup extends HttpServlet { + private static final long serialVersionUID = 1L; + + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + + try { + + String name=request.getParameter("name"); + String email=request.getParameter("email"); + String log=request.getParameter("loginid"); + String pass=request.getParameter("password"); + + + Register_table reg=new Register_table(name,email,log,pass); + + //hibernate:save() + Session s= FactoryProvider.getfactory().openSession(); + Transaction tx =s.beginTransaction(); + + s.save(reg); + tx.commit(); + s.close(); + + response.sendRedirect("index.jsp"); + + } catch (Exception e) {e.printStackTrace();} + } +} diff --git a/Note_Taker/src/main/java/com/servlets/UpdateServlet.java b/Note_Taker/src/main/java/com/servlets/UpdateServlet.java new file mode 100644 index 0000000..c6627a1 --- /dev/null +++ b/Note_Taker/src/main/java/com/servlets/UpdateServlet.java @@ -0,0 +1,47 @@ +package com.servlets; + +import java.io.IOException; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.hibernate.Session; +import org.hibernate.Transaction; + +import com.enti.Note; +import com.helper.FactoryProvider; + +public class UpdateServlet extends HttpServlet { + private static final long serialVersionUID = 1L; + + public UpdateServlet() { + super(); + // TODO Auto-generated constructor stub + } + + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + try { + String title=request.getParameter("title"); + String content=request.getParameter("content"); + int noteid=Integer.parseInt(request.getParameter("noteId").trim()); + + Session s=FactoryProvider.getfactory().openSession(); + Transaction tx=s.beginTransaction(); + + Note note= s.get(Note.class,noteid); + note.setTitle(title); + note.setContent(content); + //note.setAddedDate(new Date()); + + tx.commit(); + s.close(); + response.sendRedirect("all_notes.jsp"); + + } catch (Exception e) { + e.printStackTrace(); + } + } + +} diff --git a/Note_Taker/src/main/resources/hibernate.cfg.xml b/Note_Taker/src/main/resources/hibernate.cfg.xml new file mode 100644 index 0000000..b2692a6 --- /dev/null +++ b/Note_Taker/src/main/resources/hibernate.cfg.xml @@ -0,0 +1,20 @@ + + + + + + com.mysql.jdbc.Driver + jdbc:mysql://localhost:3306/myhiber + root + + org.hibernate.dialect.MySQL5Dialect + update + true + true + true + + + + + \ No newline at end of file diff --git a/Note_Taker/src/main/webapp/WEB-INF/web.xml b/Note_Taker/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000..f4be9d6 --- /dev/null +++ b/Note_Taker/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,77 @@ + + + + Archetype Created Web Application + + SaveNoteServlet + SaveNoteServlet + + com.servlets.SaveNoteServlet + + + DeleteServlet + DeleteServlet + + com.servlets.DeleteServlet + + + UpdateServlet + UpdateServlet + + com.servlets.UpdateServlet + + + Signin + Signin + + com.servlets.Signin + + + Signup + Signup + + com.servlets.Signup + + + Log_out + Log_out + + com.servlets.Log_out + + + Forget + Forget + + com.servlets.Forget + + + SaveNoteServlet + /SaveNoteServlet + + + DeleteServlet + /DeleteServlet + + + UpdateServlet + /UpdateServlet + + + Signin + /Signin + + + Signup + /Signup + + + Log_out + /Log_out + + + Forget + /Forget + + diff --git a/Note_Taker/src/main/webapp/add_notes.jsp b/Note_Taker/src/main/webapp/add_notes.jsp new file mode 100644 index 0000000..e20ef27 --- /dev/null +++ b/Note_Taker/src/main/webapp/add_notes.jsp @@ -0,0 +1,62 @@ +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> +<%@page import=" javax.servlet.http.*"%> + + + + +Add Notes +<%@include file="all_js_cs.jsp"%> + + + +
+ + <% + if(session.getAttribute("login_id")==null){ + out.println("Please login First!!!"); + // response.sendRedirect("index.jsp"); + } + + String id1=(String) session.getAttribute("login_id"); + %> + + <%@include file="navbar.jsp"%> +
+

Please fill note Detail

+ + + +

+ +
+
+ + +
+
+ + +
+ +
+ + +
+
+
+ + + + + \ No newline at end of file diff --git a/Note_Taker/src/main/webapp/all_js_cs.jsp b/Note_Taker/src/main/webapp/all_js_cs.jsp new file mode 100644 index 0000000..f0e88d0 --- /dev/null +++ b/Note_Taker/src/main/webapp/all_js_cs.jsp @@ -0,0 +1,21 @@ + + + + + + + + + + diff --git a/Note_Taker/src/main/webapp/all_notes.jsp b/Note_Taker/src/main/webapp/all_notes.jsp new file mode 100644 index 0000000..6f2b031 --- /dev/null +++ b/Note_Taker/src/main/webapp/all_notes.jsp @@ -0,0 +1,74 @@ +<%@page import="java.util.List"%> +<%@page import="org.hibernate.*"%> +<%@page import="com.helper.FactoryProvider"%> +<%@page import="org.hibernate.Session"%> +<%@page import="com.enti.*"%> +<%@page import=" javax.servlet.http.*"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +All notes: Note Taker +<%@include file="all_js_cs.jsp"%> + + + +
+ <% + + if(session.getAttribute("login_id")==null) + { + out.println("Please login First!!!"); + response.sendRedirect("index.jsp"); + + } + else{ + String id=(String) session.getAttribute("login_id"); + int id1=(Integer)session.getAttribute("id"); + + %> + <%@include file="navbar.jsp"%> +
+
+
+ + +
+ <% + Session s=FactoryProvider.getfactory().openSession(); + /* //Query q= s.createQuery("from Note"); */ + String query="from Note as s where s.rid=:x"; + Query q=s.createQuery(query); + q.setParameter("x",id1); + List list=q.list(); + for(Note note:list) + { + %> +
+ Card image cap +
+
<%=note.getTitle() %>
+

<%=note.getContent() %>

+ + +
+
+ <% + } + + s.close(); + } %> +
+
+
+ + \ No newline at end of file diff --git a/Note_Taker/src/main/webapp/css/style.css b/Note_Taker/src/main/webapp/css/style.css new file mode 100644 index 0000000..0cbd9af --- /dev/null +++ b/Note_Taker/src/main/webapp/css/style.css @@ -0,0 +1,3 @@ +.purple { + background: #673ab7; +} \ No newline at end of file diff --git a/Note_Taker/src/main/webapp/edit.jsp b/Note_Taker/src/main/webapp/edit.jsp new file mode 100644 index 0000000..1050383 --- /dev/null +++ b/Note_Taker/src/main/webapp/edit.jsp @@ -0,0 +1,49 @@ +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> +<%@page import="com.helper.*,org.hibernate.*,com.enti.*"%> + + + + +Edit Page +<%@include file="all_js_cs.jsp"%> + + + +
+ <%@include file="navbar.jsp"%> +

This is Edit Page

+ + <% + int noteId=Integer.parseInt(request.getParameter("note_id").trim()); + Session s=FactoryProvider.getfactory().openSession(); + Note note= (Note)s.get(Note.class,noteId); + + %> + +
+ + + +
+ + +
+
+ + +
+ +
+ +
+
+
+ + \ No newline at end of file diff --git a/Note_Taker/src/main/webapp/home.jsp b/Note_Taker/src/main/webapp/home.jsp new file mode 100644 index 0000000..9c096e2 --- /dev/null +++ b/Note_Taker/src/main/webapp/home.jsp @@ -0,0 +1,51 @@ +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +Home PAge: Note Taker +<%@include file="all_js_cs.jsp"%> + + + +
+ <%@include file="navbar.jsp"%> + +
+ Card image cap +
+ + + + +
+
+
+ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Note_Taker/src/main/webapp/img/notepad.png b/Note_Taker/src/main/webapp/img/notepad.png new file mode 100644 index 0000000..72005e2 Binary files /dev/null and b/Note_Taker/src/main/webapp/img/notepad.png differ diff --git a/Note_Taker/src/main/webapp/index.jsp b/Note_Taker/src/main/webapp/index.jsp new file mode 100644 index 0000000..e48e160 --- /dev/null +++ b/Note_Taker/src/main/webapp/index.jsp @@ -0,0 +1,22 @@ + + + + + + + + +Note Taker : Home Page +<%@include file="all_js_cs.jsp"%> + + <%-- <%@include file="navbar.jsp"%> --%> +
+ + + <%@include file="signin.jsp"%> + + +
+ + diff --git a/Note_Taker/src/main/webapp/message.jsp b/Note_Taker/src/main/webapp/message.jsp new file mode 100644 index 0000000..0a891c7 --- /dev/null +++ b/Note_Taker/src/main/webapp/message.jsp @@ -0,0 +1,24 @@ + +<% + +String message=(String)session.getAttribute("message"); +if(message!=null) +{ + %> + + + +<% + session.removeAttribute("message"); + +} + + +%> \ No newline at end of file diff --git a/Note_Taker/src/main/webapp/navbar.jsp b/Note_Taker/src/main/webapp/navbar.jsp new file mode 100644 index 0000000..2073901 --- /dev/null +++ b/Note_Taker/src/main/webapp/navbar.jsp @@ -0,0 +1,70 @@ +<%@page import="com.enti.Register_table"%> +<% +String user1=(String)session.getAttribute("current-user"); +%> + + +<%-- <%@include file="all_js_cs.jsp"%> --%> + + + +<% + + /* if(session.getAttribute("login_id")==null){ + + out.println("Please login First!!!"); + + response.sendRedirect("index.jsp"); + + } */ + %> + +
+ + +
+ + diff --git a/Note_Taker/src/main/webapp/sign_up.jsp b/Note_Taker/src/main/webapp/sign_up.jsp new file mode 100644 index 0000000..161cee7 --- /dev/null +++ b/Note_Taker/src/main/webapp/sign_up.jsp @@ -0,0 +1,61 @@ + + +Note Taker:Sign Up +<%@include file="all_js_cs.jsp"%> + + + + +
+
+
+ +
+
+

This is a Register page

+
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+ +
+ + +
+ +
+ +
+ + + diff --git a/Note_Taker/src/main/webapp/signin.jsp b/Note_Taker/src/main/webapp/signin.jsp new file mode 100644 index 0000000..e1ba8d7 --- /dev/null +++ b/Note_Taker/src/main/webapp/signin.jsp @@ -0,0 +1,50 @@ +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +Note Taker: Sign In Page +<%@include file="all_js_cs.jsp"%> + + + +
+
+
+
+
+

This is Login page

+
+
+ <%@include file="message.jsp"%> + + +
+
+ +
+
+ +
+
+ + +
+ +
+ + New User here? Sign + up Forgot password? +
+
+
+ + \ No newline at end of file diff --git a/Note_Taker/target/classes/com/enti/Note.class b/Note_Taker/target/classes/com/enti/Note.class new file mode 100644 index 0000000..a2eba87 Binary files /dev/null and b/Note_Taker/target/classes/com/enti/Note.class differ diff --git a/Note_Taker/target/classes/com/enti/Register_table.class b/Note_Taker/target/classes/com/enti/Register_table.class new file mode 100644 index 0000000..04aee02 Binary files /dev/null and b/Note_Taker/target/classes/com/enti/Register_table.class differ diff --git a/Note_Taker/target/classes/com/helper/FactoryProvider.class b/Note_Taker/target/classes/com/helper/FactoryProvider.class new file mode 100644 index 0000000..7bddf16 Binary files /dev/null and b/Note_Taker/target/classes/com/helper/FactoryProvider.class differ diff --git a/Note_Taker/target/classes/com/servlets/DeleteServlet.class b/Note_Taker/target/classes/com/servlets/DeleteServlet.class new file mode 100644 index 0000000..f111cb3 Binary files /dev/null and b/Note_Taker/target/classes/com/servlets/DeleteServlet.class differ diff --git a/Note_Taker/target/classes/com/servlets/Forget.class b/Note_Taker/target/classes/com/servlets/Forget.class new file mode 100644 index 0000000..55283f1 Binary files /dev/null and b/Note_Taker/target/classes/com/servlets/Forget.class differ diff --git a/Note_Taker/target/classes/com/servlets/Jdbcconnection.class b/Note_Taker/target/classes/com/servlets/Jdbcconnection.class new file mode 100644 index 0000000..8548636 Binary files /dev/null and b/Note_Taker/target/classes/com/servlets/Jdbcconnection.class differ diff --git a/Note_Taker/target/classes/com/servlets/Log_out.class b/Note_Taker/target/classes/com/servlets/Log_out.class new file mode 100644 index 0000000..c5d7821 Binary files /dev/null and b/Note_Taker/target/classes/com/servlets/Log_out.class differ diff --git a/Note_Taker/target/classes/com/servlets/SaveNoteServlet.class b/Note_Taker/target/classes/com/servlets/SaveNoteServlet.class new file mode 100644 index 0000000..de6b15f Binary files /dev/null and b/Note_Taker/target/classes/com/servlets/SaveNoteServlet.class differ diff --git a/Note_Taker/target/classes/com/servlets/Signin.class b/Note_Taker/target/classes/com/servlets/Signin.class new file mode 100644 index 0000000..b0c362b Binary files /dev/null and b/Note_Taker/target/classes/com/servlets/Signin.class differ diff --git a/Note_Taker/target/classes/com/servlets/Signup.class b/Note_Taker/target/classes/com/servlets/Signup.class new file mode 100644 index 0000000..75f2344 Binary files /dev/null and b/Note_Taker/target/classes/com/servlets/Signup.class differ diff --git a/Note_Taker/target/classes/com/servlets/UpdateServlet.class b/Note_Taker/target/classes/com/servlets/UpdateServlet.class new file mode 100644 index 0000000..b19fb2f Binary files /dev/null and b/Note_Taker/target/classes/com/servlets/UpdateServlet.class differ diff --git a/Note_Taker/target/classes/hibernate.cfg.xml b/Note_Taker/target/classes/hibernate.cfg.xml new file mode 100644 index 0000000..b2692a6 --- /dev/null +++ b/Note_Taker/target/classes/hibernate.cfg.xml @@ -0,0 +1,20 @@ + + + + + + com.mysql.jdbc.Driver + jdbc:mysql://localhost:3306/myhiber + root + + org.hibernate.dialect.MySQL5Dialect + update + true + true + true + + + + + \ No newline at end of file diff --git a/Note_Taker/target/m2e-wtp/web-resources/META-INF/MANIFEST.MF b/Note_Taker/target/m2e-wtp/web-resources/META-INF/MANIFEST.MF new file mode 100644 index 0000000..acb2d4b --- /dev/null +++ b/Note_Taker/target/m2e-wtp/web-resources/META-INF/MANIFEST.MF @@ -0,0 +1,5 @@ +Manifest-Version: 1.0 +Built-By: This PC +Build-Jdk: 12.0.1 +Created-By: Maven Integration for Eclipse + diff --git a/Note_Taker/target/m2e-wtp/web-resources/META-INF/maven/com.learn/Note_Taker/pom.properties b/Note_Taker/target/m2e-wtp/web-resources/META-INF/maven/com.learn/Note_Taker/pom.properties new file mode 100644 index 0000000..475dd8e --- /dev/null +++ b/Note_Taker/target/m2e-wtp/web-resources/META-INF/maven/com.learn/Note_Taker/pom.properties @@ -0,0 +1,7 @@ +#Generated by Maven Integration for Eclipse +#Mon Jul 27 18:42:24 IST 2020 +m2e.projectLocation=E\:\\harshit\\All program\\web project\\Note_Taker +m2e.projectName=Note_Taker +groupId=com.learn +artifactId=Note_Taker +version=0.0.1-SNAPSHOT diff --git a/Note_Taker/target/m2e-wtp/web-resources/META-INF/maven/com.learn/Note_Taker/pom.xml b/Note_Taker/target/m2e-wtp/web-resources/META-INF/maven/com.learn/Note_Taker/pom.xml new file mode 100644 index 0000000..03fc4a3 --- /dev/null +++ b/Note_Taker/target/m2e-wtp/web-resources/META-INF/maven/com.learn/Note_Taker/pom.xml @@ -0,0 +1,38 @@ + + 4.0.0 + com.learn + Note_Taker + war + 0.0.1-SNAPSHOT + Note_Taker Maven Webapp + http://maven.apache.org + + + junit + junit + 3.8.1 + test + + + + + org.hibernate + hibernate-core + 5.4.5.Final + + + + + + mysql + mysql-connector-java + 5.1.48 + + + + + Note_Taker + + diff --git a/Number b/Number new file mode 100644 index 0000000..5773901 --- /dev/null +++ b/Number @@ -0,0 +1,12 @@ +import java.lang.Math; +public class RandomNumberExample1 +{ +public static void main(String args[]) +{ +// Generating random numbers +System.out.println("1st Random Number: " + Math.random()); +System.out.println("2nd Random Number: " + Math.random()); +System.out.println("3rd Random Number: " + Math.random()); +System.out.println("4th Random Number: " + Math.random()); +} +} diff --git a/Object in JavaScript b/Object in JavaScript new file mode 100644 index 0000000..0823a64 --- /dev/null +++ b/Object in JavaScript @@ -0,0 +1,6 @@ +Obj = { +Name : "Samir", +Age : 20, +Job : "A Softwareengineer" +} + Console.log (obj); diff --git a/Online Exam Using Java b/Online Exam Using Java new file mode 100644 index 0000000..ff6a1ec --- /dev/null +++ b/Online Exam Using Java @@ -0,0 +1,186 @@ + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; + +class OnlineTest extends JFrame implements ActionListener +{ + JLabel l; + JRadioButton jb[]=new JRadioButton[5]; + JButton b1,b2; + ButtonGroup bg; + int count=0,current=0,x=1,y=1,now=0; + int m[]=new int[10]; + OnlineTest(String s) + { + super(s); + l=new JLabel(); + add(l); + bg=new ButtonGroup(); + for(int i=0;i<5;i++) + { + jb[i]=new JRadioButton(); + add(jb[i]); + bg.add(jb[i]); + } + b1=new JButton("Next"); + b2=new JButton("Bookmark"); + b1.addActionListener(this); + b2.addActionListener(this); + add(b1);add(b2); + set(); + l.setBounds(30,40,450,20); + jb[0].setBounds(50,80,100,20); + jb[1].setBounds(50,110,100,20); + jb[2].setBounds(50,140,100,20); + jb[3].setBounds(50,170,100,20); + b1.setBounds(100,240,100,30); + b2.setBounds(270,240,100,30); + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + setLayout(null); + setLocation(250,100); + setVisible(true); + setSize(600,350); + } + public void actionPerformed(ActionEvent e) + { + if(e.getSource()==b1) + { + if(check()) + count=count+1; + current++; + set(); + if(current==9) + { + b1.setEnabled(false); + b2.setText("Result"); + } + } + if(e.getActionCommand().equals("Bookmark")) + { + JButton bk=new JButton("Bookmark"+x); + bk.setBounds(480,20+30*x,100,30); + add(bk); + bk.addActionListener(this); + m[x]=current; + x++; + current++; + set(); + if(current==9) + b2.setText("Result"); + setVisible(false); + setVisible(true); + } + for(int i=0,y=1;i0){ + r=n%10; //getting remainder + sum=(sum*10)+r; + n=n/10; + } + if(temp==sum) + System.out.println("palindrome number "); + else + System.out.println("not palindrome"); +} +} diff --git a/Palindrome Number b/Palindrome Number new file mode 100644 index 0000000..366775a --- /dev/null +++ b/Palindrome Number @@ -0,0 +1,23 @@ +import java.util.Scanner; +class PalinRun +{ +public static void main(String ar[]) +{ +int num,rev=0,rem,n; +Scanner s=new Scanner(System.in); +System.out.println("enter no"); +num=s.nextInt(); +n=num; +do +{ +rem=num%10; +rev=rev*10+rem; +num=num/10; +} +while(num>0); +if(n==rev) +System.out.println("no is palindrome"); +else +System.out.println("no is not a palindrome "); +} +} diff --git a/Palindrome Program in Java b/Palindrome Program in Java new file mode 100644 index 0000000..dc3ad55 --- /dev/null +++ b/Palindrome Program in Java @@ -0,0 +1,17 @@ +class PalindromeExample{ + public static void main(String args[]){ + int r,sum=0,temp; + int n=454;//It is the number variable to be checked for palindrome + + temp=n; + while(n>0){ + r=n%10; //getting remainder + sum=(sum*10)+r; + n=n/10; + } + if(temp==sum) + System.out.println("palindrome number "); + else + System.out.println("not palindrome"); +} +} diff --git a/Palindrome number b/Palindrome number new file mode 100644 index 0000000..a1a6a86 --- /dev/null +++ b/Palindrome number @@ -0,0 +1,23 @@ +public class Palindrome { + + public static void main(String[] args) { + + int num = 121, reversedInteger = 0, remainder, originalInteger; + + originalInteger = num; + + // reversed integer is stored in variable + while( num != 0 ) + { + remainder = num % 10; + reversedInteger = reversedInteger * 10 + remainder; + num /= 10; + } + + // palindrome if orignalInteger and reversedInteger are equal + if (originalInteger == reversedInteger) + System.out.println(originalInteger + " is a palindrome."); + else + System.out.println(originalInteger + " is not a palindrome."); + } +} diff --git a/PascalTriangle.java b/PascalTriangle.java new file mode 100644 index 0000000..db89664 --- /dev/null +++ b/PascalTriangle.java @@ -0,0 +1,41 @@ +package com.sanket.Array; + +import java.util.ArrayList; +import java.util.List; + +/* + Problem Link - https://leetcode.com/problems/pascals-triangle/ + Status - Accepted + */ +public class PascalTriangle { + + public static void main(String[] args) { + int num = 3; + generate(num); + } + + public static List> generate(int numRows) { + List> lists = new ArrayList<>(); + if (numRows < 1) { return lists; } + List first = new ArrayList<>(); + first.add(1); + lists.add(first); + int i = 1; + while (i < numRows) { + List integers = new ArrayList<>(); + for (int j = 0; j <= i; j++) { + if (j == 0 || j == i) { + integers.add(1); + } + else { + List prev = lists.get(i - 1); + int total = prev.get(j - 1) + prev.get(j); + integers.add(total); + } + } + lists.add(integers); + i++; + } + return lists; + } +} \ No newline at end of file diff --git a/Pattern Programs in Java b/Pattern Programs in Java new file mode 100644 index 0000000..80b89ea --- /dev/null +++ b/Pattern Programs in Java @@ -0,0 +1,22 @@ +public class Edureka +{ + public static void rightTriangle(int n) + { + int i, j; + for(i=0; i=0; j--) // inner loop for spaces + { + System.out.print(" "); // printing space + } + for(j=0; j<=i; j++) // inner loop for columns + { + System.out.print("* "); // print star + } + System.out.println(); // ending line after each row + } + } + public static void main(String args[]) + { + int n = 5; + rightTriangle(n); + } +} diff --git a/Prime Number b/Prime Number new file mode 100644 index 0000000..a6a49c0 --- /dev/null +++ b/Prime Number @@ -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/Prime number b/Prime number new file mode 100644 index 0000000..5004565 --- /dev/null +++ b/Prime number @@ -0,0 +1,28 @@ +import java.util.Scanner; +class PrimeCheck +{ + public static void main(String args[]) + { + int temp; + boolean isPrime=true; + Scanner scan= new Scanner(System.in); + System.out.println("Enter any number:"); + //capture the input in an integer + int num=scan.nextInt(); + scan.close(); + for(int i=2;i<=num/2;i++) + { + temp=num%i; + if(temp==0) + { + isPrime=false; + break; + } + } + //If isPrime is true then the number is prime else not + if(isPrime) + System.out.println(num + " is a Prime Number"); + else + System.out.println(num + " is not a Prime Number"); + } +} diff --git a/Prime numbers b/Prime numbers new file mode 100644 index 0000000..f15026f --- /dev/null +++ b/Prime numbers @@ -0,0 +1,23 @@ +import java.util.*; + +public class Main{ + public static void main(String[] args) { + Scanner scn = new Scanner(System.in); + int low = scn.nextInt(); + int high = scn.nextInt(); + + for(int n = low; n <= high; n++){ + + int count = 0; + for(int div = 2; div * div <= n; div++){ + if(n % div == 0){ + count++; + break; + } + } + if(count==0){ + System.out.println(n); + } + } + } +} diff --git a/PrimeNumber b/PrimeNumber new file mode 100644 index 0000000..40bcefc --- /dev/null +++ b/PrimeNumber @@ -0,0 +1,23 @@ +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/Print Floyd's Triangle b/Print Floyd's Triangle new file mode 100644 index 0000000..e5528b3 --- /dev/null +++ b/Print Floyd's Triangle @@ -0,0 +1,16 @@ +public class Pattern { + + public static void main(String[] args) { + int rows = 4, number = 1; + + for(int i = 1; i <= rows; i++) { + + for(int j = 1; j <= i; j++) { + System.out.print(number + " "); + ++number; + } + + System.out.println(); + } + } +} diff --git a/Program for checking a number is Palindrome or not b/Program for checking a number is Palindrome or not new file mode 100644 index 0000000..a1a6a86 --- /dev/null +++ b/Program for checking a number is Palindrome or not @@ -0,0 +1,23 @@ +public class Palindrome { + + public static void main(String[] args) { + + int num = 121, reversedInteger = 0, remainder, originalInteger; + + originalInteger = num; + + // reversed integer is stored in variable + while( num != 0 ) + { + remainder = num % 10; + reversedInteger = reversedInteger * 10 + remainder; + num /= 10; + } + + // palindrome if orignalInteger and reversedInteger are equal + if (originalInteger == reversedInteger) + System.out.println(originalInteger + " is a palindrome."); + else + System.out.println(originalInteger + " is not a palindrome."); + } +} diff --git a/Program to check leap year b/Program to check leap year new file mode 100644 index 0000000..9f66df9 --- /dev/null +++ b/Program to check leap year @@ -0,0 +1,57 @@ +import java.util.Scanner; + +public class Demo { + + public static void main(String[] args) { + + int year; Scanner scan = new Scanner(System.in); + + System.out.println("Enter any Year:"); + + year = scan.nextInt(); + + scan.close(); + + boolean isLeap = false; + + if(year % 4 == 0) + + { + + if( year % 100 == 0) + + { + + if ( year % 400 == 0) + + isLeap = true; + + else + + isLeap = false; + + } + + else + + isLeap = true; + + } + + else { + + isLeap = false; + + } + + if(isLeap==true) + + System.out.println(year + " is a Leap Year."); + + else + + System.out.println(year + " is not a Leap Year."); + + } + +} diff --git a/Program to display the grade of student. b/Program to display the grade of student. new file mode 100644 index 0000000..1524923 --- /dev/null +++ b/Program to display the grade of student. @@ -0,0 +1,53 @@ +import java.util.Scanner; + +public class JavaExample +{ + public static void main(String args[]) + { + /* This program assumes that the student has 6 subjects, + * thats why I have created the array of size 6. You can + * change this as per the requirement. + */ + int marks[] = new int[6]; + int i; + float total=0, avg; + Scanner scanner = new Scanner(System.in); + + + for(i=0; i<6; i++) { + System.out.print("Enter Marks of Subject"+(i+1)+":"); + marks[i] = scanner.nextInt(); + total = total + marks[i]; + } + scanner.close(); + //Calculating average here + avg = total/6; + System.out.print("The student Grade is: "); + if(avg>=80) + { + System.out.print("A"); + } + else if(avg>=60 && avg<80) + { + System.out.print("B"); + } + else if(avg>=40 && avg<60) + { + System.out.print("C"); + } + else + { + System.out.print("D"); + } + } +} + +Output: + +Enter Marks of Subject1:40 +Enter Marks of Subject2:80 +Enter Marks of Subject3:80 +Enter Marks of Subject4:40 +Enter Marks of Subject5:60 +Enter Marks of Subject6:60 +The student Grade is: B diff --git a/Pyramid for 5 rows b/Pyramid for 5 rows new file mode 100644 index 0000000..87d31c0 --- /dev/null +++ b/Pyramid for 5 rows @@ -0,0 +1,13 @@ +public class Pattern { + + public static void main(String[] args) { + int rows = 5; + + for(int i = 1; i <= rows; ++i) { + for(int j = 1; j <= i; ++j) { + System.out.print("* "); + } + System.out.println(); + } + } +} diff --git a/Pythagorean Triplets b/Pythagorean Triplets new file mode 100644 index 0000000..cb799af --- /dev/null +++ b/Pythagorean Triplets @@ -0,0 +1,26 @@ +import java.util.*; + + public class Main { + + public static void main(String[] args) { + Scanner scn = new Scanner(System.in); + int a = scn.nextInt(); + int b = scn.nextInt(); + int c = scn.nextInt(); + + int max = a; + if(b >= max) + max = b; + + if(c >= max) + max = c; + + if(max == a){ + System.out.println((b * b + c * c) == (a * a)); + } else if(max == b){ + System.out.println((a * a + c * c) == (b * b)); + } else { + System.out.println((a * a + b * b) == (c * c)); + } + } + } diff --git a/Python Program for Fibonacci series b/Python Program for Fibonacci series new file mode 100644 index 0000000..9f6b1b3 --- /dev/null +++ b/Python Program for Fibonacci series @@ -0,0 +1,23 @@ +# Program to display the Fibonacci sequence up to n-th term + +nterms = int(input("How many terms? ")) + +# first two terms +n1, n2 = 0, 1 +count = 0 + +# check if the number of terms is valid +if nterms <= 0: + print("Please enter a positive integer") +elif nterms == 1: + print("Fibonacci sequence upto",nterms,":") + print(n1) +else: + print("Fibonacci sequence:") + while count < nterms: + print(n1) + nth = n1 + n2 + # update values + n1 = n2 + n2 = nth + count += 1 diff --git a/Quotient and Remainder of a number b/Quotient and Remainder of a number new file mode 100644 index 0000000..fa884ba --- /dev/null +++ b/Quotient and Remainder of a number @@ -0,0 +1,9 @@ +public class JavaExample { + public static void main(String[] args) { + int num_1 = 15, num_2 = 2; + int quotient = num_1 / num_2; + int remainder = num_1 % num_2; + System.out.println("Quotient is: " + quotient); + System.out.println("Remainder is: " + remainder); + } +} diff --git a/README.md b/README.md index cd4eb38..f6a16d7 100644 --- a/README.md +++ b/README.md @@ -1 +1,6 @@ -# javaprogram \ No newline at end of file +# javaprogram +class test() +public static void main (string []args) +{ +system.out.println("seed it solution") +} diff --git a/Rainbow Program b/Rainbow Program new file mode 100644 index 0000000..5302cf7 --- /dev/null +++ b/Rainbow Program @@ -0,0 +1,57 @@ +import java.awt.Color; + +public class Rainbow { + + public static void main(String[] args) { + + int N = Integer.parseInt(args[0]); + int SIZE = 1000; + StdDraw.setCanvasSize(SIZE, SIZE/2); + StdDraw.setXscale(0, SIZE); + StdDraw.setYscale(0, SIZE/2.0); + StdDraw.enableDoubleBuffering(); + + Color skyblue = new Color(48, 144, 199); + StdDraw.clear(skyblue); + + for (int i = 0; i < N; i++) { + + double r = Math.random(); + double theta = Math.random() * 2 * Math.PI; + double x = Math.sqrt(r) * Math.sin(theta); + double y = Math.sqrt(r) * Math.cos(theta); + + float c = (float) Math.random(); + double n = 1.33 + 0.06 * c; + double thetaI = Math.asin(r); + double thetaR = Math.asin(r / n); + double thetaP = 4*thetaR - 2*thetaI; + double thetaS = 6*thetaR - 2*thetaI - Math.PI; + + double p = Math.pow(Math.sin(thetaI - thetaR) + double s = Math.pow(Math.tan(thetaI - thetaR) + double intensityP = 0.5 * ( s*(1-s)*(1-s) + p*(1-p)*(1-p)); + double intensityS = 0.5 * (s*s*(1-s)*(1-s) + p*p*(1-p)*(1-p)); + + float saturation = (float) Math.min(intensityP / 0.04, 1.0); + StdDraw.setPenColor(Color.getHSBColor(c, saturation, 1.0f)); + double xp = (SIZE/2.0 * thetaP * 3 / Math.PI * x / r) + SIZE / 2.0; + double yp = (SIZE/2.0 * thetaP * 3 / Math.PI * Math.abs(y) / r); + StdDraw.point(xp, yp); + + saturation = (float) Math.min(intensityS / 0.02, 1.0); + StdDraw.setPenColor(Color.getHSBColor(c, saturation, 1.0f)); + double xs = ( SIZE/2.0 * thetaS * 3 / Math.PI * x / r) + SIZE / 2.0; + double ys = (-SIZE/2.0 * thetaS * 3 / Math.PI * Math.abs(y) / r); + StdDraw.point(xs, ys); + + if (i % 1000 == 0) { + StdDraw.show(); + StdDraw.pause(10); + } + } + + StdDraw.show(); + } + +} diff --git a/Remove duplicates in array b/Remove duplicates in array new file mode 100644 index 0000000..d5fa94f --- /dev/null +++ b/Remove duplicates in array @@ -0,0 +1,26 @@ +import java.util.ArrayList; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Set; + +public class ArrayListDuplicateDemo{ + public static void main(String args[]){ + List primes = new ArrayList(); + + primes.add(2); + primes.add(3); + primes.add(5); + primes.add(7); //duplicate + primes.add(7); + primes.add(11); + + System.out.println("list of prime numbers : " + primes); + + Set primesWithoutDuplicates = new LinkedHashSet(primes); + primes.clear(); + + primes.addAll(primesWithoutDuplicates); + + System.out.println("list of primes without duplicates : " + primes); + } +} diff --git a/Reverse a Number using a while loop in Java b/Reverse a Number using a while loop in Java new file mode 100644 index 0000000..1350bf4 --- /dev/null +++ b/Reverse a Number using a while loop in Java @@ -0,0 +1,15 @@ +public class ReverseNumber { + + public static void main(String[] args) { + + int num = 1234, reversed = 0; + + while(num != 0) { + int digit = num % 10; + reversed = reversed * 10 + digit; + num /= 10; + } + + System.out.println("Reversed Number: " + reversed); + } +} diff --git a/Reverse a Sentence Using Recursion b/Reverse a Sentence Using Recursion new file mode 100644 index 0000000..11196d7 --- /dev/null +++ b/Reverse a Sentence Using Recursion @@ -0,0 +1,15 @@ +public class Reverse { + + public static void main(String[] args) { + String sentence = "Go work"; + String reversed = reverse(sentence); + System.out.println("The reversed sentence is: " + reversed); + } + + public static String reverse(String sentence) { + if (sentence.isEmpty()) + return sentence; + + return reverse(sentence.substring(1)) + sentence.charAt(0); + } +} diff --git a/Reverse a number b/Reverse a number new file mode 100644 index 0000000..f3e470c --- /dev/null +++ b/Reverse a number @@ -0,0 +1,14 @@ + public class ReverseNumberExample1 + { + public static void main(String[] args) + { + int number = 987654, reverse = 0; + while(number != 0) + { + int remainder = number % 10; + reverse = reverse * 10 + remainder; + number = number/10; + } + System.out.println("The reverse of the given number is: " + reverse); + } + } diff --git a/Reverse a string b/Reverse a string new file mode 100644 index 0000000..290f716 --- /dev/null +++ b/Reverse a string @@ -0,0 +1,17 @@ + +import java.lang.*; +import java.io.*; +import java.util.*; + +// Class of ReverseString +class ReverseString { + public static void main(String[] args) + { + String input = "Hackober Fest"; + + char[] try1 = input.toCharArray(); + + for (int i = try1.length - 1; i >= 0; i--) + System.out.print(try1[i]); + } +} diff --git a/ReverseString b/ReverseString new file mode 100644 index 0000000..c4708bf --- /dev/null +++ b/ReverseString @@ -0,0 +1,25 @@ +// Java program to ReverseString using ByteArray. +import java.lang.*; +import java.io.*; +import java.util.*; + +// Class of ReverseString +class ReverseString { + public static void main(String[] args) + { + String input = "GeeksforGeeks"; + + // getBytes() method to convert string + // into bytes[]. + byte[] strAsByteArray = input.getBytes(); + + byte[] result = new byte[strAsByteArray.length]; + + // Store result in reverse order into the + // result byte[] + for (int i = 0; i < strAsByteArray.length; i++) + result[i] = strAsByteArray[strAsByteArray.length - i - 1]; + + System.out.println(new String(result)); + } +} diff --git a/SetMatrixZeroes .java b/SetMatrixZeroes .java new file mode 100644 index 0000000..2444727 --- /dev/null +++ b/SetMatrixZeroes .java @@ -0,0 +1,61 @@ +package com.sanket.Array; + +/* + Problem Link - https://leetcode.com/problems/set-matrix-zeroes/ + Status - Accepted + */ +public class SetMatrixZeroes { + + public void setZeroes(int[][] matrix) { + int rows = matrix.length; + if (rows < 1) { return; } + int cols = matrix[0].length; + boolean isZeroRow = false; + boolean isZeroCol = false; + for (int i = 0; i < rows; i++) { + if (matrix[i][0] == 0) { + isZeroCol = true; + break; + } + } + + for (int i = 0; i < cols; i++) { + if (matrix[0][i] == 0) { + isZeroRow = true; + break; + } + } + + for (int i = 1; i < rows; i++) { + for (int j = 1; j < cols; j++) { + if (matrix[i][j] == 0) { + matrix[i][0] = 0; + matrix[0][j] = 0; + } + } + } + + for (int i = 1; i < rows; i++) { + for (int j = 1; j < cols; j++) { + if (matrix[i][0] == 0 || + matrix[0][j] == 0) { + matrix[i][j] = 0; + } + } + } + + if (isZeroCol) { + for (int i = 0; i < rows; i++) { + matrix[i][0] = 0; + } + } + if (isZeroRow) { + for (int i = 0; i < cols; i++) { + matrix[0][i] = 0; + } + } + + + } + +} \ No newline at end of file diff --git a/Single_Linkedlist/Linkedlist.java b/Single_Linkedlist/Linkedlist.java new file mode 100644 index 0000000..652984f --- /dev/null +++ b/Single_Linkedlist/Linkedlist.java @@ -0,0 +1,114 @@ +package Linkedlist.Single_Linkedlist; + +public class Linkedlist { + + Node head; + public void insert(int data) + { + Node node=new Node(); + node.data=data; + node.next=null; + + if(head==null) + { + head=node; + } + else + { + Node n=head; + while(n.next!=null) + { + n=n.next; + } + n.next=node; + } + } + + public void insertAtStart(int data) + { + Node node=new Node(); + node.data=data; + node.next=null; + node.next=head; + head=node; + } + + public void insertAt(int index,int data) + { + Node node=new Node(); + node.data=data; + node.next=null; + + if(index==0) + { + insertAtStart(data); + } + else + { + Node n=head; + for(int i=0;imap=new LinkedHashMap<>(); + for(int i=0;i>list=new LinkedList<>(map.entrySet()); + Collections.sort(list,new Comparator>() { + @Override + public int compare(Entry o1, Entry o2) { + // TODO Auto-generated method stub + return o2.getValue().compareTo(o1.getValue()); + } + }); +System.out.println(list); +int k=o.nextInt(); +int arr[]=new int[k]; +for(int i=0;i1;j--)//inner loop for number of column + { + System.out.print(" "); + } + for(int j=0;j<=i;j++) + {System.out.print("*"); + } + System.out.println(); + } + } + public static void main (String args[]) + { + int n=5; + pyramidPattern(n); + } + } + diff --git a/String Reverse b/String Reverse new file mode 100644 index 0000000..e1ca951 --- /dev/null +++ b/String Reverse @@ -0,0 +1,23 @@ +package com.journaldev.javaprograms; + +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/Subset of an array b/Subset of an array new file mode 100644 index 0000000..d08dbe6 --- /dev/null +++ b/Subset of an array @@ -0,0 +1,31 @@ +package array; + +import java.util.Scanner; + +public class Subset { + + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + int size = sc.nextInt(); + int[] arr1 = new int[size]; + for(int i = 0; i < arr1.length; i++) { + arr1[i]= sc.nextInt(); + } + int limit = (int)Math.pow(2, arr1.length); + for(int i = 0; i =0; j--) { + int r = temp %2; + temp = temp/2; + if(r == 0) { + set = "-"+" " + set; + }else { + set = arr1[j]+ " "+ set; + } + } + System.out.println(set); + } + } + +} diff --git a/Sum of Two Numbers b/Sum of Two Numbers new file mode 100644 index 0000000..277c216 --- /dev/null +++ b/Sum of Two Numbers @@ -0,0 +1,16 @@ +import java.util.Scanner; // Import the Scanner class + +public class MyClass { + public static void main(String[] args) { + int x, y, sum; + Scanner myObj = new Scanner(System.in); // Create a Scanner object + System.out.println("Type a number:"); + x = myObj.nextInt(); // Read user input + + System.out.println("Type another number:"); + y = myObj.nextInt(); // Read user input + + sum = x + y; + System.out.println("Sum is: " + sum); // Output user input + } +} diff --git a/Sum of two numbers b/Sum of two numbers new file mode 100644 index 0000000..ed50b9a --- /dev/null +++ b/Sum of two numbers @@ -0,0 +1,18 @@ +import java.util.Scanner; +public class AddTwoNumbers2 { + + public static void main(String[] args) { + + int num1, num2, sum; + Scanner sc = new Scanner(System.in); + System.out.println("Enter First Number: "); + num1 = sc.nextInt(); + + System.out.println("Enter Second Number: "); + num2 = sc.nextInt(); + + sc.close(); + sum = num1 + num2; + System.out.println("Sum of these numbers: "+sum); + } +} diff --git a/SwapNumbers b/SwapNumbers new file mode 100644 index 0000000..ff675de --- /dev/null +++ b/SwapNumbers @@ -0,0 +1,24 @@ +public class SwapNumbers { + + public static void main(String[] args) { + + float first = 1.20f, second = 2.45f; + + System.out.println("--Before swap--"); + System.out.println("First number = " + first); + System.out.println("Second number = " + second); + + // Value of first is assigned to temporary + float temporary = first; + + // Value of second is assigned to first + first = second; + + // Value of temporary (which contains the initial value of first) is assigned to second + second = temporary; + + System.out.println("--After swap--"); + System.out.println("First number = " + first); + System.out.println("Second number = " + second); + } +} diff --git a/Swap_two_no b/Swap_two_no new file mode 100644 index 0000000..d64bd3c --- /dev/null +++ b/Swap_two_no @@ -0,0 +1,24 @@ +public class SwapNumbers { + + public static void main(String[] args) { + + float first = 1.20f, second = 2.45f; + + System.out.println("--Before swap--"); + System.out.println("First number = " + first); + System.out.println("Second number = " + second); + + + float temporary = first; + + + first = second; + + + second = temporary; + + System.out.println("--After swap--"); + System.out.println("First number = " + first); + System.out.println("Second number = " + second); + } +} diff --git a/TimSort.java b/TimSort.java new file mode 100644 index 0000000..be25b00 --- /dev/null +++ b/TimSort.java @@ -0,0 +1,137 @@ +class TimSort +{ + + static int RUN = 32; + + // this function sorts array from left index to + // to right index which is of size atmost RUN + public static void insertionSort(int[] arr, int left, int right) + { + for (int i = left + 1; i <= right; i++) + { + int temp = arr[i]; + int j = i - 1; + while (j >= left && arr[j] > temp) + { + arr[j + 1] = arr[j]; + j--; + } + arr[j + 1] = temp; + } + } + + // merge function merges the sorted runs + public static void merge(int[] arr, int l, + int m, int r) + { + // original array is broken in two parts + // left and right array + int len1 = m - l + 1, len2 = r - m; + int[] left = new int[len1]; + int[] right = new int[len2]; + for (int x = 0; x < len1; x++) + { + left[x] = arr[l + x]; + } + for (int x = 0; x < len2; x++) + { + right[x] = arr[m + 1 + x]; + } + + int i = 0; + int j = 0; + int k = l; + + // after comparing, we merge those two array + // in larger sub array + while (i < len1 && j < len2) + { + if (left[i] <= right[j]) + { + arr[k] = left[i]; + i++; + } + else + { + arr[k] = right[j]; + j++; + } + k++; + } + + // copy remaining elements of left, if any + while (i < len1) + { + arr[k] = left[i]; + k++; + i++; + } + + // copy remaining element of right, if any + while (j < len2) + { + arr[k] = right[j]; + k++; + j++; + } + } + + // iterative Timsort function to sort the + // array[0...n-1] (similar to merge sort) + public static void timSort(int[] arr, int n) + { + + // Sort individual subarrays of size RUN + for (int i = 0; i < n; i += RUN) + { + insertionSort(arr, i, Math.min((i + 31), (n - 1))); + } + + // start merging from size RUN (or 32). It will merge + // to form size 64, then 128, 256 and so on .... + for (int size = RUN; size < n; size = 2 * size) + { + + // pick starting point of left sub array. We + // are going to merge arr[left..left+size-1] + // and arr[left+size, left+2*size-1] + // After every merge, we increase left by 2*size + for (int left = 0; left < n; left += 2 * size) + { + + // find ending point of left sub array + // mid+1 is starting point of right sub array + int mid = left + size - 1; + int right = Math.min((left + 2 * size - 1), (n - 1)); + + // merge sub array arr[left.....mid] & + // arr[mid+1....right] + merge(arr, left, mid, right); + } + } + } + + // utility function to print the Array + public static void printArray(int[] arr, int n) + { + for (int i = 0; i < n; i++) + { + System.out.print(arr[i] + " "); + } + System.out.print("\n"); + } + + // Driver code + public static void main(String[] args) + { + int[] arr = {5, 21, 7, 23, 19}; + int n = arr.length; + System.out.print("Given Array is\n"); + printArray(arr, n); + + timSort(arr, n); + + System.out.print("After Sorting Array is\n"); + printArray(arr, n); + } +} diff --git a/To calculate area of circle b/To calculate area of circle new file mode 100644 index 0000000..5704fc3 --- /dev/null +++ b/To calculate area of circle @@ -0,0 +1,26 @@ +import java.util.Scanner; +public class Area +{ + public static void main(String[] args) + { + int r; + double pi = 3.14, area; + Scanner s = new Scanner(System.in); + System.out.print("Enter radius of circle:"); + r = s.nextInt(); + area = pi * r * r; + System.out.println("Area of circle:"+area); + } +} + + + + + + + + + + + + diff --git a/To find the largest number b/To find the largest number new file mode 100644 index 0000000..1eb7e36 --- /dev/null +++ b/To find the largest number @@ -0,0 +1,19 @@ +public class Largest { + + public static void main(String[] args) { + + double n1 = -4.5, n2 = 3.9, n3 = 5.5; + + if(n1 >= n2) { + if(n1 >= n3) + System.out.println(n1 + " is the largest number."); + else + System.out.println(n3 + " is the largest number."); + } else { + if(n2 >= n3) + System.out.println(n2 + " is the largest number."); + else + System.out.println(n3 + " is the largest number."); + } + } +} diff --git a/TowerOfHanio b/TowerOfHanio new file mode 100644 index 0000000..0f3a2a5 --- /dev/null +++ b/TowerOfHanio @@ -0,0 +1,19 @@ + +// Function solution to count the move in TOH + +class Hanoi { + + public long toh(int N, int from, int to, int aux) { + // Your code here + long moves = 0L; + if(N>=1) + { + // System.out.println("move disk n from "+from+ "to rod "+to); + moves=moves+toh(N-1,from, aux, to); + System.out.println("move disk "+ N +" from rod "+ from + " to rod "+ to); + moves++; + moves=moves+toh(N-1,aux, to, from); + + } + return moves; +}} diff --git a/Transport b/Transport new file mode 100644 index 0000000..1bcee3f --- /dev/null +++ b/Transport @@ -0,0 +1,55 @@ +CREATE TABLE "PAYREGISTER" +( "ID" NUMBER, +"USERNAME" VARCHAR2(4000), +"USERPASS" VARCHAR2(4000), +"BRANCH" VARCHAR2(4000), +"DATEOFJOINING" VARCHAR2(4000), +"DATEOFBIRTH" VARCHAR2(4000), +"SALARY" VARCHAR2(4000), +CONSTRAINT "PAYREGISTER_PK" PRIMARY KEY ("ID") ENABLE +) +/ + +CREATE OR REPLACE TRIGGER "BI_PAYREGISTER" +before insert on "PAYREGISTER" +for each row +begin +select "PAYREGISTER_SEQ".nextval into :NEW.ID from dual; +end; + +/ +ALTER TRIGGER "BI_PAYREGISTER" ENABLE +/ +CREATE TABLE "TINSTALL" +( "ID" NUMBER, +"TMODEL" VARCHAR2(4000), +"TNO" VARCHAR2(4000), +"INSURANCE" VARCHAR2(4000), +"INAME" VARCHAR2(4000), +"MALIK" VARCHAR2(4000), +"TFROM" VARCHAR2(4000), +"TTO" VARCHAR2(4000), +"IDATE" DATE, +"MOBILE" NUMBER, +"STATUS" VARCHAR2(4000), +CONSTRAINT "TINSTALL_PK" PRIMARY KEY ("ID") ENABLE +) +/ + +CREATE OR REPLACE TRIGGER "BI_TINSTALL" +before insert on "TINSTALL" +for each row +begin +select "TINSTALL_SEQ".nextval into :NEW.ID from dual; +end; + +/ +ALTER TRIGGER "BI_TINSTALL" ENABLE +/ +CREATE TABLE "QUIZCONTACT" +( "NAME" VARCHAR2(4000), +"EMAIL" VARCHAR2(4000), +"PHONE" NUMBER NOT NULL ENABLE, +"MESSAGE" VARCHAR2(4000) +) +/ diff --git a/Transpose matrix b/Transpose matrix new file mode 100644 index 0000000..9fc09eb --- /dev/null +++ b/Transpose matrix @@ -0,0 +1,37 @@ +import java.util.Scanner; +class TransposeAMatrix +{ + public static void main(String args[]) + { + int m, n, c, d; + + Scanner in = new Scanner(System.in); + System.out.println("Enter the number of rows and columns of matrix"); + m = in.nextInt(); + n = in.nextInt(); + + int matrix[][] = new int[m][n]; + + System.out.println("Enter elements of the matrix"); + + for (c = 0; c < m; c++) + for (d = 0; d < n; d++) + matrix[c][d] = in.nextInt(); + + int transpose[][] = new int[n][m]; + + for (c = 0; c < m; c++) + for (d = 0; d < n; d++) + transpose[d][c] = matrix[c][d]; + + System.out.println("Transpose of the matrix:"); + + for (c = 0; c < n; c++) + { + for (d = 0; d < m; d++) + System.out.print(transpose[c][d]+"\t"); + + System.out.print("\n"); + } + } +} diff --git a/Tree Traversals (Inorder, Preorder and Postorder) b/Tree Traversals (Inorder, Preorder and Postorder) new file mode 100644 index 0000000..c4a944c --- /dev/null +++ b/Tree Traversals (Inorder, Preorder and Postorder) @@ -0,0 +1,100 @@ +// Java program for different tree traversals + +/* Class containing left and right child of current + node and key value*/ +class Node +{ + int key; + Node left, right; + + public Node(int item) + { + key = item; + left = right = null; + } +} + +class BinaryTree +{ + // Root of Binary Tree + Node root; + + BinaryTree() + { + root = null; + } + + /* Given a binary tree, print its nodes according to the + "bottom-up" postorder traversal. */ + void printPostorder(Node node) + { + if (node == null) + return; + + // first recur on left subtree + printPostorder(node.left); + + // then recur on right subtree + printPostorder(node.right); + + // now deal with the node + System.out.print(node.key + " "); + } + + /* Given a binary tree, print its nodes in inorder*/ + void printInorder(Node node) + { + if (node == null) + return; + + /* first recur on left child */ + printInorder(node.left); + + /* then print the data of node */ + System.out.print(node.key + " "); + + /* now recur on right child */ + printInorder(node.right); + } + + /* Given a binary tree, print its nodes in preorder*/ + void printPreorder(Node node) + { + if (node == null) + return; + + /* first print data of node */ + System.out.print(node.key + " "); + + /* then recur on left sutree */ + printPreorder(node.left); + + /* now recur on right subtree */ + printPreorder(node.right); + } + + // Wrappers over above recursive functions + void printPostorder() { printPostorder(root); } + void printInorder() { printInorder(root); } + void printPreorder() { printPreorder(root); } + + // Driver method + public static void main(String[] args) + { + BinaryTree tree = new BinaryTree(); + tree.root = new Node(1); + tree.root.left = new Node(2); + tree.root.right = new Node(3); + tree.root.left.left = new Node(4); + tree.root.left.right = new Node(5); + + System.out.println("Preorder traversal of binary tree is "); + tree.printPreorder(); + + System.out.println("\nInorder traversal of binary tree is "); + tree.printInorder(); + + System.out.println("\nPostorder traversal of binary tree is "); + tree.printPostorder(); + } +} diff --git a/Using Java print Armstrong no b/Using Java print Armstrong no new file mode 100644 index 0000000..b59c97f --- /dev/null +++ b/Using Java print Armstrong no @@ -0,0 +1,17 @@ +class ArmstrongExample{ + public static void main(String[] args) { + int c=0,a,temp; + int n=153;//It is the number to check armstrong + temp=n; + while(n>0) + { + a=n%10; + n=n/10; + c=c+(a*a*a); + } + if(temp==c) + System.out.println("armstrong number"); + else + System.out.println("Not armstrong number"); + } +} diff --git a/amstrong b/amstrong new file mode 100644 index 0000000..d98f2a1 --- /dev/null +++ b/amstrong @@ -0,0 +1,24 @@ +public class Armstrong { + + public static void main(String[] args) { + + int number = 1634, 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/ava Program for Odd-Even Sort b/ava Program for Odd-Even Sort new file mode 100644 index 0000000..2cd1743 --- /dev/null +++ b/ava Program for Odd-Even Sort @@ -0,0 +1,49 @@ +/ Java Program to implement +// Odd-Even / Brick Sort + +import java.io.*; + +class GFG { + public static void oddEvenSort(int arr[], int n) + { + boolean isSorted = false; // Initially array is unsorted + + while (!isSorted) { + isSorted = true; + int temp = 0; + + // Perform Bubble sort on odd indexed element + for (int i = 1; i <= n - 2; i = i + 2) { + if (arr[i] > arr[i + 1]) { + temp = arr[i]; + arr[i] = arr[i + 1]; + arr[i + 1] = temp; + isSorted = false; + } + } + + // Perform Bubble sort on even indexed element + for (int i = 0; i <= n - 2; i = i + 2) { + if (arr[i] > arr[i + 1]) { + temp = arr[i]; + arr[i] = arr[i + 1]; + arr[i + 1] = temp; + isSorted = false; + } + } + } + + return; + } + public static void main(String[] args) + { + int arr[] = { 34, 2, 10, -9 }; + int n = arr.length; + + oddEvenSort(arr, n); + for (int i = 0; i < n; i++) + System.out.print(arr[i] + " "); + + System.out.println(" "); + } +} diff --git a/banking-application b/banking-application new file mode 100644 index 0000000..6f08614 --- /dev/null +++ b/banking-application @@ -0,0 +1,69 @@ +class Account +{ + int accno,balance; + void chckbalance() + { + System.out.println("Your Balance is : "+balance); + } + void deposit(int value) + { + balance=balance+value; + System.out.println("Deposited successfully."); + } + void withdraw(int value) + { + if (value>balance) + { + System.out.println("Insufficient balance."); + } + else + { + balance=balance-value; + System.out.println("Withdrawl successfully."); + } + } +} +class Saving extends Account +{ + double interestrate; + Saving(double value) + { + interestrate=value; + } +} +class Current extends Account +{ + int overdraftlimit; + Current(int value) + { + overdraftlimit=value; + } + void withdraw(int value) + { + if (value>balance && value>overdraftlimit) + { + System.out.println("Insufficient balance."); + } + else + { + balance=balance-value; + System.out.println("Withdrawl successfully."); + } + } +} +public class p15 +{ + public static void main(String[] args) { + + Saving s=new Saving(2.5); + Current c=new Current(100); + s.deposit(500); + s.chckbalance(); + c.deposit(300); + c.chckbalance(); + s.withdraw(200); + s.chckbalance(); + c.withdraw(350); + c.chckbalance(); + } +} diff --git a/binary to decimal b/binary to decimal new file mode 100644 index 0000000..3d0ac8f --- /dev/null +++ b/binary to decimal @@ -0,0 +1,24 @@ +import java.util.*; + + // Compiler version JDK 11.0.2 + + class Dcoder + { + public static void main(String args[]) + { + Scanner sc=new Scanner(System.in); + int n,d,t,s=0,i=0; + System.out.println("Enter a binary number"); + n=sc.nextInt(); + t=n; + while(n>0) + { + d=n%10; + s=s+d*(int)Math.pow(2,i); + i++; + n=n/10; + } + System.out.println("Decimal number is"+" "+s); + System.out.println("Thank you,please leave a 🌟"); + } + } diff --git a/bubble sort b/bubble sort new file mode 100644 index 0000000..0abc2c2 --- /dev/null +++ b/bubble sort @@ -0,0 +1,33 @@ +import java.util.Scanner; +class BubbleSort { + public static void main(String []args) { + int n, c, d, swap; + Scanner in = new Scanner(System.in); + + System.out.println("Input number of integers to sort"); + n = in.nextInt(); + + int array[] = new int[n]; + + System.out.println("Enter " + n + " integers"); + + for (c = 0; c < n; c++) + array[c] = in.nextInt(); + + for (c = 0; c < ( n - 1 ); c++) { + for (d = 0; d < n - c - 1; d++) { + if (array[d] > array[d+1]) /* For descending order use < */ + { + swap = array[d]; + array[d] = array[d+1]; + array[d+1] = swap; + } + } + } + + System.out.println("Sorted list of numbers:"); + + for (c = 0; c < n; c++) + System.out.println(array[c]); + } +} diff --git a/calci_java b/calci_java new file mode 100644 index 0000000..8c28c18 --- /dev/null +++ b/calci_java @@ -0,0 +1,45 @@ +import java.util.Scanner; + +public class Calculator { + + public static void main(String[] args) { + + Scanner reader = new Scanner(System.in); + System.out.print("Enter two numbers: "); + + // nextDouble() reads the next double from the keyboard + double first = reader.nextDouble(); + double second = reader.nextDouble(); + + System.out.print("Enter an operator (+, -, *, /): "); + char operator = reader.next().charAt(0); + + double result; + + switch(operator) + { + case '+': + result = first + second; + break; + + case '-': + result = first - second; + break; + + case '*': + result = first * second; + break; + + case '/': + result = first / second; + break; + + // operator doesn't match any case constant (+, -, *, /) + default: + System.out.printf("Error! operator is not correct"); + return; + } + + System.out.printf("%.1f %c %.1f = %.1f", first, operator, second, result); + } +} diff --git a/calculator b/calculator new file mode 100644 index 0000000..1b6faad --- /dev/null +++ b/calculator @@ -0,0 +1,54 @@ +import java.util.Scanner; + +public class JavaExample { + + public static void main(String[] args) { + + double num1, num2; + Scanner scanner = new Scanner(System.in); + System.out.print("Enter first number:"); + + /* We are using data type double so that user + * can enter integer as well as floating point + * value + */ + num1 = scanner.nextDouble(); + System.out.print("Enter second number:"); + num2 = scanner.nextDouble(); + + System.out.print("Enter an operator (+, -, *, /): "); + char operator = scanner.next().charAt(0); + + scanner.close(); + double output; + + switch(operator) + { + case '+': + output = num1 + num2; + break; + + case '-': + output = num1 - num2; + break; + + case '*': + output = num1 * num2; + break; + + case '/': + output = num1 / num2; + break; + + /* If user enters any other operator or char apart from + * +, -, * and /, then display an error message to user + * + */ + default: + System.out.printf("You have entered wrong operator"); + return; + } + + System.out.println(num1+" "+operator+" "+num2+": "+output); + } +} diff --git a/cgpa calculator b/cgpa calculator new file mode 100644 index 0000000..d0b79a7 --- /dev/null +++ b/cgpa calculator @@ -0,0 +1,40 @@ +class CGPA +{ + public static void main(String arg[]) + { + int n=5; + + double m[]=new double[n]; + + double g[]=new double[n]; + + double cgpa,sum=0; + + m[0]=95; + + m[1]=85; + + m[2]=75; + + m[3]=80; + + m[4]=95; + + for(int i=0;i= num2 && num1 >= num3) + System.out.println(num1+" is the largest Number"); + + else if (num2 >= num1 && num2 >= num3) + System.out.println(num2+" is the largest Number"); + + else + System.out.println(num3+" is the largest Number"); + } +} diff --git a/concatwords b/concatwords new file mode 100644 index 0000000..4e8b9ea --- /dev/null +++ b/concatwords @@ -0,0 +1,50 @@ +class Solution { + + public boolean isSmallEnough(int i, int j, int len) { + return j-i+1 <= len; + } + + public void solve(String s, int i, int j, String words[], int wordsLen, int wordLen, List list) { + int len = wordsLen*wordLen; + if (j-i+1 == len) { + Map map = new HashMap(); + for(String word : words) { + if (map.containsKey(word)) map.put(word,map.get(word)+1); + else map.put(word,1); + } + boolean stop = false; + String word; + int index = i; + while (i <= j-wordLen+1 && !stop) { + word = s.substring(i,i+wordLen); + if (map.containsKey(word) && map.get(word) > 0) map.put(word,map.get(word)-1); + else stop = true; + i+=wordLen; + } + if (!stop) list.add(index); + } + } + + public void merge(String s, int i, int mid, int j, String words[], int wordsLen, int wordLen, List list) { + int len = wordsLen * wordLen; + int begin = mid - len + 2; + if (begin < i) begin = i; + for(; begin <= mid && j-begin+1 >= len; begin++) solve(s,begin,begin+len-1,words,wordsLen,wordLen,list); + } + + public void DYV(String s, int i, int j, String words[], int wordsLen, int wordLen, List list) { + if (isSmallEnough(i,j,wordsLen*wordLen)) solve(s,i,j,words,wordsLen,wordLen,list); + else { + int mid = (i+j)/2; + DYV(s,i,mid,words,wordsLen,wordLen,list); + DYV(s,mid+1,j,words,wordsLen,wordLen,list); + merge(s,i,mid,j,words,wordsLen,wordLen,list); + } + } + + public List findSubstring(String s, String[] words) { + List list = new LinkedList(); + DYV(s,0,s.length()-1,words,words.length,words[0].length(),list); + return list; + } +} diff --git a/constructor b/constructor new file mode 100644 index 0000000..3f1f34f --- /dev/null +++ b/constructor @@ -0,0 +1,15 @@ +class Main { + private int x; + + // constructor + private Main(){ + System.out.println("Constructor Called"); + x = 5; + } + + public static void main(String[] args){ + // constructor is called while creating object + Main obj = new Main(); + System.out.println("Value of x = " + obj.x); + } +} diff --git a/creatervikas b/creatervikas new file mode 100644 index 0000000..cd45760 --- /dev/null +++ b/creatervikas @@ -0,0 +1,27 @@ +#include + #include + void main() + { + + int n1,n2,sum; + clrscr(); + + printf("\nEnter 1st number : "); + scanf("%d",&n1); + + printf("\nEnter 2nd number : "); + scanf("%d",&n2); + + if(n1 > n2) + printf("\n1st number is greatest."); + else + printf("\n2nd number is greatest."); + + getch(); + } + + Output : + + Enter 1st number : 115 + Enter 2nd number : 228 + 2nd number is greatest. diff --git a/decimaltobinary b/decimaltobinary new file mode 100644 index 0000000..0c397f1 --- /dev/null +++ b/decimaltobinary @@ -0,0 +1,34 @@ +// Java program to convert a decimal +// number to binary number +import java.io.*; + +class GFG { + // function to convert decimal to binary + static void decToBinary(int n) + { + // array to store binary number + int[] binaryNum = new int[32]; + + // counter for binary array + int i = 0; + while (n > 0) { + // storing remainder in binary array + binaryNum[i] = n % 2; + n = n / 2; + i++; + } + + // printing binary array in reverse order + for (int j = i - 1; j >= 0; j--) + System.out.print(binaryNum[j]); + } + + // driver program + public static void main(String[] args) + { + int n = 17; + decToBinary(n); + } +} + +// Contributed by niken diff --git a/display the prime numbers between 1 and 100. b/display the prime numbers between 1 and 100. new file mode 100644 index 0000000..d31ae0a --- /dev/null +++ b/display the prime numbers between 1 and 100. @@ -0,0 +1,29 @@ +class PrimeNumbers +{ + public static void main (String[] args) + { + int i =0; + int num =0; + //Empty String + String primeNumbers = ""; + + for (i = 1; i <= 100; i++) + { + int counter=0; + for(num =i; num>=1; num--) + { + if(i%num==0) + { + counter = counter + 1; + } + } + if (counter ==2) + { + //Appended the Prime number to the String + primeNumbers = primeNumbers + i + " "; + } + } + System.out.println("Prime numbers from 1 to 100 are :"); + System.out.println(primeNumbers); + } +} diff --git a/divsionoftwonumbersinjava b/divsionoftwonumbersinjava new file mode 100644 index 0000000..ede9f0b --- /dev/null +++ b/divsionoftwonumbersinjava @@ -0,0 +1,15 @@ +import java.util.Scanner; + +public class Main { + public static void main(String[] args) + { + Scanner input = new Scanner (System.in); + System.out.print("Input the first number: "); + int a = input.nextInt(); + System.out.print("Input the second number: "); + int b = input.nextInt(); + int d = (a/b); + System.out.println(); + System.out.println("The division of a and b is:" +d); + } +} diff --git a/duplicate b/duplicate new file mode 100644 index 0000000..c39cea8 --- /dev/null +++ b/duplicate @@ -0,0 +1,45 @@ +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + public class Details { + public void countDupChars(String str){ + + + Map map = new HashMap(); + + char[] chars = str.toCharArray(); + + + for(Character ch:chars){ + if(map.containsKey(ch)){ + map.put(ch, map.get(ch)+1); + } else { + map.put(ch, 1); + } + } + + + Set keys = map.keySet(); + + for(Character ch:keys){ + if(map.get(ch) > 1){ + System.out.println("Char "+ch+" "+map.get(ch)); + } + } + } + + public static void main(String a[]){ + Details obj = new Details(); + System.out.println("String: BeginnersBook.com"); + System.out.println("-------------------------"); + obj.countDupChars("BeginnersBook.com"); + + System.out.println("\nString: ChaitanyaSingh"); + System.out.println("-------------------------"); + obj.countDupChars("ChaitanyaSingh"); + + System.out.println("\nString: #@$@!#$%!!%@"); + System.out.println("-------------------------"); + obj.countDupChars("#@$@!#$%!!%@"); + } +} diff --git a/encapsulation in java b/encapsulation in java new file mode 100644 index 0000000..2e76b86 --- /dev/null +++ b/encapsulation in java @@ -0,0 +1,25 @@ +class Employee{ +private String name; +private int emp_id; +public String Name(){ +return name; +} +public int Emp_id(){ +return emp_id; +} +public void Emp_id(int emp_id){ +this.emp_id=emp_id; +} +public void Name(String name){ +this.name=name; +} +} +class Test1{ +public static void main(String[] args){ +Employee employee = new Employee(); +employee.Name("vinay"); +employee.Emp_id(100); +System.out.println("Name "+employee.Name()); +System.out.println("Id "+employee.Emp_id()); +} +} diff --git a/evenorodd.java b/evenorodd.java new file mode 100644 index 0000000..4069ebd --- /dev/null +++ b/evenorodd.java @@ -0,0 +1,17 @@ +import java.util.Scanner; + +public class EvenOdd { + + public static void main(String[] args) { + + Scanner reader = new Scanner(System.in); + + System.out.print("Enter a number: "); + int num = reader.nextInt(); + + if(num % 2 == 0) + System.out.println(num + " is even"); + else + System.out.println(num + " is odd"); + } +} diff --git a/factorial of input number using while loop b/factorial of input number using while loop new file mode 100644 index 0000000..cdf33d5 --- /dev/null +++ b/factorial of input number using while loop @@ -0,0 +1,21 @@ +import java.util.Scanner; +public class JavaExample { + + public static void main(String[] args) { + + //We will find the factorial of this number + int number; + System.out.println("Enter the number: "); + Scanner scanner = new Scanner(System.in); + number = scanner.nextInt(); + scanner.close(); + long fact = 1; + int i = 1; + while(i<=number) + { + fact = fact * i; + i++; + } + System.out.println("Factorial of "+number+" is: "+fact); + } +} diff --git a/factorialno b/factorialno new file mode 100644 index 0000000..99bb0fa --- /dev/null +++ b/factorialno @@ -0,0 +1,24 @@ +package Edureka; +import java.util.Scanner; +public class Factorial { +public static void main(String args[]){ +//Scanner object for capturing the user input +Scanner scanner = new Scanner(System.in); +System.out.println("Enter the number:"); +//Stored the entered value in variable +int num = scanner.nextInt(); +//Called the user defined function fact +int factorial = fact(num); +System.out.println("Factorial of entered number is: "+factorial); +} +static int fact(int n) +{ +int output; +if(n==1){ +return 1; +} +//Recursion: Function calling itself!! +output = fact(n-1)* n; +return output; +} +} diff --git a/fibonacci b/fibonacci new file mode 100644 index 0000000..76f5bd9 --- /dev/null +++ b/fibonacci @@ -0,0 +1,15 @@ +class FibonacciExample1{ +public static void main(String args[]) +{ + int n1=0,n2=1,n3,i,count=10; + System.out.print(n1+" "+n2);//printing 0 and 1 + + for(i=2;i 1 && string[i] != '0') + System.out.println(string[i]); + } + } +} diff --git a/findGcd b/findGcd new file mode 100644 index 0000000..40f7310 --- /dev/null +++ b/findGcd @@ -0,0 +1,16 @@ +public class Gcd { + + public static void main(String[] args) { + + int n1 = 81, n2 = 153, gcd = 1; + + for(int i = 1; i <= n1 && i <= n2; ++i) + { + // Checks if i is factor of both integers + if(n1 % i==0 && n2 % i==0) + gcd = i; + } + + System.out.printf("G.C.D of %d and %d is %d", n1, n2, gcd); + } +} diff --git a/floyd Triangle b/floyd Triangle new file mode 100644 index 0000000..9961d34 --- /dev/null +++ b/floyd Triangle @@ -0,0 +1,26 @@ +import java.util.Scanner; + +class FloydTriangle +{ + public static void main(String args[]) + { + int n, num = 1, c, d; + Scanner in = new Scanner(System.in); + + System.out.println("Enter the number of rows of Floyd's triangle to display"); + n = in.nextInt(); + + System.out.println("Floyd's triangle:"); + + for (c = 1; c <= n; c++) + { + for (d = 1; d <= c; d++) + { + System.out.print(num+" "); + num++; + } + + System.out.println(); // Moving to next row + } + } +} diff --git a/greatest of two numbers b/greatest of two numbers new file mode 100644 index 0000000..21dbe0f --- /dev/null +++ b/greatest of two numbers @@ -0,0 +1,18 @@ +// C program to find the greatest of two numbers + +#include +int main() +{ +//Fill the code +int num1, num2; +scanf(“%d %d”,&num1,&num2); +if(num1 > num2) +{ +printf(“%d is greater”,num1); +} +else +{ +printf(“%d is greater”,num2); +} +return 0; +} diff --git a/greatest2nojav b/greatest2nojav new file mode 100644 index 0000000..f74aeda --- /dev/null +++ b/greatest2nojav @@ -0,0 +1,30 @@ +/ Java Program to Find largest of Two Numbers +import java.util.Scanner; + +public class LargestofTwo { + private static Scanner sc; + public static void main(String[] args) + { + int number1, number2; + sc = new Scanner(System.in); + + System.out.print(" Please Enter the First Number : "); + number1 = sc.nextInt(); + + System.out.print(" Please Enter the Second Number : "); + number2 = sc.nextInt(); + + if(number1 > number2) + { + System.out.println("\n The Largest Number = " + number1); + } + else if (number2 > number1) + { + System.out.println("\n The Largest Number = " + number2); + } + else + { + System.out.println("\n Both are Equal"); + } + } +} diff --git a/greatnocheck b/greatnocheck new file mode 100644 index 0000000..0832d4e --- /dev/null +++ b/greatnocheck @@ -0,0 +1,37 @@ +Java Program to Find largest of Two Numbers +Write a Java program to find the largest of two numbers using Else If Statement and Conditional Operator. + + +Java Program to Find largest of Two Numbers using Else If +This Java program allows the user to enter two different values. Next, this Java program finds the largest number among those two numbers using Else If Statement + +// Java Program to Find largest of Two Numbers +import java.util.Scanner; + +public class LargestofTwo { + private static Scanner sc; + public static void main(String[] args) + { + int number1, number2; + sc = new Scanner(System.in); + + System.out.print(" Please Enter the First Number : "); + number1 = sc.nextInt(); + + System.out.print(" Please Enter the Second Number : "); + number2 = sc.nextInt(); + + if(number1 > number2) + { + System.out.println("\n The Largest Number = " + number1); + } + else if (number2 > number1) + { + System.out.println("\n The Largest Number = " + number2); + } + else + { + System.out.println("\n Both are Equal"); + } + } +} diff --git a/happynumber b/happynumber new file mode 100644 index 0000000..46f223a --- /dev/null +++ b/happynumber @@ -0,0 +1,42 @@ +class Happy +{ +static int numSquareSum(int n) +{ + int squareSum = 0; + while (n!= 0) + { + squareSum += (n % 10) * (n % 10); + n /= 10; + } + return squareSum; +} + +// method return true if n is Happy number +static boolean isHappynumber(int n) +{ + int slow, fast; + slow = fast = n; + do + { + slow = numSquareSum(slow); + + fast = numSquareSum(numSquareSum(fast)); + + } + while (slow != fast); + + + return (slow == 1); +} + +public static void main(String[] args) +{ + int n = 13; + if (isHappynumber(n)) + System.out.println(n + + " is a Happy number"); + else + System.out.println(n + + " is not a Happy number"); +} +} diff --git a/index.css b/index.css new file mode 100644 index 0000000..6647b89 --- /dev/null +++ b/index.css @@ -0,0 +1,15 @@ + + + + + + Document + + + +
+ + +
+ + diff --git a/inheritence b/inheritence new file mode 100644 index 0000000..0c56947 --- /dev/null +++ b/inheritence @@ -0,0 +1,43 @@ +package Inheritance; + +class SuperClass { + int i, j; + + void showij() { + System.out.println("i and j: " + i + " " + j); + } +} + +class SubClass extends SuperClass { + int k; + + void showk() { + System.out.println("k:" + k); + } + + void sum() { + System.out.println(i + j + k); + } + +} + +class InheritEx { + public static void main(String args[]) { + SuperClass sup = new SuperClass(); + SubClass sub = new SubClass(); + + sup.i = 10; + sup.j = 20; + System.out.println("Contents of super class "); + sup.showij(); + sub.i = 7; + sub.j = 8; + sub.k = 9; + System.out.println("Contents of sub class"); + sub.showij(); + sub.showk(); + System.out.println("Sum of i, j and k in sub class"); + sub.sum(); + } +} +© 2020 GitHub, Inc. diff --git a/intro b/intro new file mode 100644 index 0000000..4d326ea --- /dev/null +++ b/intro @@ -0,0 +1,3 @@ + diff --git a/java b/java new file mode 100644 index 0000000..d7c80d4 --- /dev/null +++ b/java @@ -0,0 +1,16 @@ +public class JavaExample{ + + public static void main(String[] args) { + + int num1 = 10, num2 = 20, num3 = 7; + + if( num1 >= num2 && num1 >= num3) + System.out.println(num1+" is the largest Number"); + + else if (num2 >= num1 && num2 >= num3) + System.out.println(num2+" is the largest Number"); + + else + System.out.println(num3+" is the largest Number"); + } +} diff --git a/java array b/java array new file mode 100644 index 0000000..1b4cba3 --- /dev/null +++ b/java array @@ -0,0 +1,11 @@ +public class OddPosition { + public static void main(String[] args) { + //Initialize array + int [] arr = new int [] {1, 2, 3, 4, 5}; + System.out.println("Elements of given array present on odd position: "); + //Loop through the array by incrementing value of i by 2 + for (int i = 0; i < arr.length; i = i+2) { + System.out.println(arr[i]); + } + } +} diff --git a/java code to convert video to audio b/java code to convert video to audio new file mode 100644 index 0000000..0a6adc2 --- /dev/null +++ b/java code to convert video to audio @@ -0,0 +1,17 @@ + +import com.xuggle.mediatool.IMediaReader; +import com.xuggle.mediatool.IMediaWriter; +import com.xuggle.mediatool.ToolFactory; +import com.xuggle.xuggler.ICodec; + +public class convert { +public static void main(String args[]){ +IMediaReader reader = ToolFactory.makeReader("F:/input.mkv"); +IMediaWriter writer = ToolFactory.makeWriter("F:/output.mp3", reader); +int sampleRate = 44100; +int channels = 1; +writer.addAudioStream(0, 0, ICodec.ID.CODEC_ID_MP3, channels, sampleRate); +while (reader.readPacket() == null); + +} +} diff --git a/java multilevel inheritance b/java multilevel inheritance new file mode 100644 index 0000000..0bb4692 --- /dev/null +++ b/java multilevel inheritance @@ -0,0 +1,27 @@ +class calculator{ +void add(int a,int b){ +System.out.println("a+b = "+(a+b)); +} +void sub(int a,int b){ +System.out.println("a-b = "+(a-b)); +} +} +class advancecalculator extends calculator{//sub class +void mult(int a,int b){ +System.out.println("a*b = "+(a*b)); +} +} +class scientificcalculator extends advancecalculator{ +void div(int a,int b){ +System.out.println("a/b = "+(a/b)); +} +} +class maincalculator{ +public static void main(String[] args){ +scientificcalculator cal = new scientificcalculator(); +cal.add(12,23); +cal.sub(45,12); +cal.mult(12,9); +cal.div(12,3); +} +} diff --git a/java program to check palindrome string using recursion b/java program to check palindrome string using recursion new file mode 100644 index 0000000..361f6ed --- /dev/null +++ b/java program to check palindrome string using recursion @@ -0,0 +1,39 @@ +package beginnersbook.com; +import java.util.Scanner; +class PalindromeCheck +{ + //My Method to check + public static boolean isPal(String s) + { // if length is 0 or 1 then String is palindrome + if(s.length() == 0 || s.length() == 1) + return true; + if(s.charAt(0) == s.charAt(s.length()-1)) + /* check for first and last char of String: + * if they are same then do the same thing for a substring + * with first and last char removed. and carry on this + * until you string completes or condition fails + * Function calling itself: Recursion + */ + return isPal(s.substring(1, s.length()-1)); + + /* If program control reaches to this statement it means + * the String is not palindrome hence return false. + */ + return false; + } + + public static void main(String[]args) + { + //For capturing user input + Scanner scanner = new Scanner(System.in); + System.out.println("Enter the String for check:"); + String string = scanner.nextLine(); + /* If function returns true then the string is + * palindrome else not + */ + if(isPal(string)) + System.out.println(string + " is a palindrome"); + else + System.out.println(string + " is not a palindrome"); + } +} diff --git a/javaprogram b/javaprogram new file mode 100644 index 0000000..dbdbc76 --- /dev/null +++ b/javaprogram @@ -0,0 +1,19 @@ +import java.util.*; +class ReverseString +{ + public static void main(String args[]) + { + String original, reverse = ""; + Scanner in = new Scanner(System.in); + + System.out.println("Enter a string to reverse"); + original = in.nextLine(); + + int length = original.length(); + + for (int i = length - 1 ; i >= 0 ; i--) + reverse = reverse + original.charAt(i); + + System.out.println("Reverse of the string: " + reverse); + } +} diff --git a/javaprogramforcompundinterest b/javaprogramforcompundinterest new file mode 100644 index 0000000..759e596 --- /dev/null +++ b/javaprogramforcompundinterest @@ -0,0 +1,13 @@ +public class JavaExample { + + public void calculate(int p, int t, double r, int n) { + double amount = p * Math.pow(1 + (r / n), n * t); + double cinterest = amount - p; + System.out.println("Compound Interest after " + t + " years: "+cinterest); + System.out.println("Amount after " + t + " years: "+amount); + } + public static void main(String args[]) { + JavaExample obj = new JavaExample(); + obj.calculate(2000, 5, .08, 12); + } +} diff --git a/lcm b/lcm new file mode 100644 index 0000000..651dbf2 --- /dev/null +++ b/lcm @@ -0,0 +1,30 @@ +class Lcm +{ + public static void main(String arg[]) + { + long a,b,lcm; + Scanner sc=new Scanner(System.in); + System.out.println("enter number 1"); + a=sc.nextLong(); + System.out.println("enter number 2"); + b=sc.nextLong(); + lcm=lcmCalculation(a,b); + System.out.println("LCM of "+a+" and "+b+" is ="+lcm); + } + static long lcmCalculation(long n1,long n2) + { + long temp,i=2,res; + if(n1>n2) + res=n1; + else + res=n2; + temp=res; + while(res%n1!=0 || res%n2!=0) + { + res=temp*i; + i++; + } + return res; + + } +} diff --git a/leap year b/leap year new file mode 100644 index 0000000..921800c --- /dev/null +++ b/leap year @@ -0,0 +1,32 @@ + Java program to check +// for a leap year + +class Test +{ + static boolean checkYear(int year) + { + // If a year is multiple of 400, + // then it is a leap year + if (year % 400 == 0) + return true; + + // Else If a year is muliplt of 100, + // then it is not a leap year + if (year % 100 == 0) + return false; + + // Else If a year is muliplt of 4, + // then it is a leap year + if (year % 4 == 0) + return true; + return false; + } + + // Driver method + public static void main(String[] args) + { + int year = 2000; + System.out.println( checkYear(2000)? "Leap Year" : + "Not a Leap Year" ); + } +} diff --git a/max b/max new file mode 100644 index 0000000..d7c80d4 --- /dev/null +++ b/max @@ -0,0 +1,16 @@ +public class JavaExample{ + + public static void main(String[] args) { + + int num1 = 10, num2 = 20, num3 = 7; + + if( num1 >= num2 && num1 >= num3) + System.out.println(num1+" is the largest Number"); + + else if (num2 >= num1 && num2 >= num3) + System.out.println(num2+" is the largest Number"); + + else + System.out.println(num3+" is the largest Number"); + } +} diff --git a/maxmum number b/maxmum number new file mode 100644 index 0000000..402a4e3 --- /dev/null +++ b/maxmum number @@ -0,0 +1,22 @@ +function digit_delete(num) { + var result = 0, + num_digits = []; + while (num) { + num_digits.push(num % 10); + num = Math.floor(num / 10); + } + for (var index_num = 0; index_num < num_digits.length; index_num++) { + var n = 0; + for (var i = num_digits.length - 1; i >= 0; i--) { + if (i !== index_num) { + n = n * 10 + num_digits[i]; + } + } + result = Math.max(n, result); + } + return result; +} + +console.log(digit_delete(100)); +console.log(digit_delete(10)); +console.log(digit_delete(1245)); diff --git a/middle_linkedlist b/middle_linkedlist new file mode 100644 index 0000000..f6cd9b9 --- /dev/null +++ b/middle_linkedlist @@ -0,0 +1,74 @@ +public class LinkedList{ + + private Node head; + + private static class Node { + private int value; + private Node next; + + Node(int value) { + this.value = value; + + } + } + + public void addToTheLast(Node node) { + + if (head == null) { + head = node; + } else { + Node temp = head; + while (temp.next != null) + temp = temp.next; + + temp.next = node; + } + } + + + public void printList() { + Node temp = head; + while (temp != null) { + System.out.format("%d ", temp.value); + temp = temp.next; + } + System.out.println(); + } + + // This function will find middle element in linkedlist + public Node findMiddleNode(Node head) + { + Node slowPointer, fastPointer; + slowPointer = fastPointer = head; + + while(fastPointer !=null) { + fastPointer = fastPointer.next; + if(fastPointer != null && fastPointer.next != null) { + slowPointer = slowPointer.next; + fastPointer = fastPointer.next; + } + } + + return slowPointer; + + } + + public static void main(String[] args) { + LinkedList list = new LinkedList(); + // Creating a linked list + Node head=new Node(5); + list.addToTheLast(head); + list.addToTheLast(new Node(6)); + list.addToTheLast(new Node(7)); + list.addToTheLast(new Node(1)); + list.addToTheLast(new Node(2)); + + list.printList(); + // finding middle element + Node middle= list.findMiddleNode(head); + System.out.println("Middle node will be: "+ middle.value); + + } + +} + diff --git a/miles to kilometers b/miles to kilometers new file mode 100644 index 0000000..e2275e2 --- /dev/null +++ b/miles to kilometers @@ -0,0 +1,27 @@ +import java.util.Scanner; + +public class DistanceConverter { + public static void main(String[] args) { + System.out.print("Enter distance in miles:"); + Scanner s = new Scanner(System.in); + + double distanceInMiles = s.nextDouble(); + + System.out.println(distanceInMiles + " miles = " + milesTokm(distanceInMiles) + " km"); + + System.out.print("Enter distance in km:"); + double distanceInKm = s.nextDouble(); + + System.out.println(distanceInKm + " km = " + kmTomiles(distanceInKm) + " miles"); + s.close(); + + } + + private static double milesTokm(double distanceInMiles) { + return distanceInMiles * 1.60934; + } + + private static double kmTomiles(double distanceInKm) { + return distanceInKm * 0.621371; + } +} diff --git a/mutiplication table b/mutiplication table new file mode 100644 index 0000000..4666c1b --- /dev/null +++ b/mutiplication table @@ -0,0 +1,14 @@ +import java.util.Scanner; +public class Multiplication_Table +{ + public static void main(String[] args) + { + Scanner s = new Scanner(System.in); + System.out.print("Enter number:"); + int n=s.nextInt(); + for(int i=1; i <= 10; i++) + { + System.out.println(n+" * "+i+" = "+n*i); + } + } +} diff --git a/neon-number b/neon-number new file mode 100644 index 0000000..b38887d --- /dev/null +++ b/neon-number @@ -0,0 +1,22 @@ +public class Neon +{ +public static void main(String args[]) +{ +Scanner sc=new Scanner(System.in); +System.out.println("enter a number to check for neon "); +int a=sc.nextInt(); +int s=a*a; +int d=0; +int q=0; +while(s>0) +{ +q=s%10; +d=d+q; +s=s/10; +} +if(d==a) +System.out.println("entered number is a neon number "); +else +System.out.println("Number you have entered is not a Neon Number"); +} +} diff --git a/new.java b/new.java new file mode 100644 index 0000000..e1a0fdb --- /dev/null +++ b/new.java @@ -0,0 +1,5 @@ +class HelloWorld { + public static void main(String[] args) { + System.out.println("Hello, World!"); + } +} diff --git a/niven.java b/niven.java new file mode 100644 index 0000000..7fce452 --- /dev/null +++ b/niven.java @@ -0,0 +1,20 @@ +import java.lang.*; +import java.util.Scanner; + class niven +{public static void main(String args[]) + { Scanner in=new Scanner(System.in); + System.out.println("Enter number"); + int n=in.nextInt(); +int s=0,t=n; + while(n!=0) + { int r=n%10; + n=n/10; + s=s+r; + } + if((t%s)==0) + System.out.println("niven number"); +else +System.out.println("number is not niven"); + + } +} diff --git a/oddEven b/oddEven new file mode 100644 index 0000000..4069ebd --- /dev/null +++ b/oddEven @@ -0,0 +1,17 @@ +import java.util.Scanner; + +public class EvenOdd { + + public static void main(String[] args) { + + Scanner reader = new Scanner(System.in); + + System.out.print("Enter a number: "); + int num = reader.nextInt(); + + if(num % 2 == 0) + System.out.println(num + " is even"); + else + System.out.println(num + " is odd"); + } +} diff --git a/palindrome b/palindrome new file mode 100644 index 0000000..b49b094 --- /dev/null +++ b/palindrome @@ -0,0 +1,40 @@ +// Java implementation of the approach +public class GFG { + + // Function that returns true if + // str is a palindrome + static boolean isPalindrome(String str) + { + + // Pointers pointing to the beginning + // and the end of the string + int i = 0, j = str.length() - 1; + + // While there are characters toc compare + while (i < j) { + + // If there is a mismatch + if (str.charAt(i) != str.charAt(j)) + return false; + + // Increment first pointer and + // decrement the other + i++; + j--; + } + + // Given string is a palindrome + return true; + } + + // Driver code + public static void main(String[] args) + { + String str = "geeks"; + + if (isPalindrome(str)) + System.out.print("Yes"); + else + System.out.print("No"); + } +} diff --git a/palindrome.java b/palindrome.java new file mode 100644 index 0000000..caea919 --- /dev/null +++ b/palindrome.java @@ -0,0 +1,22 @@ +public class pattern9 +{ +public static void main(String args[]) +{ + int n=121,rem,store=0; + int b=n; + while(n!=0) + { + rem=n%10; + store=store*10+rem; + n=n/10; + } + if(b==store) + { + System.out.println("It is a palindrome number"); + } + else + { + System.out.println("It is not a palindrome number"); + } +} +} diff --git a/pancake sorting b/pancake sorting new file mode 100644 index 0000000..ec6134c --- /dev/null +++ b/pancake sorting @@ -0,0 +1,89 @@ +// Java program to +// sort array using +// pancake sort +import java.io.*; + +class PancakeSort { + + /* Reverses arr[0..i] */ + static void flip(int arr[], int i) + { + int temp, start = 0; + while (start < i) + { + temp = arr[start]; + arr[start] = arr[i]; + arr[i] = temp; + start++; + i--; + } + } + + // Returns index of the + // maximum element in + // arr[0..n-1] + static int findMax(int arr[], int n) + { + int mi, i; + for (mi = 0, i = 0; i < n; ++i) + if (arr[i] > arr[mi]) + mi = i; + return mi; + } + + // The main function that + // sorts given array using + // flip operations + static int pancakeSort(int arr[], int n) + { + // Start from the complete + // array and one by one + // reduce current size by one + for (int curr_size = n; curr_size > 1; --curr_size) + { + // Find index of the + // maximum element in + // arr[0..curr_size-1] + int mi = findMax(arr, curr_size); + + // Move the maximum element + // to end of current array + // if it's not already at + // the end + if (mi != curr_size-1) + { + // To move at the end, + // first move maximum + // number to beginning + flip(arr, mi); + + // Now move the maximum + // number to end by + // reversing current array + flip(arr, curr_size-1); + } + } + return 0; + } + + /* Utility function to print array arr[] */ + static void printArray(int arr[], int arr_size) + { + for (int i = 0; i < arr_size; i++) + System.out.print(arr[i] + " "); + System.out.println(""); + } + + /* Driver function to check for above functions*/ + public static void main (String[] args) + { + int arr[] = {23, 10, 20, 11, 12, 6, 7}; + int n = arr.length; + + pancakeSort(arr, n); + + System.out.println("Sorted Array: "); + printArray(arr, n); + } +} +/* This code is contributed by Pritam Singha Roy*/ diff --git a/pattern b/pattern new file mode 100644 index 0000000..d1f47ab --- /dev/null +++ b/pattern @@ -0,0 +1,25 @@ + class pattern +{ +public static void main(String args[]) +{int i,j,l; +for(i=1;i<=4;i++) +{ +for(j=1;j=65;l--) +{ +System.out.print((char)(l)); +} +System.out.print("\n"); +} +} +} + + + diff --git a/pme b/pme new file mode 100644 index 0000000..0a8e648 --- /dev/null +++ b/pme @@ -0,0 +1,29 @@ +import java.util.Scanner; + +import java.util.Scanner; + +public class PrimeExample3 { + + public static void main(String[] args) { + Scanner s = new Scanner(System.in); + System.out.print("Enter a number : "); + int n = s.nextInt(); + if (isPrime(n)) { + System.out.println(n + " is a prime number"); + } else { + System.out.println(n + " is not a prime number"); + } + } + + public static boolean isPrime(int n) { + if (n <= 1) { + return false; + } + for (int i = 2; i < Math.sqrt(n); i++) { + if (n % i == 0) { + return false; + } + } + return true; + } +} diff --git a/prime number 1 to 100 b/prime number 1 to 100 new file mode 100644 index 0000000..4b9cbe4 --- /dev/null +++ b/prime number 1 to 100 @@ -0,0 +1,37 @@ +public class primeNumbersFoundber { + + public static void main(String[] args) { + + int i; + int num = 0; + int maxCheck = 100; // maxCheck limit till which you want to find prime numbers + boolean isPrime = true; + + //Empty String + String primeNumbersFound = ""; + + //Start loop 1 to maxCheck + for (i = 1; i <= maxCheck; i++) { + isPrime = CheckPrime(i); + if (isPrime) { + primeNumbersFound = primeNumbersFound + i + " "; + } + } + System.out.println("Prime numbers from 1 to " + maxCheck + " are:"); + // Print prime numbers from 1 to maxCheck + System.out.println(primeNumbersFound); + } + public static boolean CheckPrime(int numberToCheck) { + int remainder; + for (int i = 2; i <= numberToCheck / 2; i++) { + remainder = numberToCheck % i; + //if remainder is 0 than numberToCheckber is not prime and break loop. Elese continue loop + if (remainder == 0) { + return false; + } + } + return true; + + } + +} diff --git a/prime or not b/prime or not new file mode 100644 index 0000000..f7f0b9e --- /dev/null +++ b/prime or not @@ -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/print1to10number b/print1to10number new file mode 100644 index 0000000..88fec90 --- /dev/null +++ b/print1to10number @@ -0,0 +1,3 @@ +for (var input = 1; input <= 10; input++) { + console.log(input); +} diff --git a/program to find a maximum and minimum occuring character in string b/program to find a maximum and minimum occuring character in string new file mode 100644 index 0000000..5baaaf9 --- /dev/null +++ b/program to find a maximum and minimum occuring character in string @@ -0,0 +1,46 @@ +public class Characters +{ + public static void main(String[] args) { + String str = "grass is greener on the other side"; + int[] freq = new int[str.length()]; + char minChar = str.charAt(0), maxChar = str.charAt(0); + int i, j, min, max; + + //Converts given string into character array + char string[] = str.toCharArray(); + + //Count each word in given string and store in array freq + for(i = 0; i < string.length; i++) { + freq[i] = 1; + for(j = i+1; j < string.length; j++) { + if(string[i] == string[j] && string[i] != ' ' && string[i] != '0') { + freq[i]++; + + //Set string[j] to 0 to avoid printing visited character + string[j] = '0'; + } + } + } + + //Determine minimum and maximum occurring characters + min = max = freq[0]; + for(i = 0; i freq[i] && freq[i] != '0') { + min = freq[i]; + minChar = string[i]; + } + //If max is less than frequency of a character + //then, store frequency in max and corresponding character in maxChar + if(max < freq[i]) { + max = freq[i]; + maxChar = string[i]; + } + } + + System.out.println("Minimum occurring character: " + minChar); + System.out.println("Maximum occurring character: " + maxChar); + } +} diff --git a/program to rotate an array by d element b/program to rotate an array by d element new file mode 100644 index 0000000..66461a7 --- /dev/null +++ b/program to rotate an array by d element @@ -0,0 +1,52 @@ + +class RotateArray { + + void leftRotate(int arr[], int d, int n) + { + /* To handle if d >= n */ + d = d % n; + int i, j, k, temp; + int g_c_d = gcd(d, n); + for (i = 0; i < g_c_d; i++) { + /* move i-th values of blocks */ + temp = arr[i]; + j = i; + while (true) { + k = j + d; + if (k >= n) + k = k - n; + if (k == i) + break; + arr[j] = arr[k]; + j = k; + } + arr[j] = temp; + } + } + + + + + void printArray(int arr[], int size) + { + int i; + for (i = 0; i < size; i++) + System.out.print(arr[i] + " "); + } + + int gcd(int a, int b) + { + if (b == 0) + return a; + else + return gcd(b, a % b); + } + + public static void main(String[] args) + { + RotateArray rotate = new RotateArray(); + int arr[] = { 1, 2, 3, 4, 5, 6, 7 }; + rotate.leftRotate(arr, 2, 7); + rotate.printArray(arr, 7); + } +} diff --git a/reverse string b/reverse string new file mode 100644 index 0000000..97b2367 --- /dev/null +++ b/reverse string @@ -0,0 +1,24 @@ +import java.lang.*; +import java.io.*; +import java.util.*; + +// Class of ReverseString +class ReverseString { + public static void main(String[] args) + { + String input = "GeeksforGeeks"; + + // getBytes() method to convert string + // into bytes[]. + byte[] strAsByteArray = input.getBytes(); + + byte[] result = new byte[strAsByteArray.length]; + + // Store result in reverse order into the + // result byte[] + for (int i = 0; i < strAsByteArray.length; i++) + result[i] = strAsByteArray[strAsByteArray.length - i - 1]; + + System.out.println(new String(result)); + } +} diff --git a/reversing a string b/reversing a string new file mode 100644 index 0000000..dbdbc76 --- /dev/null +++ b/reversing a string @@ -0,0 +1,19 @@ +import java.util.*; +class ReverseString +{ + public static void main(String args[]) + { + String original, reverse = ""; + Scanner in = new Scanner(System.in); + + System.out.println("Enter a string to reverse"); + original = in.nextLine(); + + int length = original.length(); + + for (int i = length - 1 ; i >= 0 ; i--) + reverse = reverse + original.charAt(i); + + System.out.println("Reverse of the string: " + reverse); + } +} diff --git a/sakilhasanssaikat b/sakilhasanssaikat new file mode 100644 index 0000000..e7a7665 --- /dev/null +++ b/sakilhasanssaikat @@ -0,0 +1,7 @@ +

Click me to change my text color.

+ + diff --git a/search function b/search function new file mode 100644 index 0000000..4a9dae9 --- /dev/null +++ b/search function @@ -0,0 +1,36 @@ +function search(searchString) { + //we test if searchString is empty in that case we just return the original data + if (typeof searchString !== 'string' || searchString.length === 0) { + return bands; + } + + //we make search string lower case + let searchLower = searchString.toLowerCase(); + let filtered = bands.filter(band => { + if (band.name.toLowerCase().includes(searchLower)) { + return true; + } + + if (band.description.toLowerCase().includes(searchLower)) { + return true; + } + + //now we search in albums as well; we store values in an array + let filteredAlbums = band.albums.filter(album => { + if (album.name.toLowerCase().includes(searchLower)) { + return true; //this is a return for albums + } + + return false; //this is a return for albums + }); + + if (filteredAlbums.length > 0) { + return true; + } + + + return false; + }) + + return filtered; +} diff --git a/selection sort b/selection sort new file mode 100644 index 0000000..7f29d8f --- /dev/null +++ b/selection sort @@ -0,0 +1,40 @@ +class SelectionSort +{ + void sort(int arr[]) + { + int n = arr.length; + for (int i = 0; i < n-1; i++) + { + + int min_idx = i; + for (int j = i+1; j < n; j++) + if (arr[j] < arr[min_idx]) + min_idx = j; + + + int temp = arr[min_idx]; + arr[min_idx] = arr[i]; + arr[i] = temp; + } + } + + + void printArray(int arr[]) + { + int n = arr.length; + for (int i=0; i 0; z--) { + x[z] = x[(z - 1)]; + y[z] = y[(z - 1)]; + } + + if (leftDirection) { + x[0] -= DOT_SIZE; + } + + if (rightDirection) { + x[0] += DOT_SIZE; + } + + if (upDirection) { + y[0] -= DOT_SIZE; + } + + if (downDirection) { + y[0] += DOT_SIZE; + } + } + + private void checkCollision() { + + for (int z = dots; z > 0; z--) { + + if ((z > 4) && (x[0] == x[z]) && (y[0] == y[z])) { + inGame = false; + } + } + + if (y[0] >= B_HEIGHT) { + inGame = false; + } + + if (y[0] < 0) { + inGame = false; + } + + if (x[0] >= B_WIDTH) { + inGame = false; + } + + if (x[0] < 0) { + inGame = false; + } + + if (!inGame) { + timer.stop(); + } + } + + private void locateApple() { + + int r = (int) (Math.random() * RAND_POS); + apple_x = ((r * DOT_SIZE)); + + r = (int) (Math.random() * RAND_POS); + apple_y = ((r * DOT_SIZE)); + } + + @Override + public void actionPerformed(ActionEvent e) { + + if (inGame) { + + checkApple(); + checkCollision(); + move(); + } + + repaint(); + } + + private class TAdapter extends KeyAdapter { + + @Override + public void keyPressed(KeyEvent e) { + + int key = e.getKeyCode(); + + if ((key == KeyEvent.VK_LEFT) && (!rightDirection)) { + leftDirection = true; + upDirection = false; + downDirection = false; + } + + if ((key == KeyEvent.VK_RIGHT) && (!leftDirection)) { + rightDirection = true; + upDirection = false; + downDirection = false; + } + + if ((key == KeyEvent.VK_UP) && (!downDirection)) { + upDirection = true; + rightDirection = false; + leftDirection = false; + } + + if ((key == KeyEvent.VK_DOWN) && (!upDirection)) { + downDirection = true; + rightDirection = false; + leftDirection = false; + } + } + } +} diff --git a/string to date b/string to date new file mode 100644 index 0000000..b4f51b2 --- /dev/null +++ b/string to date @@ -0,0 +1,13 @@ +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; + +public class TimeString { + + public static void main(String[] args) { + // Format y-M-d or yyyy-MM-d + String string = "2017-07-25"; + LocalDate date = LocalDate.parse(string, DateTimeFormatter.ISO_DATE); + + System.out.println(date); + } +} diff --git a/sum of array b/sum of array new file mode 100644 index 0000000..10c5330 --- /dev/null +++ b/sum of array @@ -0,0 +1,24 @@ +class Main { + public static void main(String[] args) { + + int[] numbers = {2, -9, 0, 5, 12, -25, 22, 9, 8, 12}; + int sum = 0; + Double average; + + // access all elements using for each loop + // add each element in sum + for (int number: numbers) { + sum += number; + } + + // get the total number of elements + int arrayLength = numbers.length; + + // calculate the average + // convert the average from int to double + average = ((double)sum / (double)arrayLength); + + System.out.println("Sum = " + sum); + System.out.println("Average = " + average); + } +} diff --git a/swappingUsingBitwise b/swappingUsingBitwise new file mode 100644 index 0000000..651d043 --- /dev/null +++ b/swappingUsingBitwise @@ -0,0 +1,21 @@ +import java.util.Scanner; +public class JavaExample +{ + public static void main(String args[]) + { + int num1, num2; + Scanner scanner = new Scanner(System.in); + System.out.print("Enter first number:"); + num1 = scanner.nextInt(); + System.out.print("Enter second number:"); + num2 = scanner.nextInt(); + + num1 = num1 ^ num2; + num2 = num1 ^ num2; + num1 = num1 ^ num2; + + scanner.close(); + System.out.println("The First number after swapping:"+num1); + System.out.println("The Second number after swapping:"+num2); + } +} diff --git a/tic tac toe game b/tic tac toe game new file mode 100644 index 0000000..570cac2 --- /dev/null +++ b/tic tac toe game @@ -0,0 +1,218 @@ +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +class TTT1 extends JFrame implements ItemListener, ActionListener{ +int i,j,ii,jj,x,y,yesnull; +int a[][]={{10,1,2,3,11},{10,1,4,7,11},{10,1,5,9,11},{10,2,5,8,11}, + {10,3,5,7,11},{10,3,6,9,11},{10,4,5,6,11}, + {10,7,8,9,11} }; +int a1[][]={{10,1,2,3,11},{10,1,4,7,11},{10,1,5,9,11},{10,2,5,8,11}, + {10,3,5,7,11},{10,3,6,9,11},{10,4,5,6,11},{10,7,8,9,11} }; + +boolean state,type,set; + +Icon ic1,ic2,icon,ic11,ic22; +Checkbox c1,c2; +JLabel l1,l2; +JButton b[]=new JButton[9]; +JButton reset; + +public void showButton(){ + +x=10; y=10;j=0; +for(i=0;i<=8;i++,x+=100,j++){ + b[i]=new JButton(); +if(j==3) +{j=0; y+=100; x=10;} + b[i].setBounds(x,y,100,100); +add(b[i]); +b[i].addActionListener(this); +}//eof for + +reset=new JButton("RESET"); +reset.setBounds(100,350,100,50); +add(reset); +reset.addActionListener(this); + +}//eof showButton + +/*********************************************************/ +public void check(int num1){ +for(ii=0;ii<=7;ii++){ + for(jj=1;jj<=3;jj++){ + if(a[ii][jj]==num1){ a[ii][4]=11; } + + }//eof for jj + +}//eof for ii +}//eof check +/**********************************************************/ + +/*********************************************************/ + +public void complogic(int num){ + + for(i=0;i<=7;i++){ + for(j=1;j<=3;j++){ + if(a[i][j]==num){ a[i][0]=11; a[i][4]=10; } + } + } + for(i=0;i<=7;i++){ // for 1 + set=true; + if(a[i][4]==10){ //if 1 + int count=0; + for(j=1;j<=3;j++){ //for 2 + if(b[(a[i][j]-1)].getIcon()!=null){ //if 2 + count++; + } //eof if 2 + else{ yesnull=a[i][j]; } + } //eof for 2 + if(count==2){ //if 2 + b[yesnull-1].setIcon(ic2); + this.check(yesnull); set=false;break; + } //eof if 2 + } //eof if 1 + else + if(a[i][0]==10){ + for(j=1;j<=3;j++){ //for2 + if(b[(a[i][j]-1)].getIcon()==null){ //if 1 + b[(a[i][j]-1)].setIcon(ic2); + this.check(a[i][j]); + set=false; + break; + } //eof if1 + } //eof for 2 + if(set==false) + break; + }//eof elseif + + if(set==false) + break; + }//eof for 1 + + +}//eof complogic + + +/*********************************************************/ + +TTT1(){ +super("tic tac toe by ashwani"); + +CheckboxGroup cbg=new CheckboxGroup(); +c1=new Checkbox("vs computer",cbg,false); +c2=new Checkbox("vs friend",cbg,false); +c1.setBounds(120,80,100,40); +c2.setBounds(120,150,100,40); +add(c1); add(c2); +c1.addItemListener(this); +c2.addItemListener(this); + + +state=true;type=true;set=true; +ic1=new ImageIcon("ic1.jpg"); +ic2=new ImageIcon("ic2.jpg"); +ic11=new ImageIcon("ic11.jpg"); +ic22=new ImageIcon("ic22.jpg"); + +setLayout(null); +setSize(330,450); +setVisible(true); +setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); +}//eof constructor + +/*************************************************************/ +public void itemStateChanged(ItemEvent e){ + if(c1.getState()) + { + type=false; + } + + else if(c2.getState()) + { type=true; + } +remove(c1);remove(c2); + repaint(0,0,330,450); + showButton(); +}//eof itemstate +/************************************************************/ + +public void actionPerformed(ActionEvent e){ +/********************************/ +if(type==true)//logicfriend +{ +if(e.getSource()==reset){ + for(i=0;i<=8;i++){ + b[i].setIcon(null); + }//eof for +} +else{ + for(i=0;i<=8;i++){ + if(e.getSource()==b[i]){ + + if(b[i].getIcon()==null){ + if(state==true){ icon=ic2; + state=false;} else{ icon=ic1; state=true; } + b[i].setIcon(icon); + } + } + }//eof for +}//eof else +}//eof logicfriend +else if(type==false){ // complogic + if(e.getSource()==reset){ + for(i=0;i<=8;i++){ + b[i].setIcon(null); + }//eof for + for(i=0;i<=7;i++) + for(j=0;j<=4;j++) + a[i][j]=a1[i][j]; //again initialsing array + } + else{ //complogic + for(i=0;i<=8;i++){ + if(e.getSource()==b[i]){ + if(b[i].getIcon()==null){ + b[i].setIcon(ic1); + if(b[4].getIcon()==null){ + b[4].setIcon(ic2); + this.check(5); + } else{ + this.complogic(i); + } + } + } + }//eof for + } + }//eof complogic + +for(i=0;i<=7;i++){ + + Icon icon1=b[(a[i][1]-1)].getIcon(); + Icon icon2=b[(a[i][2]-1)].getIcon(); + Icon icon3=b[(a[i][3]-1)].getIcon(); + if((icon1==icon2)&&(icon2==icon3)&&(icon1!=null)){ + if(icon1==ic1){ + b[(a[i][1]-1)].setIcon(ic11); + b[(a[i][2]-1)].setIcon(ic11); + b[(a[i][3]-1)].setIcon(ic11); + JOptionPane.showMessageDialog(TTT1.this,"!!!YOU won!!! click reset"); + break; + } + else if(icon1==ic2){ + b[(a[i][1]-1)].setIcon(ic22); + b[(a[i][2]-1)].setIcon(ic22); + b[(a[i][3]-1)].setIcon(ic22); + JOptionPane.showMessageDialog(TTT1.this,"won! click reset"); + break; + } + } + } + + +}//eof actionperformed +/************************************************************/ + +public static void main(String []args){ +new TTT1(); +}//eof main +}//eof class diff --git a/zero sum subarray b/zero sum subarray new file mode 100644 index 0000000..228e40f --- /dev/null +++ b/zero sum subarray @@ -0,0 +1,21 @@ +import java.util.*; + +// n<10^5 where n is the size of the given array. (solution around 0(n)) + +public class ZeroSumSubarray { + public static void main(String[] args) { + int sum=0; + boolean found=false; + int arr[]={2,3,1,-6,6,1}; + Set s=new HashSet<>(); + for(int ele:arr){ + s.add(sum); + sum+=ele; + if(s.contains(sum)){ + found=true; + break; + } + } + System.out.println(found); + } +}