Java Exercises: Compute xn % y where x, y and n are all 32bit integers
Java Basic: Exercise-204 with Solution
Write a Java program to compute xn % y where x, y and n are all 32bit integers.
Sample Solution:
Java Code:
import java.util.*;
public class Main
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
System.out.print("Input x : ");
int x = in.nextInt();
System.out.print("Input n : ");
int n = in.nextInt();
System.out.print("Input y : ");
int y = in.nextInt();
double result = Math.pow(x, n);
double result1 = result % y;
System.out.println("x^n % y = " + result1);
}
}
Sample Output:
Input x : 25 Input n : 35 Input y : 45 x^n % y = 5.0
Flowchart:
Java Code Editor:
Contribute your code and comments through Disqus.
Previous: Write a Java program to find the contiguous subarray of given length k which has the maximum average value of a given array of integers. Display the maximum average value.
Next: Write a Java program to check whether an given integer is power of 2 or not using O(1) time.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
Java: Tips of the Day
How to sort an ArrayList?
Collections.sort(testList); Collections.reverse(testList);
That will do what you want. Remember to import Collections though!
Ref: https://bit.ly/32urdSe
- New Content published on w3resource:
- HTML-CSS Practical: Exercises, Practice, Solution
- Java Regular Expression: Exercises, Practice, Solution
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework