For specific number iterations can we use for loop right
@IntelliSkills2 ай бұрын
Yes.
@rajeshpasupuleti92502 ай бұрын
package java_exm; import java.util.Scanner; public class GuessNumberPuzzle { public static void main(String[] args) { // TODO Auto-generated method stub Scanner sc=new Scanner(System.in); int random=(int) (Math.random()*100); System.out.print("guess number: "); int guess=sc.nextInt(); boolean flag=true; int i=1; while(flag&&irandom) { System.out.println("it is less than your guess number"); guess=sc.nextInt(); } else { System.out.println("it is greater than your guess number"); guess=sc.nextInt(); } i++; } System.out.println("its over"); } } correct me if iam wrong
@IntelliSkills2 ай бұрын
the code was really nice and it was somewhat correct. There was only one mistake I could find, i.e., it was six guesses, not 5. You see, at first only you are taking one guess. So, in the while loop instead of writing i
@rajeshpasupuleti92502 ай бұрын
@@IntelliSkillsmam tell me the exact difference between for and while loop. And how tricky question asked in an interview