Page 66 - CTS - CSA TP - Volume 2
P. 66

COMPUTER SOFTWARE APPLICATION - CITS



           This program uses a for loop to calculate the sum of a specified number of terms. It prompts the user to enter
           numbers for each term and then calculates the sum of those numbers.

           TASK 2: Multiplication Table using for loop

           import java.util.Scanner;
           public class MultiplicationTable {
           public static void main(String[] args) {
                   Scanner scanner = new Scanner(System.in);


           System.out.print(“Enter the number for the multiplication table: “);
           int number = scanner.nextInt();
           System.out.print(“Enter the number of terms: “);
           int n = scanner.nextInt();
           System.out.println(“Multiplication table for “ + number + “:”);
           for (int i = 1; i<= n; i++) {

           System.out.println(number + “ * “ + i + “ = “ + (number * i));
                   }
           scanner.close();
               }
           }
           Output:















































                                                           51

                               CITS : IT & ITES - Computer Software Application - Exercise 88
   61   62   63   64   65   66   67   68   69   70   71