Java Programs
Java Programs
{
int r,sum=0,temp;
int n=454;
temp=n;
while(n>0)
{
r=n%10;
sum=(sum*10)+r;
n=n/10;
}
if(temp==sum)
s.o.p("palidrom number);
else
s,op("not palindrom);
Reverse String:
public class ReverseString()
{
public static String reverseString(String str)
{
StringBuilder sb= new StringBuilder(str);
sb.reverse();
return sb.toString();
}}
Anothor Method:
Class RevmoceDupliacates
{
4.
public class CountOccurences
{
public static void main(String args[])
{
int count=0;
for(int i=0; i<input.length(); i++)
{
if(input.charAt(i) == search)
count++;
}
try
{
FileOutputStream fos=new FileOutputtream(file);
wb.write(fos);
}
Catch(Exception e)
{
e.printStackTrace();
}
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
//iterate over all the row to print the data present in each cell.
for(int i=0;i<=rowCount;i++){
for(int j=0;j<cellcount;j++){
System.out.print(sheet.getRow(i).getCell(j).getStringCellValue()
+",");
}
System.out.println();
}
}
}
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
//iterate over all the rows in Excel and put data in the form.
for(int i=1;i<=rowCount;i++) {
//Enter the values read from Excel in
firstname,lastname,mobile,email,address
firstName.sendKeys(sheet.getRow(i).getCell(0).getStringCellValue());
lastName.sendKeys(sheet.getRow(i).getCell(1).getStringCellValue());
email.sendKeys(sheet.getRow(i).getCell(2).getStringCellValue());
mobile.sendKeys(sheet.getRow(i).getCell(4).getStringCellValue());
address.sendKeys(sheet.getRow(i).getCell(5).getStringCellValue());
} else {
//if the message is not displayed , write FAIL in the excel sheet
cell.setCellValue("FAIL");
}
//wait for page to come back to registration page after close button is
clicked
driver.manage().timeouts().implicitlyWait(2000, TimeUnit.SECONDS);
}
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import java.io.FileInputStream;
import java.io.IOException;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
File scr=((Takescreenshot)driver).getScreenshotAs(OUTPUTType.FILE);
FIleUtils.copyGFile(scr.