Can you change this code into java code
#include <iostream>
using namespace std;
int countReflexive(int n){
int ans = 1 << (n*n - n);
return ans;
}
int main(){
int n ;
cin >> n ; // taking input n from the user using std cin.
int result = countReflexive(n); // calling function to calculate number of reflexive relations
cout << "Number of reflexive relations on set: " << result ; // printing the answer
return 0;
}
import java.util.Scanner;
class Main {
static int countReflexive(int n){
int ans = 1 << (n*n - n);
return ans;
}
public static void main(String[] args) {
Scanner keyBoard = new Scanner(System.in);
int n ;
n =keyBoard.nextInt(); // taking input n from the user using std cin.
int result = countReflexive(n); // calling function to calculate number of reflexive relations
System.out.println("Number of reflexive relations on set: " + result); // printing the answer
keyBoard.close();
}
}
Comments
Leave a comment