Add Data Odd-Even

what if I want to add 20 data using a loop with the format:

  • If the number is odd then input Susan’s name
  • If the number is even then input the name Jaka
  • If multiple of 5 then points = number * 5, if multiple of 3 then points = number * 3, if multiple of 4 points = number * 4
  • If it is not a multiple of 3/4/5 then write the number
for(int i = 0; i < 20; i++) {

    // check evenness/oddness:
    if(i % 2 == 0) {
        // number is even, input name "Jaka"...
    } else {
        // number is odd, input name "Susan"...
    }
    
    int points = 0;
    // check if multiple:
    if(i % 3 == 0) {
        points = i * 3;
    } else if (i % 4 = 0) {
        points = i * 4;
    } else if (i % 5 = 0) {
        points = i * 5;
    } else {
        points = i;
    }
    // do something with "points"...

}

how to show output (i) when i use browser at the set text

What do you mean by output?

Do you want to just output it to the console?

System.out.println(i);

Do you want to output it to the Katalon keylogger?

KeywordUtil.logInfo(String.valueOf(i));

Can you provide more details about your test case? It would also be good to see the script you are currently working on, if possible.

my keyword:
public class Loop {
@Keyword
public void getloop(){
for (int i=1;i<=5;i++){

		if (i % 2 == 0){

			WebUI.setText(findTestObject('Submit Susan Loop/input_poin _txtPoin'), 'i')
			WebUI.delay(1)

			WebUI.setText(findTestObject('Object Repository/Submit Susan Loop/input_Name _txtName'), 'Susan')
			WebUI.delay(1)

			WebUI.click(findTestObject('Object Repository/Submit Susan Loop/input_poin _btnSubmit'))
			WebUI.delay(1)
		}else{
			WebUI.setText(findTestObject('Submit Susan Loop/input_poin _txtPoin'), '+i')
			WebUI.delay(1)

			WebUI.setText(findTestObject('Object Repository/Submit Susan Loop/input_Name _txtName'), 'Jaka')
			WebUI.delay(1)

			WebUI.click(findTestObject('Object Repository/Submit Susan Loop/input_poin _btnSubmit'))
			WebUI.delay(1)
		}
	}
}

}

my test case:
WebUI.openBrowser(’’)
WebUI.navigateToUrl(‘http://116.254.100.222:81/’)

// modify WebUI.* keywords which take TestObject as arg0
// so that they call Highlight.on() automatically
CustomKeywords.‘com.kazurayam.ksbackyard.HighlightElement.pandemic’()

WebUI.click(findTestObject(‘Object Repository/Submit Susan Loop/a_Login’))
WebUI.delay(1)

WebUI.setText(findTestObject(‘Object Repository/Submit Susan Loop/input_E-Mail Address_email’), ‘jecsanmaychel01@gmail.com’)
WebUI.delay(1)

WebUI.setEncryptedText(findTestObject(‘Object Repository/Submit Susan Loop/input_Password_password’), ‘bI3RgGn7xr4YpfW5IuOWug==’)
WebUI.delay(1)

WebUI.click(findTestObject(‘Object Repository/Submit Susan Loop/button_Login’))
WebUI.delay(1)

CustomKeywords.‘Loop.getloop’()

WebUI.click(findTestObject(‘Object Repository/Submit Susan Loop/a_Logout’))
WebUI.delay(1)

WebUI.closeBrowser()

app browser: http://116.254.100.222:81/

I want in the script loop when the field points are filled with even/odd numbers, it automatically fills in the name, odd for; Susan and even for: Jaka

You can simplify that a bit:

   for(int i = 1; i <= 5; i++) {
        WebUI.setText(findTestObject('Submit Susan Loop/input_poin _txtPoin'), String.valueOf(i))
		WebUI.delay(1)
        if(i % 2 == 0) {
			WebUI.setText(findTestObject('Object Repository/Submit Susan Loop/input_Name _txtName'), 'Jaka')
        } else {
			WebUI.setText(findTestObject('Object Repository/Submit Susan Loop/input_Name _txtName'), 'Susan')
        }
        WebUI.delay(1)
        WebUI.click(findTestObject('Object Repository/Submit Susan Loop/input_poin _btnSubmit'))
		WebUI.delay(1)
    }

oke Mr it’s work!
how about multiple data ?

What do you mean by “multiple data”?

  • If multiple of 5 then points = number * 5, if multiple of 3 then points = number * 3, if multiple of 4 points = number * 4
  • If it is not a multiple of 3/4/5 then write the number

and I want to do it together with odd-even

I had that in my original reply:

int points = 0;
if(i % 3 == 0) {
    points = i * 3;
} else if (i % 4 = 0) {
    points = i * 4;
} else if (i % 5 = 0) {
    points = i * 5;
} else {
    points = i;
}

You essentially check for multiples by using the mod (%) operator. If you want to check if a number is a multiple of x, you mod it with x and check that the remainder is zero:

i % x = 0

where should i put this ?

I don’t know, it’s your script. I was just answering your question:

I’m probably misunderstanding how this will be used to accomplish what you want to do in Katalon (I think we have a pretty serious language barrier), but I do believe that I’ve at least given you the tools you need to figure this out.

i used this successfully, but for the 3/4/5 case do i add it after the ‘if’ ?

this issue was recruitment test for my company, and TS not read this question carefully, even though I already show the output example…
for info: TS failed the test