This is not running in Eclipse but ran in other jvm. Not sure if there is anything missing :(

import javax.swing.JOptionPane;
import java.io.*;

public class file1 {
static int[][] number=new int[1000][1000];;
static int row,column;

    public static void main(String[] args) {

   readFile();
   /*for(int i=0;i<row;i++)
   	for(int j=0;j<column;j++)
   		System.out.println(number[i][j]);
		*/
	String result="";

	for(int i=0;i<row;i++)
		result+="Row "+(i+1)+" Minimum value: "+findMinimum(i)+"\n";
	JOptionPane.showMessageDialog(null, result);

	JOptionPane.showMessageDialog(null, "Even numbers in array are: "+displayEven());

	JOptionPane.showMessageDialog(null, "Sum of all number is: "+getSum());
	//prints the box with dialogue minimum vale, even numbers in array 
	//and sum of all number is:  
for(int i=0;i<row;i++)
	sortRow(i);

JOptionPane.showMessageDialog(null, "After sorting each row:\n"+Print());
    }
    
    // prints the box with dialoge after sorting each row
    



private static void readFile(){

	String ver,hor,temp;
	String[] copy=new String[1000];
	int i=0,j,len=1,beg=0,end=0;

	
	try{
	FileReader fr = new FileReader("test.txt");
	BufferedReader br = new BufferedReader(fr);


		while((copy[i++] = br.readLine()) != null);
			
			fr.close();		
			i--;	
	}catch(IOException e){}
		while(copy[0].charAt(end)!=',')
			end++;
			
		ver=copy[0].substring(beg,end);
		row=Integer.parseInt(ver);
		
		beg=end;
		while(end<copy[0].length())
			end++;
		
		hor=copy[0].substring(beg+1,end);
		column=Integer.parseInt(hor);
				
		
		i=0; j=0;		
		while(i<row){
			end=0;beg=0;j=0;
			while(end<copy[i+1].length())
			{
				try{
						while(copy[i+1].charAt(end)!=','  &&  end<copy[i+1].length())
							end++;
						
						}catch(StringIndexOutOfBoundsException e){}
						
					temp=copy[i+1].substring(beg,end);
				
					number[i][j]=Integer.parseInt(temp);
					
					System.out.println(number[i][j]);
					beg=++end;
					j++;
				}
				//JOptionPane.showMessageDialog(null,"The sum is"+integers[i],"Samir",JOptionPane.WARNING_MESSAGE);	
			i++;
			}


			
}






private static int findMinimum(int row)
{
int min=0,max=0;
            for(int i=0;i<column;i++)
              if(number[row][i]>max)
                  max=number[row][i];
min=max;
            for(int i=0;i<column;i++)
                if(number[row][i]<min)
                    min=number[row][i];

return min;
}






private static String displayEven()
{
String result="";

for(int i=0;i<row;i++)
    for(int j=0;j<column;j++)
        if(number[i][j]%2==0)
            result+=number[i][j]+" ";

return result;
}






private static int getSum()
{
int result=0;

for(int i=0;i<row;i++)
    for(int j=0;j<column;j++)
        result+=number[i][j];
return result;
}






private static void sortRow(int inrow)
{
int tempo;
    for(int j=0;j<column;j++)
    for(int i=1;i<column;i++)
        if(number[inrow][i]<number[inrow][i-1])
        {
        tempo=number[inrow][i];
        number[inrow][i]=number[inrow][i-1];
        number[inrow][i-1]=tempo;
        }
}





private static String Print()
{
String result="";

for(int i=0;i<row;i++){
    for(int j=0;j<column;j++)
        result+=number[i][j]+" ";
	result+="\n";
	}

return result;
}



}

Recommended Answers

All 4 Replies

The problem may be the 2 semicolons in line 5.

if(copy[0]==null) System.out.println("DEBUGGING IS IMPORTANT");

Put that in your readFile method before the while loop.

line number please

if(copy[0]==null) System.out.println("DEBUGGING IS IMPORTANT");

Put that in your readFile method before the while loop.

after running i am getting this error messages:
Exception in thread "main" java.lang.NullPointerException
at file1.readFile(file1.java:55) **here it should be 57
at file1.main(file1.java:10)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.