Java Saved Program: beautiful-dog

facebook share

Here's the online compiler accompanied with IDE at your service. This is a saved code by one of our users. Try it out or save your own from the IDE page and don't forget to leave a feedback. You can find that at the bottom of the page.


import java.util.*;
import java.lang.*;
import java.io.*;
import java.util.Scanner;
/* Name of the class has to be "Script" only */
class Script
{
	public static void main (String[] args)
	{
	    Scanner skener = new Scanner(System.in);
	    int matrica = 1;
	    int[] m = new int[2];
	    int[] n = new int[2];
	    float maxNum;
	    float minNum;
	    float sumFirstMatrica = 0F;
	    float sumSecondMatrica = 0F;
	    float firstColumn = 0F;
	    int x;
	    float product = 1F;
	    
	    while(matrica<3)
	    {
	    System.out.println("Unesite dimenzije " + matrica + ". matrice");
	    System.out.println("Unesite broj stupaca " + matrica + ". matrice");
	    do
	    {
	    m[matrica-1] = skener.nextInt();
	    }while(m[matrica-1]<0 || m[matrica-1]>11);
	    
	    System.out.println("Unesite broj redaka " + matrica + ". matrice");
	    do
	    {
	    n[matrica-1] = skener.nextInt();
	    }while(n[matrica-1]<0 || n[matrica-1]>11);
	    matrica++;
	    }
	    
	    float[][] polja1 = new float[m[0]][n[0]];
	    float[][] polja2 = new float[m[1]][n[1]];

	    System.out.println("Unesite vrijednosti elemenata u 1. matricu");
	    for(int i=0; i<m[0]; i++)
	    {
	        for(int j=0; j<n[0]; j++)
	        {
	            System.out.println("Element " + (i+1) + " stupca " + (j+1) + " retka");
	            polja1[i][j] = skener.nextFloat();
	            sumFirstMatrica += polja1[i][j];
	        }
	    }
	    
	    System.out.println("Unesite vrijednosti elemenata u 2. matricu");
	    for(int i=0; i<m[1]; i++)
	    {
	        for(int j=0; j<n[1]; j++)
	        {
	            System.out.println("Element " + (i+1) + " stupca " + (j+1) + " retka");
	            polja2[i][j] = skener.nextFloat();
	            sumSecondMatrica += polja2[i][j];
	        }
	    }
	    
	    System.out.println("Razlika prve i druge matrice: " + (sumFirstMatrica-sumSecondMatrica));
	    

	    for(int j=0; j<n[1]; j++)
	    {
	        firstColumn += polja1[0][j];
        }

	    System.out.println("Suma prvog stupca marice: " + firstColumn);
	    
	    System.out.println("Unesite redak druge matrice za mnozenje: ");
	    x = skener.nextInt();
	    for(int i=0; i<m[1]; i++)
	    {
	        product *= polja2[i][x-1];
	    }
	    System.out.println("Umnozak " + x + ". retka: " + product);
	    
	    
	}
	
}
Execute

Output

Press the execute button or CTRL + enter to run code.

Inputs