Java Saved Program: placid-af

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 s = new Scanner(System.in);
	    int m;
	    int i;
	    int j;
	    System.out.println("Upisite dimenzije kvadratne matrice od 2 do 10 redova/stupaca");
	    do
	     {
	        m=s.nextInt();
	    }
	    while(m<2||m>10);
	    double[][] P = new double[m][m];
	    for(i=0; i<m; i++)
	    {
	        for(j=0; j<m; j++)
	        {
	        P[i][j]= s.nextDouble();
	        System.out.println(P[i][j] + "\t");
	        }
	    System.out.println("\n");
	    }
	    double najveci=P[0][0];
	    double najmanji=P[0][0];
	    
//glavna dijagonala	    
	        for(i=0;i<m;i++)
	        {
	            j=i;
	            System.out.println(P[i][j]);
	            if(P[i][j]<najmanji)
	            {
	                najmanji=P[i][j];
	            }
	        }
	    
	    System.out.println(najmanji + " je najmanji");
//sporedna dijagonala
	    for(i=0;i<m;i++)
	    {
	        for(j=m-1;j>=0;j--)
	        {
	            
	            if(P[i][j]>najveci)
	            {
	                najveci=P[i][j];
	            }
	        }
	    }
	    System.out.println("najveci" + najveci);
	    
	}
}
Execute

Output

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

Inputs