0

for loop?

Why the latest number is 2 & also why they are not equal x<x*x; or x<36; ? package com.example.myapplication; public class Test { public static void main(String[] args) { int i; for(i=6; i<i*i; --i){ System.out.print(i); } } }

11th Apr 2022, 3:37 PM
A Rahman Mamnoon
A Rahman Mamnoon - avatar
2 Answers
+ 3
When i is 1 it is no longer less than i*i since 1*1=1. So the loop condition is no longer true. I don't understand the second part of your question.
11th Apr 2022, 3:41 PM
Simon Sauter
Simon Sauter - avatar
+ 2
For(initialization; condition; iteration) Your initialization is "i = 6" but your condition becomes false when I is equal to 1 "x<x*x" means that x is less that itself raised to the power of 2 but "x<36" means that x is less that 36 which can also be that condition for this your code as long as you are not gonna go above "I = 35"
20th May 2022, 12:26 PM
Victor Chiemerie
Victor Chiemerie - avatar