Rahul Pandit.

5 Mar 2022

I cannot get two different input in the loop, howerver if at first I define int n = 1, it works [closed]

Javascript

Closed. This question needs details or clarity. It is not currently accepting answers.


 

Want to improve this question? Add details and clarify the problem by editing this post.

Closed 42 mins ago.

Improve this question

I cannot get two different inputs in the loop, however if at first, I define int n = 1, it works

import java.util.Scanner;

public class Test 
{
 public static void main(String[] args)
 {
 Scanner Input = new Scanner(System.in);
 int n = Input.nextInt();
 while (n >= 1 && n <=5)
 {
 if (n == 1)
 {
 System.out.print("Enter a: ");
 String S1 = Input.nextLine();
 System.out.print("Enter b: ");
 String S2 = Input.nextLine();
 System.out.println(S1);
 System.out.print(S2);
 }
 System.out.println();
 n = Input.nextInt();
 }
 Input.close();
 }
}

Comments

Shilpa

5 Mar 2022

github

The default value of int is 0.

© 2024 Copyrights reserved for web-brackets.com