-
-
Notifications
You must be signed in to change notification settings - Fork 24
Java program to multiply two numbers #371
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
arghyaxcodes
merged 8 commits into
javaistic:main
from
AbhishekJadhav2002:java-program-to-multiply-two-numbers
Oct 17, 2022
Merged
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
92524f9
Java program to multiply two numbers in (/programs/multiply-two-numbers)
AbhishekJadhav2002 22e5985
Update .gitignore
arghyaxcodes 7b02e0f
Update yarn.lock
arghyaxcodes da2ac2a
Resolved suggested changes in /pages/programs/multiply-two-numbers.mdx
AbhishekJadhav2002 835a612
Merge branch 'java-program-to-multiply-two-numbers' of https://github…
AbhishekJadhav2002 f46c8ca
Fetched gitignore changes
AbhishekJadhav2002 5290ea8
Delete package-lock.json
arghyaxcodes a7c48d6
Update multiply-two-numbers.mdx
arghyaxcodes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,3 +30,4 @@ yarn-error.log* | |
| .env.production.local | ||
|
|
||
| .vercel | ||
| package-lock.json | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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' | ||
|
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 | ||
| ``` | ||
|
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 | ||
| ``` | ||
|
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> | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.