result += primes[i];
JLS 15.18:
If just one operand to + is a String, the other operand is converted to a string, and then string concatenation is used.
private static int i ;
private static int primes[] = {2,3,5,7};
private static String resulet = "";
public static void main(String[] args) {
while (i < primes.length) {
if( i == 3) {
break;
}
i++;
resulet += primes[i];
}
System.out.println(resulet);
}
A: is correct only know what happend with i = 2 case, event before append increment so when is 2 increment i = 3 and array contain element 3, so append its ok. After that while is break for if condition
A voting comment increases the vote count for the chosen answer by one.
Upvoting a comment with a selected answer will also increase the vote count towards that answer by one.
So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
ASPushkin
4 months, 2 weeks agoedwMr9
5 months, 3 weeks agod7bb0b2
11 months, 3 weeks agotmuralimanohar
1 year, 6 months agoStavok
1 year, 6 months agoTADIEWA
2 years ago