Ahoj, potřebuju poradit s maticí, naplneni atd ( dvourozmerneho pole) v poradku.. snad i vim jak seradit prvky v radcich vzestupne, ale pak mi nejde ta nova matice vypsat.. navic jeste potrebuju udělat průměr z medianů řádků. Díky za pomoc začátečníkovi :)
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package pkg4_uko_matice;
import java.util.Scanner;
/**
*
* @author Notebook HP
*/
public class Main {
public static String toString(int[] pole) {
if (pole == null) {
return "Null";
}
String pom = "";
for (int i = 0; i < pole.length; i++) {
pom = pom + String.valueOf(pole[i]) + ";";
}
pom = pom.substring(0, pom.length() - 1);
return pom;
}
public static String toString(int[][] pole){
if(pole==null){
return "NULL";
}
String pom="";
for(int i=0;i<pole.length;i++){
pom=pom + toString(pole[i]) + "\n";
}
return pom;
}
public static void razenaMatice(int [][] razenaMatice){
for(int radekMatice=0;radekMatice<razenaMatice.length;radekMatice++)
for(int sloupec=0;sloupec<razenaMatice[radekMatice].length;sloupec++){
System.out.println("Matice se serazenymi radky vzestupne je: \n"+toString(razenaMatice));
}
}
public static void serazeniRadku(int [] radekMatice){
for(int i=0;i<radekMatice.length;i++){
int pom;
if(radekMatice[i-1]>radekMatice[i])
{
pom=radekMatice[i-1];
radekMatice[i-1]=radekMatice[i];
radekMatice[i]=pom;
}}
}
public static void dosazeniMatice(int [][] matice){
Scanner sc=new Scanner(System.in);
for(int i=0;i<matice.length;i++){
int radekMatice=i+1;
System.out.println("zadej "+radekMatice+".radek\n");
for(int j=0;j<matice[i].length;j++){
System.out.println("zadej cislo\n");
matice[i][j]=sc.nextInt();
}
} }
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Scanner sc=new Scanner(System.in);
System.out.println("zadej pocet radku matice, potom pocet sloupcu Matice:\n");
int radek=sc.nextInt();
int sloupec=sc.nextInt();
System.out.println("");
int [][] Matice=new int [radek][sloupec];
dosazeniMatice(Matice);
System.out.println("Matice je: \n"+toString(Matice));
System.out.println("");
int i = 0;
int [] RadekMatice=new int [i];
serazeniRadku(RadekMatice);
int radekMatice = 0;
int [][] RazenaMatice=new int [radekMatice][sloupec];
razenaMatice(RazenaMatice);
System.out.println("Matice je: \n"+toString(RazenaMatice));
}
}