Can you change the code into java code?
def reflexive(R):
'''
@param R : set containing homogenous elements
'''
result = []
a = []
y = []
for a1, a2 in R:
if (a1 == a2):
result.append((a1,a2))
y.append(a1)
if (a1 not in a):
a.append(a1) #contains list of a0
if (set(a) == set(y)):
print("Reflexive")
return (result, True)
print("Not Reflexive")
return ([] , False)
How to determine the set is transitive using java code?
In a super market Mr. Amir has purchased 3 quantities of the same item. The bill is computed using the below formula Bill = quantity * price per item Requirements: a) The quantity and price per item has to be captured b) The bill has to be computed using the above formula c) Bill has to displayed
Write a method called isIdentityMatrix which will take a two-dimensional integer
array as argument, and returns true if the array is an identity matrix, or false otherwise.
You may use the following header for this method:
static boolean isIdentityMatrix(int[][] array)
A matrix is an identity matrix if it is a square matrix, and all its elements at the left
diagonal are ones, and all other elements are zeroes.
For example, the following matrix is an identity matrix and the method should return true
if we pass it to the isIdentityMatrix matrix as two-dimensional:
1 0 0 0 0
0 1 0 0 0
0 0 1 0 0
0 0 0 1 0
0 0 0 0 1
For the following two-dimensional array, the method should return false because there
are some non-zero elements in the matrix.
1 0 0 5 0
0 1 0 2 0
0 3 1 0 0
0 0 0 1 5
0 5 0 0 1
Similarly, for the following two-dimensional array, the method should return false
because some elements at left diagonal are not ones.
1 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 1 0
0 0 0 0 1
Write a method called addMatrices which will take two matrices (two-dimensional
integer arrays) as argument, and returns the addition of these two matrices as a two-
dimensional integer array.
You may use the following header for this method:
static int[][] addMatrices(int[][] firstMatrix,
int[][] secondMatrix)
For example, if we pass the following two two-dimensional arrays to the method:
5 7 9 4 3 7 3 2 1 5
2 3 9 7 6 3 9 4 0 3
3 6 8 7 9 6 2 8 9 4
1 9 7 5 6 5 0 3 8 7
3 8 7 9 2 1 6 8 4 3
Then the method should return the following two-dimensional array:
12 10 11 5 8
5 12 13 7 9
9 8 16 16 13
6 9 10 13 13
4 14 15 13 5
2. Write a method called printArray that takes a two-dimensional integer array as
argument and prints all elements of array. The method should print each row line by line.
You may use the following header for this method:
static void printArray(int[][] array)
In the main method:
Declare and initialize two two-dimensional arrays.
Pass these two-dimensional arrays to addMatrices()method..
In this task, you are being asked to write methods that manipulate arrays in Java.
1. Write a method called swapFirstAndLastRow which will take a two-dimensional
integer array as argument and swap all the values of first row and last row with each
other.
You may use the following header for this method:
static void swapFirstAndLastRow(int[][] array)
For example, if we pass the following two-dimensional array to this method:
5 7 9 4 3 1
2 4 9 7 6 5
3 6 8 7 9 4
1 9 7 5 6 3
Then the array will become:
1 9 7 5 6 3
2 4 9 7 6 5
3 6 8 7 9 4
5 7 9 4 3 1
2. Write a third method called printArray which will take a two-dimensional integer
array as argument and prints all elements of array. The method should print each row line
by line.
You may use the following header for this method:
static void printArray (int[][] array)
Take two numbers from the user as the size of rows and columns of the array and call the
methods in the following order:
printArray()
swapFirstAndLastRow()
printArray
Please how can I insert public class in this code to run?
Help me check and debug for me
package ArrayList
import java.until.ArrayList;
import java.until.Scanner;
public class Groceries {
public static void main (String[] args); {
Scanner s = new Scanner (System.in);
ArrayList<String> Groceries = ArrayList();
groceries.add ("Apple");
groceries.add ("Milk");
groceries.add ("Bread");
groceries.add ("Chocolate");
groceries.add ("Sugar");
System.out.PrintIn("what groceries do you want to add?");
String input_groceries = s.nextLine();
groceries.add(input_groceries);
System.out.PrintIn("Here are your groceries: ");
for (int i = 0; i < groceries.size(); i++) {
{
System.out.printIn(groceries.get(i));
}
}
}
how to determine transitive relation into java program
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;
}
batchCodes,
testsDone, positiveResults) to your source code.
2. Invoke the testsDoneInWeek() method to determine the
number of tests that was done in week 2 of month 3.
3. Display an appropriate message with the number of tests done
in this week.
4. Invoke the highestPercentage() method to determine the
month and week with the highest percentage of positive cases.
a. You must first invoke the percentagePositives() method
to generate a double array with the percentages of
positive cases per week.
b. This is one of the arguments needed for invoking the
percentagePositives() method.
5. Display an appropriate message with the indication of which
batch had the highest percentage positive cases.
highestPercentage(String[], double[]) The method receives as parameters the batch codes array as well as the ar