View Java Linear Search Algorithm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Input: | |
public class ScalerTopics | |
{ | |
public static void main(String[] args) { | |
int[] array = new int[] {5, 3, 12, 9, 45, 1, 22}; | |
int K = 9; | |
int result = linearSearch(array, K); | |
View Java Constructor Overloading
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Input: | |
public class ConstructorEG { | |
String name; | |
Integer number; | |
ConstructorEG(){ // default constructor | |
System.out.println("Default Constructor called"); | |
} |
View Reverse a String in Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1. Using toCharArray(): | |
public static String reverse(String str) | |
{ | |
String rev=""; | |
char[] finalarray = str.toCharArray(); | |
for (int i = finalarray.length - 1; i >= 0; i--) | |
rev+=finalarray[i]; | |
return rev; | |
} |