Java 程式用來計算兩個數字的積


在 Java 中,* 運算子用於相乘兩個數字。使用 Scanner 類從使用者讀取所需數字,並使用 * 運算子相乘兩個整數。

示例

import java.util.Scanner;
public class MultiplicationOfTwoNumbers {
   public static void main(String args[]){
      Scanner sc = new Scanner(System.in);
      System.out.println("Enter the value of the first number ::");
      int a = sc.nextInt();
      System.out.println("Enter the value of the first number ::");
      int b = sc.nextInt();
      int result = a*b;
      System.out.println("Product of the given two numbers is ::"+result);
   }
}

輸出

Enter the value of the first number ::
55
Enter the value of the first number ::
66
Product of the given two numbers is ::3630

更新時間:21-6-2024

10K+ 檢視

開啟你的 職業生涯

透過完成課程獲取認證

開始
廣告