Posts

Showing posts from 2015

Count number of words in string example java program code

import java.util.HashMap; public class RunApplication {     public static void main(String[] args) {         String sentence = "this is that is not is";         // Split sentence in word         String[] words = sentence.split(" ");         System.out.println("Total Word used in sentence is " + words.length);         HashMap<String, Integer> wordCounter = new HashMap<String, Integer>();         for (String w : words) {             //Search for word w             boolean foundStatus = wordCounter.containsKey(w);             if (foundStatus) {                 //if found than ...

Bubble Sort

Image
  public class BubbleSort {     public void Sort() { //method scope start         int[] salary = { 5, 1, 12, -5, 16 };                 for (int j = 0; j < salary.length; j++) { //first for loop             for (int i = 0; i < salary.length - 1; i++)  { //second for loop                 int n1 = salary[i];                 int n2 = salary[i + 1];                 if (n1 > n2)  { //if condition start                     int temp = n1;                     n1 = n2;   ...

Java loop Part 2

Java loop Path 1 Print * * * * * * * * * * * * * * * for (int i = 0; i < 5; i++) {       for (int j = 0; j < i; j++)       {          System.out.print(" "); // Print space       }       for (int k = i; k < 5; k++)       {          System.out.print("*");       }       System.out.println(""); } Print * * * * * * * * * * * * * * * for (int i = 5; i > 0; i--) {       for (int j = 0; j < i; j++)       {          System.out.print(" "); // Print space       }       for...

Java loops

Print * * * * * * * * * * * * * * * Code for (int i = 0; i < 5; i++) {             for (int j = 0; j < i; j++)            {                 System.out.print(" * ");             }             System.out.println(" "); } Print * * * * * * * * * * * * * * * Code for (int i = 5; i > 0; i--) {             for (int j = 0; j < i; j++)            {                 System.out.print(" * ");             }             System.out.println(" "); } Print * * * * * * * * * * * *...

How to read .xls file in Java

Need to download dependency JXL http://search.maven.org/#artifactdetails|net.sourceforge.jexcelapi|jxl|2.6.12|jar  ...  <dependency>         <groupId>net.sourceforge.jexcelapi</groupId>         <artifactId>jxl</artifactId>         <version>2.6.12</version>  </dependency> .... import jxl.Sheet; import jxl.Workbook; import jxl.read.biff.BiffException; import java.io.File; import java.io.IOException; public class MyDataProvider {     public Object[][] ReadDataFromExcelFile(String filePath, String sheetName, int columnSize) throws IOException, BiffException {         //I want to open excel file         Workbook workbookObj = Workbook.getWorkbook(new File(filePath));         //I ...

Method Generator

Help to understand java method syntax Generator

IDE Targating

Now it's easy to understand Selenium Locating Elements . By Id By Name By CSS By XPath Click on IDE Helper