public Object[][] dp1() {
return new Object[][] {
new Object[] { "a", "b" },
new Object[] { "c", "d" },
};
}
public Object[][] dp2() {
return new Object[][] {
new Object[] { "e", "f" },
new Object[] { "g", "h" },
};
}
@DataProvider
public Object[][] dp() {
List<Object[]> result = Lists.newArrayList();
result.addAll(Arrays.asList(dp1()));
result.addAll(Arrays.asList(dp2()));
return result.toArray(new Object[result.size()][]);
}
@Test(dataProvider = "dp")
public void f(String a, String b) {
System.out.println("f " + a + " " + b);
}
Selenium automation framework
Selenium Automation Testing
Friday, December 21, 2018
TestNG - Can i use the 2 different data providers to same @test methods in TestNG?
Java - Duplicate chars in a String
String str = "asdfasdfafk asd234asda";
Map<Character, Integer> charMap = new HashMap<Character, Integer>();
char[] arr = str.toCharArray();
for (char value: arr) {
if (Character.isAlphabetic(value)) {
if (charMap.containsKey(value)) {
charMap.put(value, charMap.get(value) + 1);
} else {
charMap.put(value, 1);
}
}
}
System.out.println(charMap);
Java - Two Max number in array
package programs;
public class TwoMaxNumbersInArray {
public void twoMaxNumbersInArray(int[] a){
int firstBigNumber = 0;
int secondBigNumber = 0;
for(int num:a){
if(firstBigNumber < num){
secondBigNumber = firstBigNumber;
firstBigNumber = num;
System.out.println("secondBigNumber:-"+secondBigNumber);
System.out.println("firstBigNumber:-"+firstBigNumber);
System.out.println("-------");
}
else if(secondBigNumber < num){
secondBigNumber = num;
System.out.println("secondBigNumber:-"+secondBigNumber);
System.out.println("*******");
}
}
System.out.println("firstBigNumber is:-"+firstBigNumber);
System.out.println("secondBigNumber is:-"+secondBigNumber);
}
public static void main(String a[]){
int num[] = {5,34,78,2,45,1,99,23};
TwoMaxNumbersInArray obj = new TwoMaxNumbersInArray();
obj.twoMaxNumbersInArray(num);
}
}
public class TwoMaxNumbersInArray {
public void twoMaxNumbersInArray(int[] a){
int firstBigNumber = 0;
int secondBigNumber = 0;
for(int num:a){
if(firstBigNumber < num){
secondBigNumber = firstBigNumber;
firstBigNumber = num;
System.out.println("secondBigNumber:-"+secondBigNumber);
System.out.println("firstBigNumber:-"+firstBigNumber);
System.out.println("-------");
}
else if(secondBigNumber < num){
secondBigNumber = num;
System.out.println("secondBigNumber:-"+secondBigNumber);
System.out.println("*******");
}
}
System.out.println("firstBigNumber is:-"+firstBigNumber);
System.out.println("secondBigNumber is:-"+secondBigNumber);
}
public static void main(String a[]){
int num[] = {5,34,78,2,45,1,99,23};
TwoMaxNumbersInArray obj = new TwoMaxNumbersInArray();
obj.twoMaxNumbersInArray(num);
}
}
Java - Sum of array
package programs;
import java.util.Arrays;
public class SumofArray1 {
public static void test() {
int[] arr = {1,2,3,4,5,6,7,8,9};
int sum =0;
for (int i : arr) {
sum =sum+i;
}
System.out.println(sum);
}
public static void repeatednumber() {
int[] arr = {10,2,2,3,5,5,6,8,8};
Arrays.sort(arr);
for (int i = 1; i < arr.length; i++) {
if (arr[i] == arr[i-1]) {
// System.out.println("Duplicate elements : "+ arr[i]);
} else {
System.out.println("---------------------------------");
System.out.println("Distinict Elements - "+ arr[i]);
}
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
repeatednumber();
}
}
import java.util.Arrays;
public class SumofArray1 {
public static void test() {
int[] arr = {1,2,3,4,5,6,7,8,9};
int sum =0;
for (int i : arr) {
sum =sum+i;
}
System.out.println(sum);
}
public static void repeatednumber() {
int[] arr = {10,2,2,3,5,5,6,8,8};
Arrays.sort(arr);
for (int i = 1; i < arr.length; i++) {
if (arr[i] == arr[i-1]) {
// System.out.println("Duplicate elements : "+ arr[i]);
} else {
System.out.println("---------------------------------");
System.out.println("Distinict Elements - "+ arr[i]);
}
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
repeatednumber();
}
}
Java - reverse Number in java
package programs;
import java.util.Scanner;
public class ReverseNumber {
public void reverseNumber(){
Scanner scn = new Scanner(System.in);
System.out.println("Enter number");
int number = scn.nextInt();
int reverse = 0;
while(number!=0){
reverse = reverse*10;
reverse = reverse + number%10;
number = number/10;
}
System.out.println("Reversed number is:-"+reverse);
}
public static void main(String[] args) {
ReverseNumber obj = new ReverseNumber();
obj.reverseNumber();
}
}
Pattern Programs in Java
package programs;
public class PatternProgram1 {
/**
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
1 2 3 4 5 6
1 2 3 4 5 6 7
*/
public static void main(String[] args) {
for(int i =1;i<=7;i++){
for(int j =1; j<=i;j++){
System.out.print(j+" ");
}
System.out.println();
}
}
}
public class PatternProgram1 {
/**
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
1 2 3 4 5 6
1 2 3 4 5 6 7
*/
public static void main(String[] args) {
for(int i =1;i<=7;i++){
for(int j =1; j<=i;j++){
System.out.print(j+" ");
}
System.out.println();
}
}
}
-------------------------------------------------------------------
package programs;
public class PatternProgram2 {
/**
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
6 6 6 6 6 6
7 7 7 7 7 7 7
*/
public static void main(String[] args) {
for(int i =1;i<=7;i++){
for(int j =1; j<=i;j++){
System.out.print(i+" ");
}
System.out.println();
}
}
}
----------------------------------------------------------------------
package programs;
public class PatternProgram3 {
/**
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
1 2 3 4 5 6
1 2 3 4 5 6 7
1 2 3 4 5 6
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1
*/
public static void main(String[] args) {
for(int i =1; i<=7;i++){
for(int j =1; j<=i;j++){
System.out.print(j+" ");
}
System.out.println();
}
for(int i=6;i>=1;i--){
for(int j =1; j<=i;j++){
System.out.print(j+" ");
}
System.out.println();
}
}
}
---------------------------------------------------------------------
package programs;
import java.util.Scanner;
public class PatternProgram5 {
/**
1 2 3 4 5 6 7
1 2 3 4 5 6
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1
*/
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("enter input data");
int number = scanner.nextInt();
for(int i=number;i>=1; i--){
for(int j = 1; j<=i;j++){
System.out.print("*"+" ");
}
System.out.println();
}
}
}
-----------------------------------------------------------------------
package programs;
import java.util.Scanner;
public class PatternProgram6{
/**
7 6 5 4 3 2 1
7 6 5 4 3 2
7 6 5 4 3
7 6 5 4
7 6 5
7 6
7
*/
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("enter input data");
int number = scanner.nextInt();
for(int i =1; i<=number;i++){
for(int j = number; j>=i;j--){
System.out.print(j+" ");
}
System.out.println();
}
}
}
--------------------------------------------------------------------------
package programs;
public class PatternProgram7 {
/**
1 2 3 4 5 6 7
1 2 3 4 5 6
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
1 2 3 4 5 6
1 2 3 4 5 6 7
*/
public static void main(String[] args) {
for(int i =7; i>=1; i--){
for(int j =1 ; j<=i; j++){
System.out.print(j+" ");
}
System.out.println();
}
for(int k = 2; k<=7; k++){
for(int j =1 ; j<=k; j++){
System.out.print(j+" ");
}
System.out.println();
}
}
}
----------------------------------------------------------------------
package programs;
public class PatternProgram8 {
/**
1
1 2 1
1 2 3 2 1
1 2 3 4 3 2 1
1 2 3 4 5 4 3 2 1
1 2 3 4 5 6 5 4 3 2 1
1 2 3 4 5 6 7 6 5 4 3 2 1
*/
public static void main(String[] args) {
for(int i = 1; i<=7; i++){
for(int j = 1; j<=i; j++){
System.out.print(j+" ");
}
for(int j = i-1; j>=1; j--){
System.out.print(j+" ");
}
System.out.println();
}
}
}
------------------------------------------------------------------------
Subscribe to:
Posts (Atom)
TestNG - Can i use the 2 different data providers to same @test methods in TestNG?
public Object [][] dp1 () { return new Object [][] { new Object [] { "a" , "b" }, new Obje...
-
public Object [][] dp1 () { return new Object [][] { new Object [] { "a" , "b" }, new Obje...
-
package programs; public class CalculateSumOfNumbersOfArray { public int calculateSumOfNumbers(){ int[] a = {10,20,30,40}; int ...
-
package programs; import java.util.Scanner; public class ReverseNumber { public void reverseNumber(){ Scanner scn = new ...