Query 1
package A1;
public class D {
public static void main (String[] args) {
for(int i=1;i<=3;)
{
for(int j=3;j>=1;)
{
if(i<=j)
{
System.out.println(i+" -- "+j);
}
j--;
}
i=i+2;
}
}
}
Query 2
package A1;
public class D {
public static void main (String[] args) {
for(int i=1;i<=3;)
{
for(int j=3;j>=1;)
{
if(i!=j)
{
System.out.println(i+" -- "+j);
break;
}
j--;
}
i=i+2;
}
}
}
Query 3
package A1;
public class D {
public static void main(String[] args) {
for (int i = 3; i <= 15;) {
i += ++i + 2;
System.out.println(i);
++i;
}
}
}
Query 4
package A1;
public class D {
public static void main(String[] args) {
for (int i = 3; i <= 15;) {
i*= ++i + 2;
i+=i;
System.out.println(++i);
}
}
}
Query 5
package A1;
public class D {
public static void main(String[] args) {
int j = 3;
for (int i = 3; i <= 9;) {
i += i + j;
j += i;
j++;
i = j;
System.out.println(i + " " + j);
}
}
}
Solutions:
Query 1 Output:
1 — 3
1 — 2
1 — 1
3 — 3
Query 2 Output:
1 — 3
3 — 2
Query 3 Output:
9
23
Query 4 Output:
37
Query 5 Output:
13 13