Java Programming Puzzles Solutions
Java Programming Puzzles Solutions
Copyright © Manikandan S
http://www.smanikandan.co.nr
2009 Free for Use
2|P age
This document consists of puzzles and programming problems, which I’ve found in the
Internet. The aim of this document is to promote logical thinking and reasoning, which are
the essential components for any application developer. Since, Java is a pure object oriented
language, I thought it would be a good language to start with. The solutions to the
programming problems and puzzles have been included as a separate document. I
recommend you to look at the solutions only after you’ve really tried your hand at solving
the problems. All the Best. Enjoy Programming.
Cheers,
Manikandan S
Copyright © Manikandan S
http://www.smanikandan.co.nr
2009 Free for Use
3|P age
System.out.println();
}
}
}
Copyright © Manikandan S
http://www.smanikandan.co.nr
2009 Free for Use
4|P age
for(i=1;i<=4;i++)
{
for(j=1;j<=i;j++)
{
System.out.print((k++)+" ");
System.out.println();
}
}
}
Copyright © Manikandan S
http://www.smanikandan.co.nr
2009 Free for Use
5|P age
class NumberPattern
{
public static void main(String args[])
{
for(int i = 1; i <= 5; i++)
{
int j = 0;
for(int k = 0; k < i; k++)
{
System.out.print((i + j) + " ");
j += 4 - k;
}
System.out.println();
}
}
Copyright © Manikandan S
http://www.smanikandan.co.nr
2009 Free for Use
6|P age
Additional Information: This number pattern is actually a mathematical pattern called Floyd’s
triangle.
class floyd
int i,j,k;
for(i=1;i<=7;i++)
if(i%2!=0)
for(j=1;j<=i;j++)
if(j%2==0)
System.out.print("0 ");
else
System.out.print("1 ");
}
Copyright © Manikandan S
http://www.smanikandan.co.nr
2009 Free for Use
7|P age
else if(i%2==0)
for(j=1;j<=i;j++)
if(j%2==0)
System.out.print("1 ");
else
System.out.print("0 ");
System.out.println();
Copyright © Manikandan S
http://www.smanikandan.co.nr
2009 Free for Use