Saved Bookmarks
| 1. |
Write program in Java to print following pattern1 3 5 7 93 5 7 9 15 7 9 1 37 9 1 3 59 1 3 5 7 |
|
Answer» Here's the quick solution I came up with, it COULD probably be improved. int[] series = {1,3,5,7,9}; int numToSkip = -1; for (int i = -1; i < series.length; i++) { //Loop as many times as the series. It starts on -1 so it loops ONE EXTRA time for (int item : series) { //Loop through each item in the series if (numToSkip != item) { //If we aren't skipping that item, print it System.out.println(item); } } numToSkip += 2; //Increase the number to skip by 2 } |
|