Ask Question
23 March, 20:24

java Given an int variable n that has already been declared, write some code that repeatedly reads a value into n until at last a number between 1 and 10 (inclusive) has been entered.

+5
Answers (1)
  1. 23 March, 20:41
    0
    import java. util. Scanner;

    public class num8 {

    public static void main (String[] args) {

    Scanner in = new Scanner (System. in);

    int n = 0;

    for (int i = 1; i<=10; i++) {

    System. out. println ("Enter the values");

    n + = in. nextInt ();

    }

    }

    }

    Explanation:

    A complete Java program implementing the solution is given above. The Scanner class is imported to allow for user input The variable n is declared and initialized to 0. Using a for loop, the user is repeatedly asked to enter a value The value is added to the variable n with this statement n + = in. nextInt (); The for loop condition for (int i = 1; i<=10; i++) ensures that it runs only ten times.
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “java Given an int variable n that has already been declared, write some code that repeatedly reads a value into n until at last a number ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers