473,396 Members | 1,998 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Biting off more than I can chew...

Hi,

My Perl is functional, but I finally decided to bite the bullet and learn Java, so please be gentle, I'm a newbie.

I have 14 lines of tab seperated data in an external file, comprising an integer value 'n' (which may or may not be present), and two double values 't' and 'c' as follows;
Expand|Select|Wrap|Line Numbers
  1. 2    0.5773502692    1
  2.     -0.5773502692    1
  3. 3    0.7745966692    0.5555555556
  4.     0    0.8888888889
  5.     -0.7745966692    0.5555555556
  6. 4    0.8611363116    0.3478548451
  7.     0.3399810436    0.6521451549
  8.     -0.3399810436    0.6521451549
  9.     -0.8611363116    0.3478548451
  10. 5    0.9061798459    0.2369268850
  11.     0.5384693101    0.4786286705
  12.     0    0.5688888889
  13.     -0.5384693101    0.4786286705
  14.     -0.9061798459    0.2369268850
I'd like to read the data into a multi-dimensional array with the following structure;
Expand|Select|Wrap|Line Numbers
  1. int n[]
  2. double t[], c[], x[], and f[]
to allow for the products of number-crunching.

I'm not yet familiar enough with java syntax to create, initialise, insert, manipulate, and write multi-dimensional array data of more than one type. Here I'd like help creating the data structure, and reading data in.

Any suggested code segments, or direction to tutorial resources would be warmly appreciated.

Thank you in advance.

Regards,
Nostradormouse
Mar 7 '10 #1
1 1355
jkmyoung
2,057 Expert 2GB
Scanner class, if you're using Java 1.5 or up.

Looks to me like you're reading in roots of complex numbers.
I would suggest rearranging the data into objects or structures.

Base level: original number
--2nd level: root number
----3rd level: values of roots.

So building backwards, you might have something like:
Expand|Select|Wrap|Line Numbers
  1. class ComplexRoot(
  2.         public int t, c;
  3. )
Then work up one level, use an array of ComplexRoots. Sorry couldn't think of a good name for this class.
Expand|Select|Wrap|Line Numbers
  1. class Solutions{
  2.         public int n;
  3.         ComplexRoot[] cr;
  4. }
And finally have an array of Solutions
Solutions [] s;

code would go something like:
Expand|Select|Wrap|Line Numbers
  1. Scanner sc = new Scanner("inputfile.txt");
  2. int n;
  3. while (sc.hasNextLine()){
  4.   if(! sc.hasNextInt()){ // just in case of newLine at end.
  5.      break;
  6.   }
  7.   n = sc.nextInt();
  8.   Solutions sol = new Solutions(n);
  9.   s.add(sol);
  10.   for (int i = 0; i < n; i++){
  11.      t = sc.NextDouble();
  12.      c = sc.NextDouble();
  13.      sol.add(new ComplexRoot(t,c));
  14.   }
  15. }
  16.  
The constructors are relatively easy. Sorry, didn't get the x[] and f[]
Hope this helps, and doesn't confuse you too much.
Mar 8 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

73
by: RobertMaas | last post by:
After many years of using LISP, I'm taking a class in Java and finding the two roughly comparable in some ways and very different in other ways. Each has a decent size library of useful utilities...
220
by: Brandon J. Van Every | last post by:
What's better about Ruby than Python? I'm sure there's something. What is it? This is not a troll. I'm language shopping and I want people's answers. I don't know beans about Ruby or have...
5
by: Lukas Holcik | last post by:
Hi everyone! How can I simply search text for regexps (lets say <a href="(.*?)">(.*?)</a>) and save all URLs(1) and link contents(2) in a dictionary { name : URL}? In a single pass if it could....
114
by: Maurice LING | last post by:
This may be a dumb thing to ask, but besides the penalty for dynamic typing, is there any other real reasons that Python is slower than Java? maurice
5
by: tHeRoBeRtMiTcHeLL | last post by:
Well, I think I have bitten off a little more than I can chew (at least all at once), and I'm only trying to hammer out tables/relationships at the design level. Which translates to "Seasoned...
87
by: John Rivers | last post by:
Hello everybody, I just wondered if anybody else has noticed this? It takes around 6 seconds to start debugging a very simple ASPX page with VS.NET whereas VB6 takes under 0.5 seconds, even...
43
by: Tony | last post by:
I'm working with GUI messaging and note that MFC encapsulates the message loop inside of a C++ class member function. Is this somehow inherently less robust than calling the message loop functions...
16
by: Mike | last post by:
Hi, I have a form with some controls, and a different class that needs to modify some control properties at run time. Hoy can I reference the from so I have access to its controls and...
36
by: x_knifer_x | last post by:
read the subject it says it all int main(void) is better than int main()
9
by: Don | last post by:
I've continued to use Access 97 all these years because (1) it does everything I need quickly and (2) most of what I've read online indicates that it's still the most bug-free version of Access. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.