Related questions
Convert the following java code to C++
//LabProgram.java
import java.util.Scanner;
public class LabProgram {
public static void main(String[] args) {
//defining a Scanner to read input from the user
Scanner input = new Scanner(System.in);
//reading the value for N
int N = input.nextInt();
//creating a 1xN matrix
int[] m1 = new int[N];
//creating an NxN matrix
int[][] m2 = new int[N][N];
//creating a 1xN matrix to store the result
int[] result = new int[N];
//looping and reading N integers into m1
for (int i = 0; i < N; i++) {
m1[i] = input.nextInt();
}
//looping from 0 to N-1
for (int i = 0; i < N; i++) {
//looping from 0 to N-1
for (int j = 0; j < N; j++) {
//reading an integer and storing it into m2 at position i,j
m2[i][j] = input.nextInt();
}
}
//multiply m1 and m2, store result in result
//looping from 0 to N-1
for (int i = 0; i < N; i++) {
//looping from 0 to N-1
for (int j = 0; j < N; j++) {
//multiplying value at index j in m1 with value at j,i in m2, adding to current value at index i
// on result
result[i] += m1[j] * m2[j][i];
}
}
//print result
for (int i = 0; i < N; i++) {
//printing value at index i in result, followed by a space
System.out.print(result[i] + " ");
}
//ending with a newline
System.out.println();
}
}
Step by stepSolved in 4 steps with 1 images
- Java - Write a program that removes all non alpha characters from the given input.arrow_forward*JAVA* complete method Delete the largest valueremoveMax(); Delete the smallest valueremoveMin(); class BinarHeap<T> { int root; static int[] arr; static int size; public BinarHeap() { arr = new int[50]; size = 0; } public void insert(int val) { arr[++size] = val; bubbleUP(size); } public void bubbleUP(int i) { int parent = (i) / 2; while (i > 1 && arr[parent] > arr[i]) { int temp = arr[parent]; arr[parent] = arr[i]; arr[i] = temp; i = parent; } } public int retMin() { return arr[1]; } public void removeMin() { } public void removeMax() { } public void print() { for (int i = 0; i <= size; i++) { System.out.print( arr[i] + " "); } }} public class BinarH { public static void main(String[] args) { BinarHeap Heap1 = new BinarHeap();...arrow_forwardpublic class Main { static int findPosSum(int A[], int N) { if (N <= 0) return 0; { if(A[N-1]>0) return (findPosSum(A, N - 1) + A[N - 1]); else return findPosSum(A, N - 1); } } public static void main(String[] args) { int demo[] = { 11, -22, 33, -4, 25,12 }; System.out.println(findPosSum(demo, demo.length)); } } Consider the recursive function you wrote in the previous problem. Suppose the initial call to the function has an array of N elements, how many recursive calls will be made? How many statements are executed in each call? What is the total number of statements executed for all recursive calls? What is the big O for this function?arrow_forward
- I need help with this code !! import java.util.Arrays;import java.util.Scanner; public class MaxElement {public static void main(String[] args) { //create an object for Scanner class Scanner x = new Scanner (System.in);System.out.print ("Enter 10 integers: ");// create an arrayInteger[] arr = new Integer[10]; // Execute for loopfor (int i = 0; i < arr.length; i++) {//get the 10 integersarr[i] = x.nextInt(); } // Print the maximum numberSystem.out.print("The max number is = " + max(arr));System.out.print("\n"); } //max method public static <E extends Comparable<E>> E max(E[] arr) {E max = arr[0]; // Execute for loop for (int i = 1; i < arr.length; i++) { E element = arr[i];if (element.compareTo(max) > 0) {max = element;}}return max; }}arrow_forwardFind error #include<bits/stdc++.h> using namespace std; class Solution{ public: bool isPossible(vector<int>ank,int n,int mid) { int count=0; for(int i=0;i<rank.size()) { int val= (-1 + sqrt(1+(8*mid)/rank[i]))/2; count+=val; } return count>=n; } int findMinTime(int N, vector<int>&A, int L){ int low=*min_element(A.end()),high=1000000; int ans=high; while(low<=high) { int mid=low+(high)/2; if(isPossible(A,mid)) { ans=mid; high=mid; } else low=mid; } return ans; } }; int main() { int t; cin>>t; while(t--) { int l; cin >> l; vector<int>arr(l); for(int i = 0; i < l; i++){ cin >> arr[i]; } Solution ob; int ans = ob.findMin(n, *arr, l); cout...arrow_forwardCorrect my codes in java // Arraysimport java.util.Scanner;public class Assignment1 {public static void main (String args[]){Scanner sc=new Scanner (System.in);System.out.println("Enter mark of student");int n=sc.nextInt();int a[]=new int [n];int i;for(i=0;i<n;i++){System.out.println("Total marks of student in smster");a[i]=sc.nextInt();}int sum=0;for(i=0;i<n;i++){sum=sum+a[i];}System.out.println("Total marks is :");for (i=0;i<n;i++);{System.out.println(a[i]);}System.out.println();}}arrow_forward
- Define the method findHighestValue() with a Scanner parameter that reads integers from input until a negative integer is read. The method returns the largest of the integers read. Ex: If the input is 70 65 100 -85 -15 -50, then the output is: 100Note: Negative numbers are less than 0. import java.util.Scanner; public class HighestValueFinder { public static void main(String[] args) { Scanner scnr = new Scanner(System.in); int maxVal; maxVal = findHighestValue(scnr); System.out.println(maxVal); }}arrow_forwardpublic class arrayOutput ( public static void main (String [] args) { final int NUM ELEMENTS = 3; int[] userVals = new int [NUM_ELEMENTS]; int i; } Type the program's output userVals [0] = 2; userVals [1] = 6; userVals [2] = 8; for (i = userVals.length - 1; i>= 0; −−1) { System.out.println(userVals [1]); } C.C. ? ? ??arrow_forwardConsider the following method. /** Postcondition: m is displayed in a rectangular matrix for example: 1 2 3 4 5 6 7 8 public static void displayMatrix (int [] [] m) for (int r = 0; r < m.length; r++) for (int c = 0; c < m.length; c++) System.out.print (m[r] [c] + " "); System.out.println (); Will method displayMatrixsatisfy its postcondition? Yes, but only if the row-size and col-size are identical, No, all the numbers will display in one column. Yes, all the numbers will display in a correct rectangular display. No, because the code will generate an IndexArrayoutofBoundsException error. No, all the numbers will display in one row. ОООО Оarrow_forward
- write the output due to c code given in imagearrow_forwardMy issue: I don't know how to shift left after swapping arrays. My code: import java.util.Scanner;public class StudentScores {public static void main (String [] args) {Scanner scnr = new Scanner(System.in);final int SCORES_SIZE = 4;int[] oldScores = new int[SCORES_SIZE];int[] newScores = new int[SCORES_SIZE];int i; for (i = 0; i < oldScores.length; ++i) {oldScores[i] = scnr.nextInt();} /* Your solution goes here */for (i=0; i < oldScores.length; i++) {newScores[i]= oldScores[i];}// student code ends here for (i = 0; i < newScores.length; ++i) {System.out.print(newScores[i] + " ");}System.out.println();}}arrow_forwardS09...arrow_forward
- Text book imageDatabase System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationText book imageStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONText book imageDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- Text book imageC How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONText book imageDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningText book imageProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education