Sunday, July 5, 2015

List of Indian states as Comma separated

Andhra Pradesh,Arunachal Pradesh,Assam,Bihar,Chhattisgarh,Goa,Gujarat,Haryana,Himachal Pradesh,Jammu and Kashmir,Jharkhand,Karnataka,Kerala,Madhya Pradesh,Maharashtra,Manipur,Meghalaya,Mizoram,Nagaland,Odisha,Punjab,Rajasthan,Sikkim,Tamil Nadu,Telangana,Tripura,Uttar Pradesh,Uttarakhand,West Bengal,Andaman and Nicobar,Chandigarh,Dadra and Nagar Haveli,Daman and Diu,Lakshadweep,Delhi,Puducherry

Friday, January 2, 2015

How to open (Launch) Google chrome browser in selenium

       System.setProperty("webdriver.chrome.driver", "E://chromedriver_win32//chromedriver.exe");
      driver = new ChromeDriver();  
       driver.manage().window().maximize();
       driver.get("http://www.google.com");

Sunday, December 21, 2014

How to open chrome inspector(Developer tool) in separate window

Follow these steps to open chrome inspector(Developer tool) in separate window
1. Launch Chrome Browser and press key (Ctrl + Shift + i)
2. Step 1 will launch the developer tool, Place your pointer on the dock button and long click it (some    seconds) or right & left mouse click depending on the browser version.
3. Click on the option displaying after step 2, this will open developers tool in new window.

Tuesday, July 29, 2014

Find the occurrence of Each character in an Given String

This Java code will Print the number of occurrence for all unique character in the given String

Input - Test@Tutor
Output  -
Occurrence of char [t] - 4
Occurrence of char [e] - 1
Occurrence of char [s] - 1
Occurrence of char [@] - 1
Occurrence of char [u] - 1
Occurrence of char [o] - 1
Occurrence of char [r] - 1


CODE -

public class CountCharOccurance
{
public static void main(String[] args)
{
String value = "Test@Tutor";

int[] count = new int[256];

value = value.toLowerCase();

for (int i = 0; i< value.length(); i++)
{
count[(int)value.charAt(i)]++;
}

List<Character> printed = new ArrayList<Character>();

for (int i = 0; i< value.length(); i++)
{
if (printed.contains(value.charAt(i)))
continue;

printed.add(value.charAt(i));

System.out.println("Occurrence of char [" + value.charAt(i) + "] - " + count[(int)value.charAt(i)]);
}
}

}

Converting ASCII to char and Char to ASCII

ASCII to Char
char char-value= (char) asciiValue;

Char to ASCII
int asciiValue = (int) char-Value

Input = 5245 the output should be displayed as 5000+200+40+5.

Java code to Format the given Integer Value

public class FormatIntValue
{
public static void main(String[] args)
{
int num = 5245;

int position = 1;
String outString = "";
String tempString = "";

while(true)
{
tempString = outString ;
outString = "";

outString += (num%10) * position;
position *= 10;
num /=10;

if (position != 10)
outString += "+";
outString += tempString;

if (num < 10)
break;

}
tempString = outString;
outString = "";

outString += (num)*position;
outString += "+";
outString += tempString;

System.out.println(outString);
}
}

Java code to print Asterisks (*) based on Input Provides

Java code to print Asterisks (*) based on Input Provides

e.g: n = 5
then o/p will be as -








CODE:  

public class AstrikPrint
{
public static void main(String[] args)
{
int n = 5;
int count = 1;
for (int i = 0; i<n/2; i++ )
{

for (int j = 0; j < count; j++)
{
System.out.print("*");
}
count+=2;

System.out.print("\n");
}

for (int j = 0; j < count; j++)
{
System.out.print("*");
}
count-=2;

System.out.print("\n");

for (int i = 0; i<n/2; i++ )
{
for (int j = count; j >0; j--)
{

System.out.print("*");
}
count-=2;

System.out.print("\n");
}

}


}