/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package matriz;
import java.io.*;
import java.util.*;
/**
*
* @author xxx
*/
public class matrizhori {
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws FileNotFoundException, IOException {
Scanner sn = new Scanner (new File ("in3.txt"));
FileOutputStream fos = new FileOutputStream ("out3.txt");
PrintStream ps = new PrintStream (fos);
int n = sn.nextInt();
int matriz [ ] [ ] = new int [n] [n];
for(int i=0;i<=n-1;i++){
for (int j=0;j<=n-1;j++){
matriz [i] [j] = sn.nextInt();
System.out.print(matriz [i] [j] + " " );
ps.print(matriz [i] [j] + " " );
}
System.out.println();
ps.println();
}
for(int i=0;i<=n-1;i++){
int suma = 0;
for (int j=0;j<=n-1;j++){
suma= suma + matriz [i] [j];
}
System.out.println( );
System.out.print(suma + " ");
ps.print(suma + " ");
}
// TODO code application logic here
//suma de columnas horizontalmente
}
}
ayuda psicologica
jueves, 9 de diciembre de 2010
multiplicacion 2a * 3b
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package matriz;
import java.io.*;
import java.util.*;
/**
*
* @author xxx
*/
public class matriz2a3b {
public static void main(String[] args) throws FileNotFoundException, IOException {
Scanner sn = new Scanner (new File ("in2.txt"));
FileOutputStream fos = new FileOutputStream ("out2.txt");
PrintStream ps = new PrintStream (fos);
int n = sn.nextInt();
int a [ ] [ ] = new int [n] [n];
int b [ ] [ ] = new int [n] [n];
int c [ ] [ ] = new int [n] [n];
for (int i=0;i<=n-1;i++){
for (int j=0;j<=n-1;j++){
a [i] [j] = sn.nextInt();
}
}
for (int i=0;i<=n-1;i++){
for (int j=0;j<=n-1;j++){
b [i] [j] = sn.nextInt();
}
}
for (int i=0;i<=n-1;i++){
for (int j=0;j<=n-1;j++){
c [i] [j]=0;
c [i] [j]= (2* a [i] [j]) - (3 * b [i] [j]);
System.out.print(c [i] [j]+ " ");
ps.print(c [i] [j]+ " ");
}
System.out.println();
ps.println();
}
}
}
//multiplicacion 2a * 3b
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package matriz;
import java.io.*;
import java.util.*;
/**
*
* @author xxx
*/
public class matriz2a3b {
public static void main(String[] args) throws FileNotFoundException, IOException {
Scanner sn = new Scanner (new File ("in2.txt"));
FileOutputStream fos = new FileOutputStream ("out2.txt");
PrintStream ps = new PrintStream (fos);
int n = sn.nextInt();
int a [ ] [ ] = new int [n] [n];
int b [ ] [ ] = new int [n] [n];
int c [ ] [ ] = new int [n] [n];
for (int i=0;i<=n-1;i++){
for (int j=0;j<=n-1;j++){
a [i] [j] = sn.nextInt();
}
}
for (int i=0;i<=n-1;i++){
for (int j=0;j<=n-1;j++){
b [i] [j] = sn.nextInt();
}
}
for (int i=0;i<=n-1;i++){
for (int j=0;j<=n-1;j++){
c [i] [j]=0;
c [i] [j]= (2* a [i] [j]) - (3 * b [i] [j]);
System.out.print(c [i] [j]+ " ");
ps.print(c [i] [j]+ " ");
}
System.out.println();
ps.println();
}
}
}
//multiplicacion 2a * 3b
multiplicacion de 2 matrices
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package matriz;
import java.io.*;
import java.util.*;
/**
*
* @author xxx
*/
public class multiplicamatriz {
public static void main(String[] args) throws FileNotFoundException, IOException {
Scanner sn = new Scanner (new File ("in1.txt"));
FileOutputStream fos = new FileOutputStream ("out1.txt");
PrintStream ps = new PrintStream (fos);
int n = sn.nextInt();
int a [ ] [ ] = new int [n] [n];
int b [ ] [ ] = new int [n] [n];
int c [ ] [ ] = new int [n] [n];
for(int i=0;i<=n-1;i++){
for(int j=0;j<=n-1;j++){
a [i] [j] = sn.nextInt();
//ps.print(a [i] [j] + " ");
}
//ps.println();
}
for(int i=0;i<=n-1;i++){
for(int j=0;j<=n-1;j++){
b [i] [j] = sn.nextInt();
// ps.print(b [i] [j] + " ");
}
//ps.println();
}
for (int i=0;i<=n-1;i++){
for (int j=0;j<=n-1;j++){
c [i] [j]=0;
for (int k=0;k<=n-1;k++){
c [i] [j]+= a [i] [k] * b [k] [j];
}
}
}
for (int i=0;i<=n-1;i++){
for (int j=0;j<=n-1;j++){
System.out.print (c [i] [j] + " ");
ps.print(c [i][j] + " ");
}
ps.println();
System.out.println();
}
}
}
//multiplicacion de 2 matrices
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package matriz;
import java.io.*;
import java.util.*;
/**
*
* @author xxx
*/
public class multiplicamatriz {
public static void main(String[] args) throws FileNotFoundException, IOException {
Scanner sn = new Scanner (new File ("in1.txt"));
FileOutputStream fos = new FileOutputStream ("out1.txt");
PrintStream ps = new PrintStream (fos);
int n = sn.nextInt();
int a [ ] [ ] = new int [n] [n];
int b [ ] [ ] = new int [n] [n];
int c [ ] [ ] = new int [n] [n];
for(int i=0;i<=n-1;i++){
for(int j=0;j<=n-1;j++){
a [i] [j] = sn.nextInt();
//ps.print(a [i] [j] + " ");
}
//ps.println();
}
for(int i=0;i<=n-1;i++){
for(int j=0;j<=n-1;j++){
b [i] [j] = sn.nextInt();
// ps.print(b [i] [j] + " ");
}
//ps.println();
}
for (int i=0;i<=n-1;i++){
for (int j=0;j<=n-1;j++){
c [i] [j]=0;
for (int k=0;k<=n-1;k++){
c [i] [j]+= a [i] [k] * b [k] [j];
}
}
}
for (int i=0;i<=n-1;i++){
for (int j=0;j<=n-1;j++){
System.out.print (c [i] [j] + " ");
ps.print(c [i][j] + " ");
}
ps.println();
System.out.println();
}
}
}
//multiplicacion de 2 matrices
suma de columnas verticalmente
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package matriz;
import java.io.*;
import java.util.*;
/**
*
* @author xxx
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws FileNotFoundException, IOException {
Scanner sn = new Scanner (new File ("in.txt"));
FileOutputStream fos = new FileOutputStream ("out.txt");
PrintStream ps = new PrintStream (fos);
int n = sn.nextInt();
int matriz [ ] [ ] = new int [n] [n];
for(int i=0;i<=n-1;i++){
for (int j=0;j<=n-1;j++){
matriz [i] [j] = sn.nextInt();
System.out.print(matriz [i] [j] + " " );
ps.print(matriz [i] [j] + " " );
}
System.out.println();
ps.println();
}
for(int i=0;i<=n-1;i++){
int suma = 0;
for (int j=0;j<=n-1;j++){
suma= suma + matriz [j] [i];
}
System.out.println( );
System.out.print(suma + " ");
ps.print(suma + " ");
}
// TODO code application logic here
//suma de columnas verticalmente
}
}
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package matriz;
import java.io.*;
import java.util.*;
/**
*
* @author xxx
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws FileNotFoundException, IOException {
Scanner sn = new Scanner (new File ("in.txt"));
FileOutputStream fos = new FileOutputStream ("out.txt");
PrintStream ps = new PrintStream (fos);
int n = sn.nextInt();
int matriz [ ] [ ] = new int [n] [n];
for(int i=0;i<=n-1;i++){
for (int j=0;j<=n-1;j++){
matriz [i] [j] = sn.nextInt();
System.out.print(matriz [i] [j] + " " );
ps.print(matriz [i] [j] + " " );
}
System.out.println();
ps.println();
}
for(int i=0;i<=n-1;i++){
int suma = 0;
for (int j=0;j<=n-1;j++){
suma= suma + matriz [j] [i];
}
System.out.println( );
System.out.print(suma + " ");
ps.print(suma + " ");
}
// TODO code application logic here
//suma de columnas verticalmente
}
}
jueves, 2 de diciembre de 2010
menor triangulo inferior
/*
* triangulosuma.java
*
* Created on 23 de noviembre de 2010, 03:36 PM
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package archivo;
import java.io.*;
import java.util.*;
/**
*
* @author Ari
*/
public class triangulosuma
{
/** Creates a new instance of triangulosuma */
public static void main(String[]args) throws FileNotFoundException, IOException
{
Scanner sn = new Scanner(new File("in1.txt"));
FileOutputStream fos = new FileOutputStream("out1.txt");
PrintStream ps = new PrintStream(fos);
int n=sn.nextInt();
int m[][]=new int [n][n];
for(int i=0;i<=n-1;i++)
{for (int j=0;j<=n-1;j++)
{
m[i][j]=sn.nextInt();
}
}
int menor= m[1][0]; //2
int aux;
for(int i=n-1;i<=n-1;i++) //2
{
for (int j=0;j<=1;j++) //0
{
aux=m[i][j]; //1
if(menor>aux) // compara 2>1
menor=aux; // menor:1
}
}
System.out.println(menor);
}
}
* triangulosuma.java
*
* Created on 23 de noviembre de 2010, 03:36 PM
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package archivo;
import java.io.*;
import java.util.*;
/**
*
* @author Ari
*/
public class triangulosuma
{
/** Creates a new instance of triangulosuma */
public static void main(String[]args) throws FileNotFoundException, IOException
{
Scanner sn = new Scanner(new File("in1.txt"));
FileOutputStream fos = new FileOutputStream("out1.txt");
PrintStream ps = new PrintStream(fos);
int n=sn.nextInt();
int m[][]=new int [n][n];
for(int i=0;i<=n-1;i++)
{for (int j=0;j<=n-1;j++)
{
m[i][j]=sn.nextInt();
}
}
int menor= m[1][0]; //2
int aux;
for(int i=n-1;i<=n-1;i++) //2
{
for (int j=0;j<=1;j++) //0
{
aux=m[i][j]; //1
if(menor>aux) // compara 2>1
menor=aux; // menor:1
}
}
System.out.println(menor);
}
}
Cuadrado de la diagonal de una matriz
/*
* matriz.java
*
* Created on 23 de noviembre de 2010, 02:44 PM
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package archivo;
import java.io.*;
import java.util.*;
*/
public class matriz {
/** Creates a new instance of matriz */
public static void main(String[]args) throws FileNotFoundException,IOException // Funcion
{
Scanner sc= new Scanner(new File ("in.txt")); //Lee el archivo
FileOutputStream fos = new FileOutputStream("out.txt"); //Crea Nombre del Archivo donde se va a guardar
PrintStream ps= new PrintStream(fos); // Guardar en el archivo.
int n=sc.nextInt(); // Lee la primera linea del archivo
int m[][]= new int [n][n]; //Se guarda en una matriz con el tamaño de n
for (int i=0;i<=n-1;i++) // los 2 for llenan la matriz i es fila y j es columna
{for(int j=0;j<=n-1;j++)
{ m[i][j]=sc.nextInt(); //Lee los numeros y descarta los espacios entrenumeros
// System.out.println(m[i][j]);
}
}
for (int i=0;i<=n-1;i++) //Visualizacion
{for(int j=0;j<=n-1;j++)
{ //m[i][j]=sc.nextInt();
System.out.print(m[i][j]+" "); // se manda al archivo
ps.print(m[i][j]+" ");
}
ps.println();
System.out.println();
}
int x,y,z;
x=m[0][0];
y=m[1][1];
z=m[2][2];
System.out.print((int)Math.pow(x,2)+" "+(int)Math.pow(y,2)+" "+(int)Math.pow(z,2));
ps.print((int)Math.pow(x,2)+" "+(int)Math.pow(y,2)+" "+(int)Math.pow(z,2));
System.out.println();
}
}
* matriz.java
*
* Created on 23 de noviembre de 2010, 02:44 PM
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package archivo;
import java.io.*;
import java.util.*;
*/
public class matriz {
/** Creates a new instance of matriz */
public static void main(String[]args) throws FileNotFoundException,IOException // Funcion
{
Scanner sc= new Scanner(new File ("in.txt")); //Lee el archivo
FileOutputStream fos = new FileOutputStream("out.txt"); //Crea Nombre del Archivo donde se va a guardar
PrintStream ps= new PrintStream(fos); // Guardar en el archivo.
int n=sc.nextInt(); // Lee la primera linea del archivo
int m[][]= new int [n][n]; //Se guarda en una matriz con el tamaño de n
for (int i=0;i<=n-1;i++) // los 2 for llenan la matriz i es fila y j es columna
{for(int j=0;j<=n-1;j++)
{ m[i][j]=sc.nextInt(); //Lee los numeros y descarta los espacios entrenumeros
// System.out.println(m[i][j]);
}
}
for (int i=0;i<=n-1;i++) //Visualizacion
{for(int j=0;j<=n-1;j++)
{ //m[i][j]=sc.nextInt();
System.out.print(m[i][j]+" "); // se manda al archivo
ps.print(m[i][j]+" ");
}
ps.println();
System.out.println();
}
int x,y,z;
x=m[0][0];
y=m[1][1];
z=m[2][2];
System.out.print((int)Math.pow(x,2)+" "+(int)Math.pow(y,2)+" "+(int)Math.pow(z,2));
ps.print((int)Math.pow(x,2)+" "+(int)Math.pow(y,2)+" "+(int)Math.pow(z,2));
System.out.println();
}
}
Llenado de matrices // suma de matriz en diagonal
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package matriz2;
import java.io.*;
import java.util.*;
/**
*
* @author xxx
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws FileNotFoundException, IOException {
Scanner sn= new Scanner (new File ("in.txt")); //crea archivo //escaner crea y lee
FileOutputStream fos= new FileOutputStream ("out.txt"); //crea y envia un archivo de salida
PrintStream ps = new PrintStream (fos); // imprime lo q se tiene en fos fos= out.txt
int comida = sn.nextInt(); // lee primer valor
int salsa [] [] = new int [comida] [comida]; //crea una matriz
for (int i=0;i<=comida-1;i++){
for (int j=0;j<=comida-1;j++){
salsa [i] [j] =sn.nextInt();
System.out.print (salsa [i] [j]);
ps.print(salsa [i] [j]);
}
System.out.println();
ps.println();
}
//suma de matriz // suma diagonal
int x,y,z;
x= salsa [0] [0];
y= salsa [1] [1];
z= salsa [2] [2];
System.out.print(x+y+z);
ps.print(x+y+z);
}
}
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package matriz2;
import java.io.*;
import java.util.*;
/**
*
* @author xxx
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws FileNotFoundException, IOException {
Scanner sn= new Scanner (new File ("in.txt")); //crea archivo //escaner crea y lee
FileOutputStream fos= new FileOutputStream ("out.txt"); //crea y envia un archivo de salida
PrintStream ps = new PrintStream (fos); // imprime lo q se tiene en fos fos= out.txt
int comida = sn.nextInt(); // lee primer valor
int salsa [] [] = new int [comida] [comida]; //crea una matriz
for (int i=0;i<=comida-1;i++){
for (int j=0;j<=comida-1;j++){
salsa [i] [j] =sn.nextInt();
System.out.print (salsa [i] [j]);
ps.print(salsa [i] [j]);
}
System.out.println();
ps.println();
}
//suma de matriz // suma diagonal
int x,y,z;
x= salsa [0] [0];
y= salsa [1] [1];
z= salsa [2] [2];
System.out.print(x+y+z);
ps.print(x+y+z);
}
}
Suscribirse a:
Comentarios (Atom)