Skip to content

Instantly share code, notes, and snippets.

@sachin-handiekar
Created June 11, 2011 22:05
Show Gist options
  • Save sachin-handiekar/1021005 to your computer and use it in GitHub Desktop.
Save sachin-handiekar/1021005 to your computer and use it in GitHub Desktop.
Interview Question - InfiniteSeries
public class InfiniteSeries {
public static void main(String[] args) {
int i = 100;
while (true) {
if (i > 0) {
System.out.println((100 - i) + " " + i);
i--;
} else if (i == -100) {
System.out.println((100 + i) + " " + 0);
i--;
} else if (i >= -101 || i >= -200) {
System.out.println((-i - 100) + " " + (-i - 100));
i--;
} else {
i = 100;
}
}
}
}
@sachin-handiekar
Copy link
Author

Write a program to print the following series, using the following condition -

  • One variable
  • One loop
0 100


1 99


2 98


3 97


4 96


5 95


...... ......


98 2


99 1


100 0


99 0


98 0


97 0


96 0


95 0


..... .....


3 0


2 0


1 0


0 0


1 1


2 2


3 3


4 4


.... ....


to infinite

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment