View Single Post
Old Apr 8th, 2005, 11:58 AM   #7
xavier
Professional Programmer
 
xavier's Avatar
 
Join Date: Oct 2004
Location: .ro
Posts: 383
Rep Power: 4 xavier is on a distinguished road
Send a message via Yahoo to xavier
I know, i'm slow .. but i haven't got the time to think about it. Here it is:
import java.io.*;

class matrix {
	public static void main(String args[]){
		BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
		
                int n=3;


		int a[][]=new int[3][3];
		int i=0;  //row
		int j=0;  //colomn
		int step=1; // used when under the main diagonal
		int pas=0;  // used when above the main diagonal
		

		for(;;){
			if(pas<=n-1){
				i=0;
				j=n-1-pas;

				do{
					try{
						String s=in.readLine();
						int x=Integer.parseInt(s);
                               //see if the index is working
						System.out.println("i="+i+" "+"j="+j);

						a[i][j]=x;
						i++;
						j++;
						}
					catch(IOException e){e.printStackTrace();}
				}while(i<=pas);
				pas++;
			}

			if(pas>n-1){
				i=step;
				j=0;

				do{
					try{
						String s=in.readLine();
						int x=Integer.parseInt(s);
                               //see if the index is working
					System.out.println("i="+i+" "+"j="+j);
					a[i][j]=x;
					i++;
					j++;

					}catch(IOException e){e.printStackTrace();}
				}while(i<=n-1);
				step++;
			}
		if((step>n-1))break;
		}
//see if it worked :)
	for(i=0;i<n;i++){
		for(j=0;j<n;j++){
			System.out.print(a[i][j]);}
	System.out.println();}
}
}
__________________
Don't take life too seriously, it's not permanent !
xavier is offline   Reply With Quote