Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Small problem with strings in java
New Posts  All Forums:Forum Nav:

Small problem with strings in java - Page 4

post #31 of 34
Thread Starter 
Attachment 234398

Here's the screenshot. Thanks again!
First build
(13 items)
 
Pandoras Box
(13 items)
 
NV57H
(6 items)
 
CPUMotherboardGraphicsRAM
Phenom II X4 965 BE 4.0GHz @ 1.385V ASRock 970 Extreme 3 Gigabyte 650 Ti boost Mushkin Enhanced Silverline 4GB DDR3 1600 MHz 
RAMHard DriveOptical DriveCooling
Mushkin Enhanced Silverline 4GB DDR3 1600 MHz Seagate Barracuda 160GB  Samsung Noctua NH-D14 
MonitorPowerCaseMouse
Acer X223W Corsair VX550 Cooler Master Elite 430 TT E-Sports Theron 
Mouse Pad
Steelseries QcK Portal 2 
CPUMotherboardGraphicsRAM
E7500 @2.93 GHz Gigabyte G41M-ES2L Gigabyte HD 4650 2x 2 GB TwinMOS @ 800MHz 
Hard DriveOSMonitorPower
Samsung HD502IJ 500GB Windows 7 Ultimate 32-bit Samsung SyncMaster 943 18.5" Stock 450W 
Case
some piece of junk... 
CPUMotherboardGraphicsRAM
i3-2310M HM65 Intel HD 3000 6 GB DDR3 
Hard DriveOS
750 GB Windows 7 Home Premium x64 
  hide details  
Reply
First build
(13 items)
 
Pandoras Box
(13 items)
 
NV57H
(6 items)
 
CPUMotherboardGraphicsRAM
Phenom II X4 965 BE 4.0GHz @ 1.385V ASRock 970 Extreme 3 Gigabyte 650 Ti boost Mushkin Enhanced Silverline 4GB DDR3 1600 MHz 
RAMHard DriveOptical DriveCooling
Mushkin Enhanced Silverline 4GB DDR3 1600 MHz Seagate Barracuda 160GB  Samsung Noctua NH-D14 
MonitorPowerCaseMouse
Acer X223W Corsair VX550 Cooler Master Elite 430 TT E-Sports Theron 
Mouse Pad
Steelseries QcK Portal 2 
CPUMotherboardGraphicsRAM
E7500 @2.93 GHz Gigabyte G41M-ES2L Gigabyte HD 4650 2x 2 GB TwinMOS @ 800MHz 
Hard DriveOSMonitorPower
Samsung HD502IJ 500GB Windows 7 Ultimate 32-bit Samsung SyncMaster 943 18.5" Stock 450W 
Case
some piece of junk... 
CPUMotherboardGraphicsRAM
i3-2310M HM65 Intel HD 3000 6 GB DDR3 
Hard DriveOS
750 GB Windows 7 Home Premium x64 
  hide details  
Reply
post #32 of 34
No problem... I've been meaning to learn Java, so it's amusing doing small exercises like these.
The New Guy
(16 items)
 
  
CPUMotherboardGraphicsRAM
Q6600 G0@3.0GHz GA-P35-DS3L EVGA 8800GT Superclocked 4GB Corsair XMS2 DDR2 800 
Hard DriveHard DriveOptical DriveOS
Seagate 320GB 7200RPM Western Digital Caviar Black Lite-on DVD burner Windows 7 Professional x64 
MonitorKeyboardPowerCase
Samsung 225BW Filco Majestouch Ninja (full keyboard w/browns) Cooler Master Xtreme 650 Antec 900 
MouseAudioAudio
Logitech MX518 Denon AHD-2000 Sennheiser HD595 
  hide details  
Reply
The New Guy
(16 items)
 
  
CPUMotherboardGraphicsRAM
Q6600 G0@3.0GHz GA-P35-DS3L EVGA 8800GT Superclocked 4GB Corsair XMS2 DDR2 800 
Hard DriveHard DriveOptical DriveOS
Seagate 320GB 7200RPM Western Digital Caviar Black Lite-on DVD burner Windows 7 Professional x64 
MonitorKeyboardPowerCase
Samsung 225BW Filco Majestouch Ninja (full keyboard w/browns) Cooler Master Xtreme 650 Antec 900 
MouseAudioAudio
Logitech MX518 Denon AHD-2000 Sennheiser HD595 
  hide details  
Reply
post #33 of 34
Quote:
Originally Posted by Desidero View Post
You can actually cast a character as an integer in java. charAt returns the decimal ascii value of the character referenced. If you subtract 48 from any ascii number (0-9), you will get the actual value. I just ran a test program that does this. My method doesn't require any fancy error handling. It just checks to see if it's a number (0-9). You could also see if it's "X" or "x" (88 and 120, respectively... or 40 and 72 if you already subtracted 48) if you need to do your sum+=10 business for X.
converting chars to ints like that is pretty standard in assembly and C, but i try not to 'reinvent the wheel' in java and c++. generally if there's a function that does it for you, thats the best way to go. encapsulation and information hiding are pretty important in OOP.
Fractal Design
(15 items)
 
