8 Mart 2010, PAZARTESİ
Java: kolon Nedir (:) operatörü?
Kendim bakmak istiyorum, ama ne dendiğini bile bilmiyorum. Herkes ne yaptığını açıklayan bir sakıncası var mı?
EDİT: birden fazla olduğunu bilmiyordum kat : ortaya çıktı. Bu durumda burada ne yapar:
public String toString() {
String cardString = "";
for (PlayingCard c : this.list) // <--
{
cardString = cardString c "\n";
}
Edit: Nasıl her biri için bu yaz döngü değil birleştirmek için farklı bir yol miydiniz ":"?
CEVAP
8 Mart 2010, PAZARTESİ
Kolon Java kodunda kullanıldığı çeşitli yerler vardır:
1) Jump-etiket (Tutorial):
label: for (int i = 0; i < x; i ) {
for (int j = 0; j < i; j ) {
if (something(i, j)) break label; // jumps out of the i loop
}
}
// i.e. jumps to here
2) durum (Tutorial) Üçlü:
int a = (b < 4)? 7: 8; // if b < 4, set a to 7, else set a to 8
3)-Her döngü (Tutorial):
String[] ss = {"hi", "there"}
for (String s: ss) {
print(s); // output "hi" , and "there" on the next iteration
}
4) İddia (Guide):
int a = factorial(b);
assert a >= 0: "factorial may not be less than 0"; // quits the program with the message if the condition evaluates to false
5) switch deyiminde Case (Tutorial):
switch (type) {
case WHITESPACE:
case RETURN:
break;
case NUMBER:
print("got number: " value);
break;
default:
print("syntax error");
}
Bunu Paylaş:
Ruby kolon operatörü nedir?...
= Operatörü Java...
Bu nedir !! JavaScript? (değil) operat...
ETMENİZ için Java karşılığı nedir?...
C Çifti eşdeğer<L,R> Java nedir?...