Posts

Sieve of Eratosthenes

Image
Steve of Eratosthenes is an ancient and very important algorithm for finding all primes number up to a given limit. this algorithm  is named after great Greek mathematician “ Eratosthenes”. Principle of Steve of Eratosthenes algorithm is removing all prime numbers i.e. composite numbers from array and now remaining numbers are Prime numbers. For more about algorithm go to Wikipedia . Now without wasting your time I like discuss steps for Steve of Eratosthenes and a simple code in Java to find all prime numbers up to a limit. Algorithm : Step 1: Make an array from 2 to n [2 , 3 , 4 , 5 , 6 , 7 ,8 , 9 ,........ n] Step 2: Beginnings from 2 delete all of its multipliers in the array except itself. for 2 [2 , 3 ,  4 , 5 , 6 , 7 , 8 , 9 ,......n] Step 3: Repeat the step 2 till square root of n. for 3 [2 ,3 , 5 , 7 , 9 , ............ n] . . . . Repeat till sqrt(n) Source Code import java.util.*; public class SteveOfEratosthenes...

Abstraction in Java

Image
During learning of Java programming a term comes Abstract and that term attached with several other terms like class, methods and introduced with a new concept called Abstraction. Abstraction is a process to hide certain details from user and only show essential feature of objects. Abstract class Abstract class is such type of class that contains abstract methods although Abstract classes may contain abstract and concrete both methods but a class which contains abstract method must be declared as Abstract class. Abstract method Abstract terms introduced during Inheritance for hiding unwanted information from user and in case of Inheritance parent and child class terms are introduced during which child class inherit property of parent class and process will be continued but in this case Abstract methods are declared in Abstract class but that does not contains its definition, child class that inherit Abstract class must be contained definition of Abstract method. ...

Microsoft Excel shortcut keys

Image
Today I am delivering some important excel keyboard shortcuts.By using these shortcut keys we can make our work more easy. Shortcut Key Description ctrl+A Select complete Sheet ctrl+C copy selected content ctrl+X cut selected content ctrl+V paste selected content ctrl+A Select complete Sheet Ctrl+Alt+V activate the Paste Special dialog box ctrl+Z Undo Last Action ctrl+Y Redo Last Action ctrl+P Open a Dialogue box to give print order ctrl+S save workbook ctrl+U Underline selected content Ctrl+1 activate the Format Cells dialog box Ctrl+;(semicolon) enter the current date into the current cell like, 4/10/2017 ctrl+shift+;(semi-colon) apply current Time,like 11:28 PM Ctrl+Shift+& ...

Mobile Validation Using Java Regular Expression

Image
We discussed here to validate Indian mobile number using concept of regular expression and Indian mobile numbering convention follows a particular protocol 1.India mobile number contains 10 digits 2.First digit of any number is either 7,8,9 and rest 9 lies between 0-9 3.if we include country code then number will be either 11 or 12 digits  a) In case of 11 digits First digit will be 0  b) In case of 12 digits First two digits will be 91 So at first we design regular expression which follows above rules At first we write a rule which follow first number will be either 7,8 or 9 and for this we will write [7,8,9] or in short we can write like this [7-9] after that we have to write rest 9 digits between 0-9 and for this in case of regular expression we can write like this [0-9][0-9].........[0-9] either [0-9] 9 times or in short [0-9]{9} And when we want to write std code then in case of 11 digit i.e to write 0 and in case of 12 digits we write std code as 91 an...

Java Regular Expression

Image
Java Regex or Regular Expression is an API to define Pattern for searching or manipulating Strings, In simple word we can say that Regular expression is a representation of a group of String object according to a particular Pattern. Java provides the java.util.regex package for pattern matching with regular expressions. java.util.regex package consists of following three classes : Pattern Class In Pattern class Pattern object is a compiled version of a regular expression. It contains a compile() method which is used to create a Pattern. Pattern class provides no Public constructors.              Public static Pattern compile(String) Matcher Class Matcher object match the given pattern in the  target String Matcher object is created by matcher() method of Pattern Class     Public Matcher matcher (String target) Important Methods of Matcher class S. No. Method Description 1 bo...

Excel VBA Tricks

Image
If you are working in Excel and want to make your work easy then today I am providing some VBA tricks and from these few lines of can definitely divide your task in to small chunks. So now without wasting your and my time I am coming to the point. Here I am discussing Some tricks    Find Number of tabs between two tabs using Excel VBA   Find Empty Sheet using Excel VBA             Find header of sheet using Excel VBA Find Number of tabs between two tabs using Excel VBA  I am providing  a simple trick by which you can perform this task easily for this purpose I am using excel index function , As we know that index function provides number of that tabs like  This is my working sheet as given below and I want to know index value of given sheet then I will write down few lines of code and it will provide me index value of that sheet as shown below Sheet shows I am working inside tab1 and if I want to kn...

Euclidean Algorithm with Example in Java

Image
Euclidean Algorithm is a way to finding GCD (Greatest Common Divisor) of two integers quickly. If we have two integers (A, B) and we want to find out gcd(A,B) then Euclidean Algorithm is one of the best technique. Application Of Euclidean Algorithm For finding GCD of two numbers Euclidean Rythms : developed by GodFried Tourssaint in 2004 and described in a 2005 paper "The Euclidean Algorithm generates Traditional Musical Rhythms. The Algorithm If A=0 then GCD(A,B)=B since GCD(0,B) and we can stop If B=0 then GCD(A,B)=A since GCD(A,0) and we can stop Example: import java.util.*; public class EuclideanAlgorithm { public static void main(String arg[]) { Scanner sb = new Scanner(System.in); int a, b, q, r; System.out.println("Enter value of A :"); a = sb.nextInt(); System.out.println("Enter value of B :"); b = sb.nextInt(); if (a == 0) { System.out.println("gcd(...