What does this mean

int next //bye

int game //is amount of teams entered

next = (game % 2 == 0) ? -1 : ((Teams)iList.get(game-1)).getNum();

game /= 2;

matches =newint[game][3];

what do each of these lines mean, am i correct. what does ?-1 mean

[329 byte] By [magiciana] at [2007-11-27 0:44:49]
# 1
? : http://java.sun.com/docs/books/tutorial/java/nutsandbolts/op2.html
DrLaszloJamfa at 2007-7-11 23:09:24 > top of Java-index,Java Essentials,Java Programming...
# 2

I can explain the syntax. But the meaning of what they do is up to you.

// line 1

next = something ? a : b;

means

if (something) next=a; else next=b;

// line 2

game /= 2;

means

game = game / 2;

// line 3

matches = new int[game][3];

means

matches = a new 2-dimensional integer array with game*3 entries

KathyMcDonnella at 2007-7-11 23:09:24 > top of Java-index,Java Essentials,Java Programming...
# 3

> int next //bye

> int game //is amount of teams entered

>

>

> next = (game % 2 == 0) ? -1 :

> ((Teams)iList.get(game-1)).getNum();

> game /= 2;

> matches = new int[game][3];

>

>

what do each of these lines mean, am i

> correct. what does ?-1 mean

// ternary - means: if game 'modulus' 2 'equals' 0, set next to -1, else set next to that other expression ...

// which is the 'element (game-1)' of a 'List', cast to a 'Teams' Object, upon which the getNum() method is called ...

// which apparently is - or should be - an int.

next = (game % 2 == 0) ? -1 : ((Teams)iList.get(game-1)).getNum();

// This is the 'divide-equals' operator(s). means same as: game = game / 2

game /= 2;

// This you know right?

matches = new int[game][3];

abillconsla at 2007-7-11 23:09:24 > top of Java-index,Java Essentials,Java Programming...
# 4

ok brill, so

public void setNum(int x)

{

Num= x;

}

public int getNum()

{

return Num;

}

how would that connect to last line, sorry been here all day and just all over my head

magiciana at 2007-7-11 23:09:24 > top of Java-index,Java Essentials,Java Programming...
# 5

> ok brill, so

> > public void setNum(int x)

> {

> Num= x;

> }

>

> public int getNum()

> {

> return Num;

> }

>

> how would that connect to last line, sorry been here

> all day and just all over my head

You mean 2nd line, or 2nd to last line? It's just what I said it returns an int. int getNum() ... returns the int value Num.

abillconsla at 2007-7-11 23:09:24 > top of Java-index,Java Essentials,Java Programming...