775 4 life
(15 items)
 
 
CPUMotherboardGraphicsRAM
Intel i7 2600K Biostar TP67XE NVidia GTX 570 Crucial Ballistix 
Hard DriveHard DriveCoolingOS
Crucial C300 RealSSD SDD Samsung F4 2TB Noctua NH-D14 Windows 7 Professional x64 
MonitorMonitorKeyboardPower
Asus VH202T 20'' 1600x900 Acer P244W 24" 1920 x 1080 Apple Keyboard with Numeric Keypad SeaSonic M12II 620W 
CaseMouseAudio
Fractal Design Define XL Titanium Grey Razor Abyssus Creative Sound Blaster X-FI Xtreme Gamer 
CPUMotherboardGraphicsRAM
Intel X3350 3.2Ghz @ 1.25v Gigabyte-GA-P35-DS3L (rev 2) XFX 4870 1GB 4GB OCZ Reaper PC2-6400 
RAMHard DriveHard DriveOptical Drive
2GB Corsair XMS2 PC2-6400 Crucial C300 64GB SSD 2TB Samsung Spinpoint F4 Sony Super Multi 
OSMonitorPowerCase
Windows 7 Professional x64 SP1 Asus VH202T 20'' 1600x900 SeaSonic M12II 620W Cooler Master Centurion 5 
Mouse
Razor Abyssus 
CPUMotherboardGraphicsRAM
Core i5-520M Lenovo 2522BF3 NVIDIA® Quadro® NVS3100M  Ramaxel Technology 4Gb DDR3 
Hard DriveOptical DriveOSMonitor
Samsung SSD 128GB 1.8" Micro SATA  hl-dt-st dvdram gu10n Windows 7 Enterprise (64-bit) 14.1" WXGA (1280x800) display, anti-glare, LED ... 
Power
9-cell plus Slice battery 
  hide details  
Reply
Fractal Design
(15 items)
 
775 4 life
(15 items)
 
 
CPUMotherboardGraphicsRAM
Intel i7 2600K Biostar TP67XE NVidia GTX 570 Crucial Ballistix 
Hard DriveHard DriveCoolingOS
Crucial C300 RealSSD SDD Samsung F4 2TB Noctua NH-D14 Windows 7 Professional x64 
MonitorMonitorKeyboardPower
Asus VH202T 20'' 1600x900 Acer P244W 24" 1920 x 1080 Apple Keyboard with Numeric Keypad SeaSonic M12II 620W 
CaseMouseAudio
Fractal Design Define XL Titanium Grey Razor Abyssus Creative Sound Blaster X-FI Xtreme Gamer 
CPUMotherboardGraphicsRAM
Intel X3350 3.2Ghz @ 1.25v Gigabyte-GA-P35-DS3L (rev 2) XFX 4870 1GB 4GB OCZ Reaper PC2-6400 
RAMHard DriveHard DriveOptical Drive
2GB Corsair XMS2 PC2-6400 Crucial C300 64GB SSD 2TB Samsung Spinpoint F4 Sony Super Multi 
OSMonitorPowerCase
Windows 7 Professional x64 SP1 Asus VH202T 20'' 1600x900 SeaSonic M12II 620W Cooler Master Centurion 5 
Mouse
Razor Abyssus 
CPUMotherboardGraphicsRAM
Core i5-520M Lenovo 2522BF3 NVIDIA® Quadro® NVS3100M  Ramaxel Technology 4Gb DDR3 
Hard DriveOptical DriveOSMonitor
Samsung SSD 128GB 1.8" Micro SATA  hl-dt-st dvdram gu10n Windows 7 Enterprise (64-bit) 14.1" WXGA (1280x800) display, anti-glare, LED ... 
Power
9-cell plus Slice battery 
  hide details  
Reply
post #34 of 34
Quote:
Originally Posted by travesty View Post
converting chars to ints like that is pretty standard in assembly and C, but i try not to 'reinvent the wheel' in java and c++. generally if there's a function that does it for you, thats the best way to go. encapsulation and information hiding are pretty important in OOP.
It's not reinventing the wheel. It's pretty standard stuff. One of the main problems with Java is that people use all the extra class crap when they don't need to. That's a major part of why Java is so much slower than other compiled languages.

It's not a big deal to pump out inefficient test applications for simple homework assignments, but it's important for him to find better ways of doing things if he's going to be a real programmer some day. I spend way too much time looking at goofy code written by people who "just wanted to get it working" to shrug this off. It's best to pick up good habits early on.
The New Guy
(16 items)
 
  
CPUMotherboardGraphicsRAM
Q6600 G0@3.0GHz GA-P35-DS3L EVGA 8800GT Superclocked 4GB Corsair XMS2 DDR2 800 
Hard DriveHard DriveOptical DriveOS
Seagate 320GB 7200RPM Western Digital Caviar Black Lite-on DVD burner Windows 7 Professional x64 
MonitorKeyboardPowerCase
Samsung 225BW Filco Majestouch Ninja (full keyboard w/browns) Cooler Master Xtreme 650 Antec 900 
MouseAudioAudio
Logitech MX518 Denon AHD-2000 Sennheiser HD595 
  hide details  
Reply
The New Guy
(16 items)
 
  
CPUMotherboardGraphicsRAM
Q6600 G0@3.0GHz GA-P35-DS3L EVGA 8800GT Superclocked 4GB Corsair XMS2 DDR2 800 
Hard DriveHard DriveOptical DriveOS
Seagate 320GB 7200RPM Western Digital Caviar Black Lite-on DVD burner Windows 7 Professional x64 
MonitorKeyboardPowerCase
Samsung 225BW Filco Majestouch Ninja (full keyboard w/browns) Cooler Master Xtreme 650 Antec 900 
MouseAudioAudio
Logitech MX518 Denon AHD-2000 Sennheiser HD595 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Small problem with strings in java