• Post Reply Bookmark Topic Watch Topic
  • New Topic

What is the output for the below code ?  RSS feed

 
Ramesh Kumar Koyya
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
public class Test {

public static void main(String... args) {
for(int i = 2; i < 4; i++)
for(int j = 2; j < 4; j++)
if(i < j)
assert i!=j : i;


}
}

answer The class compiles and runs, but does not print anything.

can anybody tell explanation of this code
 
Paweł Baczyński
Bartender
Posts: 2087
44
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you run this code with assertions enabled?
What is the condition that must be true (regarding values of i and j) that must be true to assert statement being reached?
What is the condition that must be true (regarding values of i and j) that must be true that would make assert statement print anything?

Can those conditions be true at the same time?
 
Campbell Ritchie
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please always tell us where such questions come from, to avoid copyright problems.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!