Category Archives: Java

Queue in Java

package test5; import java.util.LinkedList; /** * Queues using LinkedList * @author asharda * */ public class Queues { LinkedList<Integer> list=new LinkedList<Integer>(); /** * Enqueue * @param data */ public void enqueue(int data) { list.add(data); } /** * Dequeue * @return … Continue reading

Posted in Data Structures, Java, Java 8, Uncategorized | Leave a comment

Stack using LinkedList in Java

package test5; import java.util.LinkedList; /** * Stack using LinkedList * @author asharda * */ public class Stack { LinkedList<Integer> list=new LinkedList<Integer>(); /** * Push Operation * @param data */ public void push(int data) { list.addFirst(data); } /** * Display contents … Continue reading

Posted in Data Structures, Java, Java 8, Uncategorized | Leave a comment

Add 2 Binary Strings using Java

class Solution { public String addBinary(String a, String b) { int c=Integer.parseInt(a, 2) + Integer.parseInt(b, 2) ; return Integer.toBinaryString(c); } }

Posted in Java, LeetCode Solutions, Uncategorized | Leave a comment

Calculate Length of Hypotenuse of Right Angle Triangle

package test5; public class RightTriangle { public static void main(String[] args) { double c; double a=4,b=3; c=Math.sqrt(a*a+b*b); System.out.println(“Length of the hypotenuse is “+c); } }

Posted in Java | Leave a comment

Encrypt/Decrypt a password

package test5; import java.util.Base64; /** * Encrypt/Decrypt a Password * @author asharda * */ public class PasswordTest { /** * @param args */ public static void main(String[] args) { String password=”Hi this is a password”; byte []b=Base64.getEncoder().encode(password.getBytes()); System.out.println(new String(Base64.getDecoder().decode(b))); } … Continue reading

Posted in Java, Uncategorized | Leave a comment

Simple Binary Search using Java

/** * Simple Binary Search * @author asharda * */ public class BinSearch { public static void main(String[] args) { BinSearch bin=new BinSearch(); int arr[]= {2,4,6,8,10,12,14,16}; boolean b=bin.binSearch(arr,0,arr.length-1,16); System.out.println(“Number found “+b); } public boolean binSearch(int arr[],int low,int high,int val) { … Continue reading

Posted in Data Structures, Java, Java 8, Uncategorized | Leave a comment

Rotate Array

/**Program to rotate array * @author asharda * */ public class RotateArray { /** * @param args */ public static void main(String[] args) { RotateArray r =new RotateArray(); int arr[]= {1,2,3,4,5,6,7}; int b[]=r.rotateArray(arr,2); for(int i:b) { System.out.println(i); } } /** … Continue reading

Posted in Data Structures, Java, Java 8 | Leave a comment