![](/img/trans.png)
[英]I want to check in my path if there is a pair of value… suppose if my path is 1 2 3 4 5 i want to check if (2 3) occurs in my path or not
[英]How to increment the string value using for loop? Suppose my first value is “Project1” and then i want the second value as “project2” and so on
給定的字符串為String [] s1 = {“ Project1”}使用for循環,我想在下一次迭代中將s1值從“ Project1”更改為“ Project2”。 隨着循環的不斷進行,項目值應該增加。有人可以解決這個問題,這對java和selenium來說是新的。
您可以將int
與字符串串聯結合使用:
for (int i = 1; i <= 10; i++) {
String projectName = "Project" + i;
// use projectName here...
}
嘗試這個:
String str = "Project";
int HighestNumber; //set the bound for the number of projects you want
for(int i = 0;i<HighestNumber; i++)
{
System.out.println(str + toString(i));
}
如果您不想設置限制,可以使用
int i = 0; // or 1
while(true)
{
i++;
System.out.println(str + toString(i));
}
String[] s1={"Project1"};
for(int i=2; i<n;i++) // n is how many you have to increase the project value
{
s1[0]= "Project"+String.valueOf(i);
System.out.println(s1[0]);
}
在第一次迭代中,我將打印Project2
第二次迭代Project3
第二次迭代Project4 ..........
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.