More than 3000 questions in repository. There are more than 900 unanswered questions. Click here and help us by providing the answer. Have a video suggestion. Click Correct / Improve and please let us know.
Interview Questions and Answers for 'Intelliswift' - 1 question(s) found - Order By Newest
Q1. Write a program to print all even numbers first and then all odd numbers till 100. For example the output should be
2
4
6
8
...... 100
and then
1
3
5
7
...... 99
using only 1 for loop ? Is it possible with just one loop ?
public class BuggyBread{
public static void main (String args[]) {
int x = 50;
for(int i=1;i <= 100;i++){
if(i<=50){
System.out.println(i*2);
} else {
System.out.println(i-x);
x = x - 1;
}
}
}
}
Help us improve. Please let us know the company, where you were asked this question :