Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions src/navs/program.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,7 @@ export const programsNav = {
pages['java-program-to-check-Leap-year'],
pages['calculate-simple-interest'],
pages['java-program-to-check-divisbility'],
pages['find-quotient-and-reminder'],
pages['calculate-power-of-a-number'],
],
}
40 changes: 40 additions & 0 deletions src/pages/programs/calculate-power-of-a-number.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---
title: Java Program to calculate power of a number
shortTitle: Calculate power of a number
description: In this program you'll learn, How to calculate power of a number
---

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)
- [Control Flow statement - For-Loop in Java](/docs/for-loop)
## Calculating power of a number
A java program to calculate the power of a number is as follows:

```java
public class power {
public static void main(String[] args){
java.util.Scanner input = new java.util.Scanner(System.in);
System.out.print("Base Number: ");
int baseNumber = input.nextInt();
System.out.print("Power of : ");
int powerOf = input.nextInt();
int output = baseNumber;
for(int i=1;i<powerOf;i++){
output*=baseNumber;
}
System.out.println(baseNumber + " power of " + powerOf + " = " + output );
}
}
```

#### Output:

```text
Base Number: 2
Power of : 6
2 power of 6 = 64
```

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.
68 changes: 68 additions & 0 deletions src/pages/programs/find-quotient-and-reminder.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
---
title: Java Program to calculate quotient and reminder
shortTitle: Calculate Quotient and reminder
description: In this program you'll learn, How you can calculate the quotient and reminder of a number (divident) by dividing a number (divisor)
---

import {TipInfo} from '@/components/Tip'

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)

## Calculating Quotient and reminder

A Java program that find Quotient and Reminder is as follow:

```java
import java.util.Scanner;
public class quotient_reminder {
public static void main(String[] args){
int dividend, divisor;
Scanner input = new Scanner(System.in);
System.out.print("Enter the dividend: ");
dividend = input.nextInt();
System.out.print("Enter the divisor: ");
divisor = input.nextInt();
int quotient = dividend / divisor;
int reminder = dividend % divisor;

System.out.println("Quotient: " + quotient + "\nReminder: " + reminder);
input.close();
}
}
```
### Output 1:

```text
Enter the dividend: 11
Enter the divisor: 15
Quotient: 0
Reminder: 11
```

### Output 2:
```text
Enter the dividend: 100
Enter the divisor: 8
Quotient: 12
Reminder: 4
```

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

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.
Thus, here we perform the divison operation using ```/``` operator and storing the value in ```quotient``` variable.

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.
After getting Quotient and Reminder we just printing these.


<TipInfo>

Don't know how to take input from the user ? Look at [this examples](/docs/basic-input-output#java-input)

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).

</TipInfo>