Question

Java Submit a program in a .java file. The program should print a multiplication table for...

Java

  • Submit a program in a .java file. The program should print a multiplication table for the numbers 1-9.
  • This requires a nested for loop. The outer loop moves from row to row, while the inner loop prints the row.
  • Use tabs to separate the output, such as in the following statement:

     System.out.println(“1\t2\t3\t4\t5\t6\t7\t8\t9”);

  • Output should look similar to the following.

1      2     3     4     5     6     7     8     9

------------------------------------------------------------------

1       2     3     4     5     6        7     8     9

2       4     6     8    10    12    14    16    18

3       6     9    12   15    18    21    24    27

4       8    12   16   20    24    28    32    36
     …

9      18   27   36   45    54    63    72    81

Write a program as follows:

  • Inner Loop
    • Ask the user to specify how many values (an integer between 2 an 10) they want to to sum up.
    • Use a loop inside this loop to ensure that the number of values they enter is between 2 and 10
    • Use that value as a counter to request the user to enter the numbers to sum.
  • Outer loop - ask the user if they want to sum up numbers again. If they do, the inner loop will execute again.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.util.Scanner;

public class Mult_Table {

public static void main(String[ ] args) {

for(int i=1; i <= 9; i++)

System.out.print(i +" \t ");

for(int i=1; i <=9; i++){// nested loop

  System.out.print(\t" ");

for(int j=1; j<= 9; j++)

System.out.print(i*j +" \t ");

}

}

}

-----------------+-------------------+

Program2

import java.util.Scanner;

public class Sum {

public static void main(String[ ] args) {

int n,x, sum=0,flag;

Scanner scan = new Scanner(System.in); System.out.print("Enter number between 2 and 10 "); n = scan.nextInt();

if( n<2||n>10)

{ System.out.print("invalid input");

return;. }

do{//outer loop

for(int i=1; i <= n; i++){//inner loop

x=scan.nextInt();

sum+=x;

}

System.out.println(" do you want to sum up again 1 for yes 0 for no");

flag=scan.nextInt();

}while(flag==1);

}

}

Add a comment
Know the answer?
Add Answer to:
Java Submit a program in a .java file. The program should print a multiplication table for...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT