Important Information: This is an individual assignment for you to complete on y
ID: 3852064 • Letter: I
Question
Important Information: This is an individual assignment for you to complete on your own. If you need help, take advantage of the Piazza discussion board, office hours or the open forum lab, You may not work with or assist another student or receive assistance from anyone other than the CS 177 teaching staff. Due Date: Submit your finished program to the Project 1 assignment on Blackboard by 11: 59 pm on June 27^th. Problem Description: Spaced Multiplication & Division Tables Multiplication tables show the product of natural numbers in a tabular format. The rows represent the multiplicands and the columns represent the multipliers. Division tables are the same concept for division, and show the quotient. The rows represent the dividends and the columns represent the divisors. Generally, the dividends and multiplicands for these tables begin from 1. For Project 1, inputs N1 and N2 determine the range of dividends and multiplicands, and the Multiplication and Division tables are for natural numbers from N1 to N2 (both included), Include multipliers and divisors at increments of x, which will be provided as input. Inputs: Starting number (N1), ending number (N2), and increment (x) Output: Spaced Multiplication Table for N1-N2, with multipliers 1. 1 + X, 1+2X... 1+10x Spaced Division Table for N1 - N2 with divisors 1, 1+x, 1+2x... 1+10xExplanation / Answer
Code:
import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner s = new Scanner(System.in);
//Taking input from user
System.out.print("Enter N1:");
int n1=s.nextInt();
System.out.print("Enter N2:");
int n2=s.nextInt();
System.out.print("Enter X:");
int x=s.nextInt();
//For multiplication Table
System.out.println(" Spaced Multiplication Table ");
for(int i=1;i<10;i++){
System.out.print(" "+i);
}
System.out.println(" ");
for(int i=n1; i <= n2; i=i+x){
System.out.print(i);
for(int j=1;j<10;j++){
System.out.print(" "+i*j);
}
System.out.println();
}
System.out.println(" ");
//For Division Table
System.out.println(" Spaced Division Table ");
for(int i=1;i<10;i++){
System.out.print(" "+i);
}
System.out.println(" ");
for(int i=n1; i <= n2; i=i+x){
System.out.print(i);
for(int j=1;j<10;j++){
System.out.printf(" %.2f",(float)i/j);
}
System.out.println();
}
}
}
Output: