Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ yarn-error.log*
.env.production.local

.vercel
package-lock.json
1 change: 1 addition & 0 deletions src/navs/program.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const programsNav = {
Introduction: [
pages['print-an-integer'],
pages['add-two-integers'],
pages['multiply-two-numbers'],
Comment thread
AbhishekJadhav2002 marked this conversation as resolved.
Outdated
pages['check-even-or-odd'],
pages['java-program-to-add-two-binary-numbers'],
pages['java-program-to-add-two-complex-numbers'],
Expand Down
89 changes: 89 additions & 0 deletions src/pages/programs/multiply-two-numbers.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
---
title: Java Program to Multiply Two Integers
shortTitle: Multiply Two Integers
description: In this program, you'll learn to store and multiply two integer numbers in Java. After multiplication, the final value is displayed on the screen.
---

import { List, ListItemGood } from '@/components/List'
Comment thread
AbhishekJadhav2002 marked this conversation as resolved.
Outdated


To understand this example, you should have the knowledge of the following Java programming topics:

- [Java Operators](/docs/operators)
- [Java Basic Input and Output](/docs/basic-input-output)

## Multiply Two Integers

A Java program that multiply two numbers predefined by the user is as follows:

### Example 1: Program to Multiply Two Integers

```java
class Main {

public static void main(String[] args) {

System.out.println("Enter two numbers");
int first = 10;
int second = 2;

System.out.println(first + " " + second);

// multiply two numbers
int multiplication = first * second;
System.out.println("Multiplication: " + first + " * " + second + " = " + multiplication);
}
}
```

#### Output

```text
Enter two numbers
10 2
Multiplication: 10 * 2 = 20
```
Comment thread
AbhishekJadhav2002 marked this conversation as resolved.
Just like the [previous program](/programs/add-two-integers#example-program-to-add-two-integers) of addition,

Then, `first` and `second` are multiplied using the `*` operator, and its result is stored in another variable `multiplication`.

And then, `multiplication` along with some [string concatenation](/docs/basic-input-output#example-print-concatenated-strings) is printed on the screen using `println()` function.


### Example 2: Program to Multiply Two Double

Multiplication can be performed between positive, negative numbers as well,

```java
class Main {

public static void main(String[] args) {

System.out.println("Enter two numbers");
double first = -13.0;
double second = 2.3;

System.out.println(first + " " + second);

// multiply two numbers
double multiplication = first * second;
System.out.println("Multiplication: " + first + " * " + second + " = " + multiplication);
}
}
```

#### Output

```text
Enter two numbers
-13.0 2.3
Multiplication: -13.0 * 2.3 = -29.9
```
Comment thread
AbhishekJadhav2002 marked this conversation as resolved.

Datatype of variable `multiplication` is `double`, because the result of multiplying two numbers having data type `double` is `double`.

<TipInfo>

**Note:** Here, the output `multiplication` is negative, because these operations foolow [standard mathematical rules](https://en.wikipedia.org/wiki/Multiplication#Properties).

</TipInfo>
Loading