Results 1 to 16 of 16
  1. #1
    Join Date
    Jun 2008
    Posts
    54
    Rep Power
    0

    Default initialising an array

    Hello,
    i have the problem, that i have to read in lines from a text document into an array. I know how to write it, but my main problem is, that one line says 1*0 and so i don't know how i have to initialise the array. It can't be private int array so what do I have to use... it would be lovely if someone could help me

    thank you so much

    little_polarbear

  2. #2
    xcallmejudasx's Avatar
    xcallmejudasx is offline Senior Member
    Join Date
    Oct 2008
    Location
    Houston, TX & Flint, MI
    Posts
    609
    Rep Power
    6

    Default

    I'm a little confused to what you mean. You say you know how to write it so can you post some pseudo code at least so we can get a better idea?

    The line that says 1*0 needs to be calculated and read in as just 0? If that's the case you can just noob your way out and put an if statement that checks if the string is "1*0" and change it to just 0, or you could look up a string to int converter method(I am unaware of any off the top of my head) so it would work for multiple occasions like this one.

  3. #3
    Join Date
    Jun 2008
    Posts
    54
    Rep Power
    0

    Default

    oh no... sry... it is not a calculation... I have to write somethinh with MinTerms... really confusing... this is the code...

    import java.io.*;
    import java.util.Vector;
    public class Implikanten
    {

    private Vector Q[];
    public int n;
    private int array[];

    public void reading(String fileName)
    throws FileNotFoundException, NullPointerException
    {
    String line = null;
    int n = 0;
    int track = 0;

    BufferedReader in = new BufferedReader(new FileReader(fileName));

    try
    {
    while((line = in.readLine()) != null)
    {
    if(track == 0)
    {
    n = Integer.parseInt(line);
    array = new array[n];

    }
    else
    {
    array[track - 1] = array.valueOf(line.trim());
    }
    if(track == n+)
    {
    break;
    }
    track++;
    }
    }
    catch (IOException e)
    {
    System.out.println("Error in reading file");
    }

    for(int i = 0; i <= Q.length; i++)
    {
    System.out.println(array[i]);
    }
    }

    public static void main(String[] args)
    throws FileNotFoundException
    {
    Implikanten app = new Implikanten();
    app.reading("fileName");
    }




    }


    and it is saying that i have to save the MinTerms in the array Q so that if I have for example 100 it must be in Q[2] because it contains 2 zeros, if it has one zero, it must be in Q[1] the * just means, that there is no number... what i wanted to do is read in the terms into an normal array and then put them from there into the Vector Q but i think that there is another way which is more simple, so that i can put it directly into the array Q, but i don't know exactly how to do it... i tried it and this is my code, which followes:

    import java.io.*;
    import java.util.Vector;
    public class Implikanten
    {

    private Vector Q[];
    public int n;

    public void reading(String fileName)
    throws FileNotFoundException, NullPointerException
    {
    String line = null;
    int n = 0;
    int track = 0;

    BufferedReader in = new BufferedReader(new FileReader(fileName));

    try
    {
    while((line = in.readLine()) != null)
    {
    if(track == 0)
    {
    n = Integer.parseInt(line);
    Q = new Vector[n];

    }
    else
    {
    Q[track - 1] = Vector.valueOf(line.trim());
    }
    if(track == n+)
    {
    break;
    }
    track++;
    }
    }
    catch (IOException e)
    {
    System.out.println("Error in reading file");
    }

    for(int i = 0; i <= Q.length; i++)
    {
    System.out.println(Q[i]);
    }
    }

    public static void main(String[] args)
    throws FileNotFoundException
    {
    Implikanten app = new Implikanten();
    app.reading("fileName");
    }




    }


    little_polarbear

  4. #4
    ianjedi is offline Member
    Join Date
    Oct 2008
    Posts
    21
    Rep Power
    0

    Default

    toArray() populate a static array with the contents of a Vector? or is that to simple.

    cheers

    ian J

  5. #5
    xcallmejudasx's Avatar
    xcallmejudasx is offline Senior Member
    Join Date
    Oct 2008
    Location
    Houston, TX & Flint, MI
    Posts
    609
    Rep Power
    6

    Default

    Quote Originally Posted by little_polarbear View Post
    oh no... sry... it is not a calculation... I have to write somethinh with MinTerms... really confusing... this is the code...
    Java Code:
    import java.io.*;
    import java.util.Vector;
    public class Implikanten 
    {
    	
    private Vector Q[];
    public int n;
    private int array[];
    
    	public void reading(String fileName) 
    	throws FileNotFoundException, NullPointerException
    	{
    		String line = null;
    		int n = 0;
    		int track = 0;
    		
    		BufferedReader in = new BufferedReader(new FileReader(fileName));
    		
    		try
    		{
    			while((line = in.readLine()) != null)
    			{
    				if(track == 0)
    				{
    					n = Integer.parseInt(line);
    					array = new array[n];
    					
    				}
    				else
            		{
            			array[track - 1] = array.valueOf(line.trim());
            		}
    				if(track == n+)
    				{
    					break;
    				}
    				track++;
    			}
    		}
    		catch (IOException e)
    		{
    			System.out.println("Error in reading file");
    		}
    		
    		for(int i = 0; i <= Q.length; i++)
    		{
    			System.out.println(array[i]);
    		}
    }
    	
    	public static void main(String[] args) 
    	throws FileNotFoundException
    	{
    		Implikanten app = new Implikanten();
    		app.reading("fileName");
    	}
    
    
    
    
    }
    and it is saying that i have to save the MinTerms in the array Q so that if I have for example 100 it must be in Q[2] because it contains 2 zeros, if it has one zero, it must be in Q[1] the * just means, that there is no number... what i wanted to do is read in the terms into an normal array and then put them from there into the Vector Q but i think that there is another way which is more simple, so that i can put it directly into the array Q, but i don't know exactly how to do it... i tried it and this is my code, which followes:

    Java Code:
    import java.io.*;
    import java.util.Vector;
    public class Implikanten 
    {
    	
    private Vector Q[];
    public int n;
    
    	public void reading(String fileName) 
    	throws FileNotFoundException, NullPointerException
    	{
    		String line = null;
    		int n = 0;
    		int track = 0;
    		
    		BufferedReader in = new BufferedReader(new FileReader(fileName));
    		
    		try
    		{
    			while((line = in.readLine()) != null)
    			{
    				if(track == 0)
    				{
    					n = Integer.parseInt(line);
    					Q = new Vector[n];
    					
    				}
    				else
            		{
            			Q[track - 1] = Vector.valueOf(line.trim());
            		}
    				if(track == n+)
    				{
    					break;
    				}
    				track++;
    			}
    		}
    		catch (IOException e)
    		{
    			System.out.println("Error in reading file");
    		}
    		
    		for(int i = 0; i <= Q.length; i++)
    		{
    			System.out.println(Q[i]);
    		}
    }
    	
    	public static void main(String[] args) 
    	throws FileNotFoundException
    	{
    		Implikanten app = new Implikanten();
    		app.reading("fileName");
    	}
    
    
    
    
    }
    little_polarbear
    Just made your response a little easier to read. Did you copy paste your code exactly from a text document or an IDE? I ask this because of
    Java Code:
    if(track == n+)
    is there supposed to a digit after that or are you just incrementing it?

    also
    Java Code:
    	Q[track - 1] = Vector.valueOf(line.trim());
    is supposed to take the value of the line after you parse it. So
    Java Code:
    Q[track - 1] = Vector.valueOf(Integer.parseInt(line.trim()));
    or some sort of numeric value. I havn't worked with Vector but common sense tells me i can't use a String type and get a valueOf unless it has been parsed to something numeric.

  6. #6
    Join Date
    Jun 2008
    Posts
    54
    Rep Power
    0

    Default

    Hey Ian,
    just one question, if i wanna put the vector into an array, i first have to read in the values from the document, haven't I.... but I wanna have all the values which contains two zeros in Q[2] and the values which contains one zero in Q[1] and this method wouldn't do it... id i understood it right... or do i understand it wrong...

    little_polarbear

  7. #7
    ianjedi is offline Member
    Join Date
    Oct 2008
    Posts
    21
    Rep Power
    0

    Default

    Quote Originally Posted by little_polarbear View Post
    Hey Ian,
    just one question, if i wanna put the vector into an array, i first have to read in the values from the document, haven't I.... but I wanna have all the values which contains two zeros in Q[2] and the values which contains one zero in Q[1] and this method wouldn't do it... id i understood it right... or do i understand it wrong...

    little_polarbear
    No not all of that :) you would need to break it down into steps, I am not sure what part you need help with.

    cheers

    ian J

  8. #8
    Join Date
    Jun 2008
    Posts
    54
    Rep Power
    0

    Default

    ok, i kind of managed to read it into an array, the one problem is, that I don't know, how i have to initialisise my array, because i am always getting an error message, that * is not an integer... so i now have an array with
    array[0] = 100
    array[1] = 001
    array[2] = 1*0

    the star doesn't mean times, just that there is no number... and now i have to put it into the vector Q[] and here i don't know how to do do it... because i have to count the zeros in this array and then put it into the right position at Q[] can i do it by the way with the methos AddMinterm()

    little_polarbear

  9. #9
    emceenugget is offline Senior Member
    Join Date
    Sep 2008
    Posts
    564
    Rep Power
    6

    Default

    could you give us the exact error message(s) and what line(s) they indicate?

  10. #10
    Join Date
    Jun 2008
    Posts
    54
    Rep Power
    0

    Default

    ok, I just put the code down again... and under it the error message

    import java.io.*;
    import java.util.Vector;
    public class Implikanten
    {

    private Vector Q[];
    public int n;
    private int array[];

    public void AddMinterm(int n, String s)
    {

    }


    public void reading(String fileName)
    throws FileNotFoundException, NullPointerException
    {
    String line = null;
    int n = 0;
    int track = 0;

    BufferedReader in = new BufferedReader(new FileReader(fileName));

    try
    {
    while((line = in.readLine()) != null)
    {
    if(track == 0)
    {
    n = Integer.parseInt(line);
    Q = new Vector[n];

    }
    else
    {
    Q[track - 1] = Vector.valueOf(Integer.parseInt(line.trim()));
    }
    if(track == n)
    {
    break;
    }
    track++;
    }
    }
    catch (IOException e)
    {
    System.out.println("Error in reading file");
    }

    for(int i = 0; i <= Q.length; i++)
    {
    System.out.println(Q[i]);
    }
    }

    public void Ausgeben()
    {

    }

    public static void main(String[] args)
    throws FileNotFoundException
    {
    Implikanten app = new Implikanten();
    app.reading("fileName");
    }




    }


    and here is the error message:

    Exception in thread "main" java.lang.Error: Unresolved compilation problem:
    The method valueOf(int) is undefined for the type Vector

    at Implikanten.reading(Implikanten.java:41)
    at Implikanten.main(Implikanten.java:70)


    hope that it is helping you... thank you so much for all your help


    little_polarbear

  11. #11
    Nakira is offline Member
    Join Date
    Oct 2008
    Location
    Aberystwyth
    Posts
    55
    Rep Power
    0

    Default

    Maybe im just being a noob here, if i am then im sorry, but try:

    Java Code:
    import java.lang.*;
    Sorry if that doesn't help.

  12. #12
    Join Date
    Jun 2008
    Posts
    54
    Rep Power
    0

    Default

    thank you, i tried it, but it doesn't really help, but still thank you so much :-)

    little_polarbear

  13. #13
    emceenugget is offline Senior Member
    Join Date
    Sep 2008
    Posts
    564
    Rep Power
    6

    Default

    java.lang.* is imported by default and doesn't have to explicitly be stated.

    The error is telling you that the class Vector has no method "valueOf" that takes in type int as a parameter.

  14. #14
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    Quote Originally Posted by Nakira View Post
    Maybe im just being a noob here, if i am then im sorry, but try:
    Java Code:
    import java.lang.*;
    Sorry if that doesn't help.
    I don't think that you ever have to import java.lang.* that this is automatically imported. Do you have a reference that suggests otherwise? If so, please share it with us.

  15. #15
    ianjedi is offline Member
    Join Date
    Oct 2008
    Posts
    21
    Rep Power
    0

    Default

    Exception in thread "main" java.lang.Error: Unresolved compilation problem:
    The method valueOf(int) is undefined for the type Vector

    should be I think ? Q[track - 1] = Integer.valueOf(Integer.parseInt(line.trim()));


    I think its expecting a String at valueOf and you are passing an int into the vector.

    thanks

    Ian J
    Last edited by ianjedi; 10-29-2008 at 10:26 AM. Reason: new info

  16. #16
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,564
    Rep Power
    23

    Default

    method valueOf(int) is undefined for the type Vector

    at Implikanten.reading(Implikanten.java:41)
    What code is at line 41 in Implikanten.java?

Similar Threads

  1. new array ?
    By seandingobat in forum New To Java
    Replies: 7
    Last Post: 10-03-2008, 07:31 PM
  2. initialising Array of object??
    By Somitesh Chakraborty in forum New To Java
    Replies: 4
    Last Post: 08-27-2008, 09:00 PM
  3. initialising a webcam?
    By jonsamwell in forum New To Java
    Replies: 1
    Last Post: 08-25-2008, 05:17 PM
  4. Array Reflection: Multi Array Reflection
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-23-2008, 08:08 PM
  5. can anyone help... 2d Array
    By Mark1989 in forum New To Java
    Replies: 2
    Last Post: 03-12-2008, 08:59 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •