• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Need help...

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everyone; two questions today.
1. I'm looking for a way to take each number from a string such as " 713 | 413 | 756 | 13 | 382 | -365 |" and put in into an appropriately sized 2 by [half as many elements] matrix/array. The input will always be an even amount of numbers. I already have a snippet of code to find out how many numbers there are total (count the |'s), divide by two, label as "temp", and you get "new int[2][temp]". The array needs to be ordered such that the
1st number is in [0][0];
2nd number is in [1][0];
3rd number is in [0][1];
4th number is in [1][1]; (and so on until all numbers have been added.)
That is if I'm stupid and can't see some easier way of doing this. As of the moment, I'm stuck on a String to Integer function or something. Say I have the string "234" and want to turn it into an integer with the value 234. Any help is appreciated. Insults on my stupidity are acceptable.
 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
to convert a String to an Integer, go like this:
String str = "435"
int num = Integer.parseInt(str);
As for your other questions, i dont understand it so sorry.
 
Rocky Summers
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
oh oh..
i can show you how to read in a file of |321|422|151|-252|
etc.
you dont need to count the | stuff.. there's a built in method in java where you can read in a string and ignore the |...

good luck!
 
Without subsidies, chem-ag food costs four times more than organic. Or this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic