Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: My Code has no output

  1. #1
    Junior Member
    Join Date
    Feb 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default My Code has no output

    i need help with my code its intended to read from a file and take data and assign the first two numbers it reads as the size of the matrix, then i need it to display a matrix that assigns a number to a certain location in the matrix. IT MUST BE IN METHODS

    i want it to read from a .dat file in the format of the following:

    10 10
    2 3 5
    2 8 1
    1 9 2
    0 1 8

    I want the out put to be:

    0 0 0 0 0 0 0 0 0 0
    0 8 0 0 0 0 0 0 0 2
    0 0 0 5 0 0 0 0 1 0
    0 0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0 0




     
    import java.util.Scanner;
    import java.io.*;
     
    class lab16a
    {
    	int[][] rix;
    	public void size(int rows, int cols)
    	{
    		rix = new int[rows][cols];
    		return;
    	}
    	int rowsets,colsets,saves;
    	public void store(int rowsets, int colsets, int saves)
    	{
    		rix[rowsets][colsets]=saves;
    		return;
    	}
    	public void show()
    	{
    		for(int rowcount=0;rowcount<rix.length; rowcount++)
    			{
    				for(int part=0;part<rix[rowcount].length;part++)
    				{
    					System.out.print(rix[rowcount][part]+" ");	
    				}
    				System.out.println();
    			}
    	}
    	public static void main (String[] args) throws FileNotFoundException
    	{
    		lab16a Run = new lab16a();
    		Scanner loc = new Scanner (System.in);
    		System.out.println("Input File Location");
    		String File = loc.next();	
    		loc = new Scanner (new File (File));
    		int row=loc.nextInt();
    		int	col=loc.nextInt();
    		Run.size(row,col);
    		while(loc.hasNext())
    		{
    			int rowset=loc.nextInt();
    			int colset=loc.nextInt();
    			int save=loc.nextInt();
    			Run.store(rowset,colset,save);
     
    		}
                    Run.show();
    	}
     
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,067
    Thanks
    47
    Thanked 2,146 Times in 2,119 Posts

    Default Re: My Code has no output

    Can you explain what problems you are having and ask some specific questions about them?

    Please edit your post and wrap your code with
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Feb 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: My Code has no output

    when i run the program i insert the file location and then it just completes the process and it doesnt show the matrix at all. why does the code not have an out put cause i ask it to output in the show method ?

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,067
    Thanks
    47
    Thanked 2,146 Times in 2,119 Posts

    Default Re: My Code has no output

    Where does the code call the show() method? A method won't be executed unless it is called.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Feb 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: My Code has no output

    I don't understand what you mean in your question, sorry but i am new at this and my teacher said that if i write the method it will work so what should i do different

    --- Update ---

    oh okay thank you i figured it out after a min of thinking about what you said i commanded a "Run.show();" 2 } at the bottom of my main method

Similar Threads

  1. What does this code output?
    By rickjames8710 in forum Java Theory & Questions
    Replies: 4
    Last Post: January 14th, 2012, 10:06 PM
  2. My code runs forever without output
    By jbinsomnia in forum What's Wrong With My Code?
    Replies: 6
    Last Post: October 8th, 2011, 07:53 AM
  3. No Error in Code but Output is not desired...!!!
    By Adi in forum What's Wrong With My Code?
    Replies: 1
    Last Post: August 28th, 2011, 08:56 AM
  4. output to a specific location in html code
    By aketr in forum What's Wrong With My Code?
    Replies: 1
    Last Post: July 15th, 2011, 11:44 AM
  5. [SOLVED] Code is correct, but incorrect output?
    By moodycrab3 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: February 6th, 2011, 01:32 PM

Tags for this Thread