Tuesday, October 5, 2021

 


Java Program: Take 2 arrays, write a method to - Insert array2 in to array1 at given position

//Output: {12, 13,14,5,6,15}


package qasign;

import java.util.ArrayList;

import java.util.Arrays;

public class SampleTest {

public static void main(String[] args) {

Integer array1[]={12, 13,14,15};

Integer array2[]={5, 6};

int position=3;

List<Integer> list1=new ArrayList<>(Arrays.asList(array1));

System.out.println();

Arrays.asList(array2);

List<Integer> list2=new ArrayList<>(Arrays.asList(array2));

list1.addAll(position, list2);

System.out.println(list1);

}

}

 

1) Reverse each word in a string Input: hello world java   

  //Output: olleh dlrow avaj

String str="hello world java";

String[] tokens=str.split(" ");

for(int i=0;i<tokens.length;i++) {

for(int j=tokens[i].length()-1;j>=0;j--) {

System.out.print(tokens[i].charAt(j));

}

System.out.print(" ");

}

 


package qasignpackage;

import java.util.ArrayList;

import java.util.Arrays;

import java.util.HashMap;

import java.util.List;

import java.util.Map;

import java.util.Map.Entry;

public class SampleTest {

    public static void main(String[] args) {

  HashMap<String, String> hmap=new HashMap<String,String>();

                  hmap.put("1", "qa"); 

                  hmap.put("2", "sign"); 

                  hmap.put("3", "selenium");

  for (Entry<String,String> entry: hmap.entrySet()) {

  System.out.println("Key = " + entry.getKey() +

                      ", Value = " + entry.getValue());

  }

  }

 

selenium-repo by venu

Blog helps to a student or IT employee to develop or improve skills in Software Testing.
For Online Classes Email us: gadiparthi122@mail.com

Followers

About Me

My photo
Hyderabad, Andhra Pradesh, India
I am Automation Testing Professional. I have completed my graduation in B.Tech (Computers) from JNTU Hyderabad and started my career in Software Testing accidentally since then, I passionate on learning new technologies

Contact Form

Name

Email *

Message *

Popular Posts