Shashi Kumar

Forum Replies Created

Viewing 3 posts - 1 through 3 (of 3 total)

  • Shashi Kumar
    Participant

    We can use the % Modulus operator to which returns the remainder. In the below code we are taking two variable one is i and j. i and j are looped 10 times. The value of i goes from 0-5 for 2 iterations which is because of Modulus %;

    String[] a = new String[]{"a","b","c","d","e"};
    for(int i =0,j=0 ; i< a.length*2 && j < a.length*2 ; i++, j++) {
    			i = i%a.length;
    			System.out.println(a[i]);
    		}

    Shashi Kumar
    Participant

    We can reverse the string by splitting the string characters into an char array and then looping through the array. Below is the code where you can reverse the string Hello World in Java.

    String string = "Hello World";
    	char[] stringCharArray = string.toCharArray();
    	String reverse = "";
    	for(int i=stringCharArray.length-1; i>=0 ; i-- ) {
    		reverse = reverse + stringCharArray[i];
    	}
    	System.out.println(reverse);

    Code Explanation : At first we are defining the string variable which contains the string Hello world. We use a string method toCharArray which converts the string into a char array. We can use the for loop in decreasing order, it start with the char Array Size – 1 and decrease one time in each iteration. You can define an empty string reverse and append each character to the reverse string.


    Shashi Kumar
    Participant

    Hi Ashok,
    You can loop through all the data in CSV file using a while loop controller.
    1. Add a Thread Grouo
    2. Add a while controller and give condition as ${varName}. Suppose your have defined varName as variable in CSV file. You can put the same in the while controller condition
    3. Add the sampler and use the ${varName} in your sampler.

    The while controller will loop through all the rows in CSV file and assign the value of that row to the variable.

Viewing 3 posts - 1 through 3 (of 3 total)