Skip to content

Commit 3d4be27

Browse files
committed
Add java program to find quotient and reminder, calculate power of a number.
1 parent e870bd0 commit 3d4be27

File tree

3 files changed

+110
-0
lines changed

3 files changed

+110
-0
lines changed

src/navs/program.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,7 @@ export const programsNav = {
1717
pages['java-program-to-check-Leap-year'],
1818
pages['calculate-simple-interest'],
1919
pages['java-program-to-check-divisbility'],
20+
pages['find-quotient-and-reminder'],
21+
pages['calculate-power-of-a-number'],
2022
],
2123
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
---
2+
title: Java Program to calculate power of a number
3+
shortTitle: Calculate power of a number
4+
description: In this program you'll learn, How to calculate power of a number
5+
---
6+
7+
To understand this example, you should have the knowledge of the following Java programming topics:
8+
9+
- [Java Operators](/docs/operators)
10+
- [Java Basic Input and Output](/docs/basic-input-output)
11+
- [Control Flow statement - For-Loop in Java](/docs/for-loop)
12+
## Calculating power of a number
13+
A java program to calculate the power of a number is as follows:
14+
15+
```java
16+
public class power {
17+
public static void main(String[] args){
18+
java.util.Scanner input = new java.util.Scanner(System.in);
19+
System.out.print("Base Number: ");
20+
int baseNumber = input.nextInt();
21+
System.out.print("Power of : ");
22+
int powerOf = input.nextInt();
23+
int output = baseNumber;
24+
for(int i=1;i<powerOf;i++){
25+
output*=baseNumber;
26+
}
27+
System.out.println(baseNumber + " power of " + powerOf + " = " + output );
28+
}
29+
}
30+
```
31+
32+
#### Output:
33+
34+
```text
35+
Base Number: 2
36+
Power of : 6
37+
2 power of 6 = 64
38+
```
39+
40+
Here we are taking two input from user and storing in a variable ```baseNumber, powerOf```. To calculating the power of a number we initialize the output variable with base number and multiplying the baseNumber in a loop for powerOf-1 times inorder to get final result.
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
---
2+
title: Java Program to calculate quotient and reminder
3+
shortTitle: Calculate Quotient and reminder
4+
description: In this program you'll learn, How you can calculate the quotient and reminder of a number (divident) by dividing a number (divisor)
5+
---
6+
7+
import {TipInfo} from '@/components/Tip'
8+
9+
To understand this example, you should have the knowledge of the following Java programming topics:
10+
11+
- [Java Operators](/docs/operators)
12+
- [Java Basic Input and Output](/docs/basic-input-output)
13+
14+
## Calculating Quotient and reminder
15+
16+
A Java program that find Quotient and Reminder is as follow:
17+
18+
```java
19+
import java.util.Scanner;
20+
public class quotient_reminder {
21+
public static void main(String[] args){
22+
int dividend, divisor;
23+
Scanner input = new Scanner(System.in);
24+
System.out.print("Enter the dividend: ");
25+
dividend = input.nextInt();
26+
System.out.print("Enter the divisor: ");
27+
divisor = input.nextInt();
28+
int quotient = dividend / divisor;
29+
int reminder = dividend % divisor;
30+
31+
System.out.println("Quotient: " + quotient + "\nReminder: " + reminder);
32+
input.close();
33+
}
34+
}
35+
```
36+
### Output 1:
37+
38+
```text
39+
Enter the dividend: 11
40+
Enter the divisor: 15
41+
Quotient: 0
42+
Reminder: 11
43+
```
44+
45+
### Output 2:
46+
```text
47+
Enter the dividend: 100
48+
Enter the divisor: 8
49+
Quotient: 12
50+
Reminder: 4
51+
```
52+
53+
To calculate the Quotient or reminder we first need two number as prerequesties among which the division operation is going to performed to calculate the Quotient or Reminder
54+
55+
Here, we are taking two input from user for some prompt and sotring these value in variable ```dividend, and divisor```. Now in order to calculate the quotient we need to divide a number (divident) by some another number (divisor) the number which we get after performing divison is we get quotient.
56+
Thus, here we perform the divison operation using ```/``` operator and storing the value in ```quotient``` variable.
57+
58+
And what about reminder ? many time the divison isn't the absolute. So inorder to calculate the reminder we are calculating it using modulas operator and storing it in ```reminder``` variable.
59+
After getting Quotient and Reminder we just printing these.
60+
61+
62+
<TipInfo>
63+
64+
Don't know how to take input from the user ? Look at [this examples](/docs/basic-input-output#java-input)
65+
66+
Here two input numbers are taken from user one after another with space in between them which distinguish between two different inputs, this useful behavior is because of the default settings of Scanner called as Delimiter, [learn more here](https://www.javatpoint.com/post/java-scanner-delimiter-method).
67+
68+
</TipInfo>

0 commit comments

Comments
 (0)