Basic Arithmetic Operations in Java | Java Programming | Direct Coding |
Java Programming Playlist : https://www.youtube.com/playlist?list=PLLv1D2fSHA_WsDuGKIeRB_EqiJWAe28gV
First Java Program | Java Programming | Direct Coding | :
https://youtu.be/e6pn9lmSbrY
Source Code in Telegram :
Telegram : https://t.me/DirectCoding
Arithmetic Operators
These operators involve the mathematical operators that can be used to perform various simple or advanced arithmetic operations on the primitive data types referred to as the operands. These operators consist of various unary and binary operators that can be applied on a single or two operands. Let’s look at the various operators that Java has to provide under the arithmetic operators.
1. Addition(+): This operator is a binary operator and is used to add two operands.
Syntax:
num1 + num2
Example:
num1 = 10, num2 = 20
sum = num1 + num2 = 30
2. Subtraction(-): This operator is a binary operator and is used to subtract two operands.
Syntax:
num1 - num2
Example:
num1 = 20, num2 = 10
sub = num1 - num2 = 10
3. Multiplication(*): This operator is a binary operator and is used to multiply two operands.
Syntax:
num1 * num2
Example:
num1 = 20, num2 = 10
mult = num1 * num2 = 200
4. Division(/): This is a binary operator that is used to divide the first operand(dividend) by the second operand(divisor) and give the quotient as a result.
Syntax:
num1 / num2
Example:
num1 = 20, num2 = 10
div = num1 / num2 = 2
5. Modulus(%): This is a binary operator that is used to return the remainder when the first operand(dividend) is divided by the second operand(divisor).
Syntax:
num1 % num2
Example:
num1 = 5, num2 = 2
mod = num1 % num2 = 1
Explanation
The program implements basic arithmetic operations using user input in Java. The program uses the Scanner class from the java.util package to read user input from the console. The following steps describe how the program works in detail:
Import the java.util.Scanner class: The program starts by importing the Scanner class, which is used to read input from the console.
Create a Scanner object: Next, a Scanner object sc is created and associated with the standard input stream System.in.
Read the first number from the user: The program prompts the user to enter the first number and uses the nextDouble() method of the Scanner class to read the input. The input is stored in the num1 variable of type double.
Read the second number from the user: The program prompts the user to enter the second number and uses the nextDouble() method of the Scanner class to read the input. The input is stored in the num2 variable of type double.
Perform arithmetic operations: The program performs the four basic arithmetic operations (addition, subtraction, multiplication, and division) using the num1 and num2 variables and stores the results in separate variables sum, difference, product, and quotient.
Print the results: The program prints out the results of the arithmetic operations using the println method of the System.out object.
This program demonstrates how to implement basic arithmetic operations using user input in Java. The Scanner class makes it easy to read user input from the console, and the basic arithmetic operations are performed using standard mathematical operators in Java.
Что делает видео по-настоящему запоминающимся? Наверное, та самая атмосфера, которая заставляет забыть о времени. Когда вы заходите на RUVIDEO, чтобы посмотреть онлайн «Basic Arithmetic Operations in Java | Java Programming | Direct Coding |», вы рассчитываете на нечто большее, чем просто загрузку плеера. И мы это понимаем. Контент такого уровня заслуживает того, чтобы его смотрели в HD 1080, без дрожания картинки и бесконечного буферизации.
Честно говоря, Rutube сегодня — это кладезь уникальных находок, которые часто теряются в общем шуме. Мы же вытаскиваем на поверхность самое интересное. Будь то динамичный экшн, глубокий разбор темы от любимого автора или просто уютное видео для настроения — всё это доступно здесь бесплатно и без лишних формальностей. Никаких «заполните анкету, чтобы продолжить». Только вы, ваш экран и качественный поток.
Если вас зацепило это видео, не забудьте взглянуть на похожие материалы в блоке справа. Мы откалибровали наши алгоритмы так, чтобы они подбирали контент не просто «по тегам», а по настроению и смыслу. Ведь в конечном итоге, онлайн-кинотеатр — это не склад файлов, а место, где каждый вечер можно найти свою историю. Приятного вам отдыха на RUVIDEO!
Видео взято из открытых источников Rutube. Если вы правообладатель, обратитесь к первоисточнику.