Question

1) Write a java programming nested while loop where you will declare two numbers one for...

1) Write a java programming nested while loop where you will declare two numbers one for outer loop and the other one for inner while loop, and display the result. (Try using scanner)

Steps: 1) Declare the variable of outer loop int and assign value of your choice

2) Declare while condition which outer variable is less the number of your choice

3) Declare variable of inner loop int and assign the value of your choice

4) Declare while condition where inner variable is less the number of your choice

5) Print the outer and inner value

6) Increment inner by 1

7) Increment outer by 1

Homework Answers

Answer #1

Implement the program as follows:

  1. import Scanner class
  2. define main() method
  3. Initialize Scanner object, input
  4. declare variables m, n
  5. Read value to the variable, m
  6. declare value to the variable n
  7. Declare the variable of outer loop int, i
  8. Declare the variable of inner loop int, j
  9. assign value 0 to i
  10. Declare while condition which outer variable, i is less the number m
  11. assign value 0 to j
  12. Declare while condition which inner variable, j is less the number n
  13. Print the outer value, i and inner value, j
  14. increment inner value j by 1
  15. increment outer value i by 1

Program: Nested_While.java


import java.util.Scanner;                                                                                                                       /* import Scanner class */
public class Nested_While { 
        public static void main(String[] args){                                                                                 /* define main() method */
                Scanner input = new Scanner(System.in);                                                                         /* Initialize Scanner object, input */
                int m,n;                                                                                                                                        /* declare variables m, n */
                System.out.print("Enter the number of Outer while loop executions : ");
                m = input.nextInt();                                                                                                            /* Read value to the variable, m */
                System.out.print("Enter the number of Inner while loop executions : ");
                n = input.nextInt();                                                                                                            /* declare value to the variable n */
                
                int i;                                                                                                                                          /* Declare the variable of outer loop int, i */
                int j;                                                                                                                                          /* Declare the variable of inner loop int, j */
                
                i = 0;                                                                                                                                          /* assign value 0 to i */
                while(i<m){                                                                                                                                  /* Declare while condition which outer variable, i is less the number m */
                        j=0;                                                                                                                                    /* assign value 0 to j */
                        while(j<n){                                                                                                                          /* Declare while condition which inner variable, j is less the number n */
                                System.out.println("i = " + i + ", j = " + j);                                          /* Print the outer value, i and inner value, j */
                                j++;                                                                                                                            /* increment inner value j by 1 */
                        }
                        i++;                                                                                                                                    /* increment outer value i by 1 */
                }
        }
}
                

Screenshot:

Output:

Please don't forget to give a Thumbs Up.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
1) Write a java programming using a while loop where you will add numbers and when...
1) Write a java programming using a while loop where you will add numbers and when you press number 0 it will add all your numbers and display the results. Use Scanner object. Steps: 1) Declare variables integer called sum which is equal to zero   2) Declare Scanner object   3) Declare while condition where is true   4) Inside of that condition prompt the user to enter the numbers   5) Declare variable integer called number and input the number statement   6)...
4) Write a java program where you will use while loop, where if condition is equal...
4) Write a java program where you will use while loop, where if condition is equal to 2 (or any other choice of your number) then it will break the while condition. Steps: 1) Declare variable int (any name) which is equal to zero 2) Declare while condition which variable int is less then equal to 10 3) Declare print out where the value of variable is the same name that you declared in step 1 4) Declare condition if...
5) Write a java program with scanner object to input first number and second number as...
5) Write a java program with scanner object to input first number and second number as variable with input statement and system out print statement. Steps: 1) Declare scanner object 2) Ask system out print for first number and declare variable first number 3) Ask system out print for second number and declare variable second number 4) Declare first for loop where variable int i has already a value (your choice), that i is less then equal to ? and...
Write the C++ code using nested for loops that prints the product of the outer loop...
Write the C++ code using nested for loops that prints the product of the outer loop counter and the inner loop counter; one per line. The outer loop counter should go from 1 to 8 and the inner loop counter should go from the value of the outer loop counter to 10. Both counters should increment by 1. Use outer for the outer loop counter and inner for the inner loop counter.
4.9.1: Nested loops: Indent text. JAVA Print numbers 0, 1, 2, ..., userNum as shown, with...
4.9.1: Nested loops: Indent text. JAVA Print numbers 0, 1, 2, ..., userNum as shown, with each number indented by that number of spaces. For each printed line, print the leading spaces, then the number, and then a newline. Hint: Use i and j as loop variables (initialize i and j explicitly). Note: Avoid any other spaces like spaces after the printed number. Ex: userNum = 3 prints: 0 1 2 3 Please use my template import java.util.Scanner; public class...
In Java programming language 11.Create the code for a for loop to print the numbers 1  through...
In Java programming language 11.Create the code for a for loop to print the numbers 1  through 5 inclusive vertically so the output is 1 2 3 4 5 11b What is the output of the following               OUTPUT int i=3; while(int i >0) { System.out.println(i); i--; } 11c What is the output of the following               OUTPUT for(int i=3;i<10;i++) System.out.println(3*i); 11d Create the line of code to print the numbers 10 through 1 decreasing by 1 each time 11e Create the line of code...
5) Create a Java program using Scanner: Write a program where you will enter the grade...
5) Create a Java program using Scanner: Write a program where you will enter the grade score for 5 classes, then it will display total points and average and it will display the grade based on percentage. Steps: 1) Declare variable integer for English, Chemistry, Java Programming, Physics and Math 2) Declare variable total and percentage 3) Create Scanner object and prompt the user to enter grades for each class and input grades after each class 4) Calculate total of...
4.2.2 Basic while loop with user input. JAVA Write an expression that executes the loop while...
4.2.2 Basic while loop with user input. JAVA Write an expression that executes the loop while the user enters a number greater than or equal to 0. Note: These activities may test code with different test values. This activity will perform three tests, with user input of 9, 5, 2, -1, then with user input of 0, -17, then with user input of 0 1 0 -1. See "How to Use zyBooks". Also note: If the submitted code has an...
4) Write a Java program using Conditions: Write a program where it will ask user to...
4) Write a Java program using Conditions: Write a program where it will ask user to enter a number and after that it will give you answer how many digits that number has. Steps: 1) Create Scanner object and prompt user to enter the number and declare variable integer for input 2) Use if else condition with && condition where you will specify the digits of numbers by writing yourself the digit number that should display: Example(num<100 && num>=1), and...
The Java program should sum the odd integers from 1 to the integer that the user...
The Java program should sum the odd integers from 1 to the integer that the user enters. For example, if the user enters 30, the program should sum the odd integers from 1 to 30.   Print "Please enter a positive nonzero integer." Declare a Scanner and obtain an integer from the user.   Use a Do...while statement and calculate the sum Use the integer that the obtained from the previous step for the loop-continuation condition. Display the sum Print the sum...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT