Java

package JavaPrograms; import java.util.*; public class palindrome { public static void main(String args[]) { String original, reverse=””; Scanner in = new Scanner(System.in); System.out.println(“Enter a string to check if it is a palindrome”); original = in.nextLine(); int length = original.length(); for ( int i = length – 1 ; i >= 0 ; i– ) reverse […]

Continue Reading

package JavaPrograms; import java.util.HashSet; import java.util.Set; public class IntersectionofArrays { public static void main(String[] args) { int[] firstInts = new int[]{2,3,4,5,5,7,9,0,0,0}; int[] secondInts = new int[]{2,44,2,33,8,5,12,14,0}; Set<Integer> intersects = intersectArrays(firstInts, secondInts); // print out the set of intersecting integers for (Integer theInt : intersects) { System.out.println(“intersect on ” + theInt); } } public static Set<Integer> […]

Continue Reading

package JavaPrograms; import java.util.Arrays; public class IntArraySorting { public static void main(String[] args) { int arrayList[] = {1,2,4,5,9,3,6,22,33}; int len = arrayList.length; Arrays.sort(arrayList); for(int i=0;i<len; i++) { System.out.print(arrayList[i] +”\n”); } Arrays.sort(arrayList); // sort method used to sort the array contents . System.out.println(“2nd Highest number: ” + Arrays.asList(arrayList[len-2])); int index = Arrays.binarySearch(arrayList, 33); for (int j=0;j<len; […]

Continue Reading

package JavaPrograms; public class fabonacciSeries { /*Write a program to find Fibonacci series of a given no. Example : Input – 8 Output – 1 1 2 3 5 8 13 21 */ public static void main(String args[]) { int num = 6; //taking no. as command line argument. System.out.println(“*****Fibonacci Series*****”); int f1=0, f2=0, f3=1, […]

Continue Reading

package JavaPrograms; public class CompareArray { public static void compareArrays(int[] array1, int[] array2) { boolean b = true; if (array1 != null && array2 != null){ if (array1.length != array2.length) b = false; else for (int i = 0; i < array2.length; i++) { if (array2[i] != array1[i]) { b = false; } } }else{ […]

Continue Reading

package JavaPrograms; 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(); […]

Continue Reading

package JavaPrograms; import java.util.*; public class ArraytoVector { public static void main(String[] args) { // declare and initialize array of object of given class. Object[] arrObject = {“Manish”, new Date(), “Rajesh”}; //create list for this object array. List list = Arrays.asList(arrObject); // create vector for given list. Vector vector = new Vector(list); // access the […]

Continue Reading

Automation Tester who uses selenium with Java, has to know all core java concepts. and during interview most of the interviewers including me ask several core Java questions. here is most common asked interview questions.

Continue Reading