Q:

Write a Java program to compute xn % y where x, y and n are all 32bit integers.

0

Expected Output:

Input x :  25
Input n :  35
Input y :  45
x^n % y = 5.0

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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); 
    }
 }

Output:

Input x :  25
Input n :  35
Input y :  45
x^n % y = 5.0

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now