From 688319db0068030e48b80b14d34c715e035a53e6 Mon Sep 17 00:00:00 2001 From: psavarmattas Date: Mon, 26 Apr 2021 10:34:30 +0530 Subject: [PATCH] FirstNonRepeating --- FirstNonRepeating.java | 26 ++++++++++++++++++++++++++ FirstNonRepeatingStatic.java | 21 +++++++++++++++++++++ InputFromKeyBoard.java | 2 +- README.MD | 4 ++++ 4 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 FirstNonRepeating.java create mode 100644 FirstNonRepeatingStatic.java diff --git a/FirstNonRepeating.java b/FirstNonRepeating.java new file mode 100644 index 0000000..896a681 --- /dev/null +++ b/FirstNonRepeating.java @@ -0,0 +1,26 @@ +// Program to find first non-repeating character in a string (Dynamic Method). + +import java.util.Scanner; + +public class FirstNonRepeating { + public static void main(String[] args) { + String str1; + Scanner sc = new Scanner(System.in); + System.out.println("Enter the string: "); + str1 = sc.next(); + System.out.println("The given string is: " + str1); + for (int i = 0; i < str1.length(); i++) { + boolean unique = true; + for (int j = 0; j < str1.length(); j++) { + if (i != j && str1.charAt(i) == str1.charAt(j)) { + unique = false; + break; + } + } + if (unique) { + System.out.println("The first non repeated character in String is: " + str1.charAt(i)); + break; + } + } + } +} diff --git a/FirstNonRepeatingStatic.java b/FirstNonRepeatingStatic.java new file mode 100644 index 0000000..b544b9d --- /dev/null +++ b/FirstNonRepeatingStatic.java @@ -0,0 +1,21 @@ +// Program to find first non-repeating character in a string (Static Method). + +public class FirstNonRepeatingStatic { + public static void main(String[] args) { + String str1 = "abcrabc"; + System.out.println("The given string is: " + str1); + for (int i = 0; i < str1.length(); i++) { + boolean unique = true; + for (int j = 0; j < str1.length(); j++) { + if (i != j && str1.charAt(i) == str1.charAt(j)) { + unique = false; + break; + } + } + if (unique) { + System.out.println("The first non repeated character in String is: " + str1.charAt(i)); + break; + } + } + } +} \ No newline at end of file diff --git a/InputFromKeyBoard.java b/InputFromKeyBoard.java index cf1d7f7..7ec661f 100644 --- a/InputFromKeyBoard.java +++ b/InputFromKeyBoard.java @@ -19,4 +19,4 @@ public class InputFromKeyBoard { System.out.println(s); } } -} +} \ No newline at end of file diff --git a/README.MD b/README.MD index f684414..afc8a47 100644 --- a/README.MD +++ b/README.MD @@ -40,6 +40,8 @@ if the problem still persist then create a issue or use Google/Stack Overlflow f |14 | [Calculator](https://github.com/psavarmattas/Java-Projects/blob/master/Calculator.java) | Program that implements the arithmetic operation (Calculator) using switch statement. |15 | [ArithmeticOperations.java](https://github.com/psavarmattas/Java-Projects/blob/master/ArithmeticOperations.java) | Program to print the sum (addition), multiply, subtract, divide and remainder of two numbers. | |16 | [InputFromKeyBoard.java](https://github.com/psavarmattas/Java-Projects/blob/master/InputFromKeyBoard.java) | Program to demonstrate input from keyboard using Command line argument. | +|17 | [FirstNonRepeatingStatic.java](https://github.com/psavarmattas/Java-Projects/blob/master/FirstNonRepeatingStatic.java) | Program to find first non-repeating character in a string (Static Method). | +|18 | [FirstNonRepeating.java](https://github.com/psavarmattas/Java-Projects/blob/master/FirstNonRepeating.java) | Program to find first non-repeating character in a string (Dynamic Method). | @@ -55,6 +57,7 @@ if the problem still persist then create a issue or use Google/Stack Overlflow f |1 | [PrimeNoStatic.java](https://github.com/psavarmattas/Java-Projects/blob/master/PrimeNoStatic.java) | Program to display first n Prime number (Static Method). | |1 | [FibonacciSeriesStatic.java](https://github.com/psavarmattas/Java-Projects/blob/master/FibonacciSeriesStatic.java) | Program to generate fibonacci series upto n value (Static Method). | |1 | [RootsOfQuadracticEquationStatic.java](https://github.com/psavarmattas/Java-Projects/blob/master/RootsOfQuadraticEquationStatic.javav) | Program to find the root of quadratic equation (Static Method). | +|1 | [FirstNonRepeatingStatic.java](https://github.com/psavarmattas/Java-Projects/blob/master/FirstNonRepeatingStatic.java) | Program to find first non-repeating character in a string (Static Method). | |2 | [EvenOddDynamic.java](https://github.com/psavarmattas/Java-Projects/blob/master/EvenOddDynamic.java) | Program to find out the number entered is Even/Odd (Dynamic Method). | |2 | [ArithmeticOperations.java](https://github.com/psavarmattas/Java-Projects/blob/master/ArithmeticOperations.java) | Program to print the sum (addition), multiply, subtract, divide and remainder of two numbers | |2 | [LargestNumber.java](https://github.com/psavarmattas/Java-Projects/blob/master/LargestNumber.java) | Program to find out the largest number (Dynamic Method). | @@ -62,6 +65,7 @@ if the problem still persist then create a issue or use Google/Stack Overlflow f |2 | [PrimeNo.java](https://github.com/psavarmattas/Java-Projects/blob/master/PrimeNo.java) | Program to display first n Prime number (Dynamic Method). | |2 | [FibonacciSeries.java](https://github.com/psavarmattas/Java-Projects/blob/master/FibonacciSeries.java) | Program to generate fibonacci series upto n value (Dynamic Method). | |2 | [RootsOfQuadracticEquation.java](https://github.com/psavarmattas/Java-Projects/blob/master/RootsOfQuadraticEquation.java) | Program to find the root of quadratic equation (Dynamic Method). | +|2 | [FirstNonRepeating.java](https://github.com/psavarmattas/Java-Projects/blob/master/FirstNonRepeating.java) | Program to find first non-repeating character in a string (Dynamic Method). | |3 | [Calculator](https://github.com/psavarmattas/Java-Projects/blob/master/Calculator.java) | Program that implements the arithmetic operation (Calculator) using switch statement.