Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Need help with arrays in Java
New Posts  All Forums:Forum Nav:

Need help with arrays in Java

post #1 of 23
Thread Starter 
I'm new to programming and arrays are hard for me to deal with.
The image shows the problem.
Problem.PNG 22k .PNG file
My code sucks so far, I need help to get on the right path.
Please help.
Code:
import java.util.Scanner;

public class ParkingGarage {

        public static void main(String[] args) {
                Scanner input = new Scanner(System.in);
                int[] cars;
                double hours, maxCharge;
                int j;
                
                cars = new int[5];
                j    = 1;
                
                while (j <= 5) {
                        System.out.print("Enter the hours parked for car " + j);
                        hours[j] = input.nextDouble(); // Error on this line
                        
                        // I am completely lost and cannot figure out arrays.
                        
                }
                
        }

}

Edited by Heat Miser - 3/11/14 at 2:42am
My System
(15 items)
 
  
CPUMotherboardGraphicsRAM
i7-2600k ASUS P8P67 Deluxe EVGA GTX 570 SC G.SKILL Ripjaws X 8GB 
Hard DriveHard DriveCoolingOS
Crucial M4 Samsung Spinpoint F3 Prolimatech Megahalems Windows 7 Professional 
MonitorKeyboardPowerCase
Samsung P2450H 24" Ducky Shine Blue LED w/ Cherry MX Reds Corsair HX850 FT02B-W 
Mouse
Razer Death Adder 
  hide details  
Reply
My System
(15 items)
 
  
CPUMotherboardGraphicsRAM
i7-2600k ASUS P8P67 Deluxe EVGA GTX 570 SC G.SKILL Ripjaws X 8GB 
Hard DriveHard DriveCoolingOS
Crucial M4 Samsung Spinpoint F3 Prolimatech Megahalems Windows 7 Professional 
MonitorKeyboardPowerCase
Samsung P2450H 24" Ducky Shine Blue LED w/ Cherry MX Reds Corsair HX850 FT02B-W 
Mouse
Razer Death Adder 
  hide details  
Reply
post #2 of 23
Pseudo-code:
Code:
/* set up our constants */
let const minPrice : 5
let const  maxPrice : 12
let const  minHours : 2
let const  hourIncrementPrice : 1

/* declares an array */
let cars : []

for n 1 to 5
  print "Enter the hours parked for car <n>:"

  /* make sure the input is never less than minimum time. _input is a pseudo variable that captures the user input */
  if _input < minHours
    _input : minHours

  /* calculate the price for parking
   * this adds the minimum price ($5.00) + any additional hours multiplied by the hourly increment ($1.00) 
   */
  cars[n] : minPrice + ( ( _input - minHours ) * hourIncrementPrice )

  /* if the price goes above max price, cap it at max price */
  if cars[n] > maxPrice
    cars[n] : maxPrice
  
end

You should be using a for loop in your Java code, not a while loop:
Code:
for ( j = 0; j < 5; ++j )
{
        /* ... */
}
Ol' Sandy
(28 items)
 
"Zeus"
(12 items)
 
Elite Preview
(6 items)
 
CPUMotherboardGraphicsRAM
Intel Xeon E3-1230v3 Gigabyte GA-Z97X-UD5H-BK MSI Gaming GTX 980 Kingston 32GB (4x8) 
Hard DriveHard DriveHard DriveHard Drive
Plextor PX-256M5S 256GB Samsung EVO 1TB Hitachi HDS721010CLA332 Hitachi HDS723020BLA642 
Hard DriveHard DriveHard DriveOptical Drive
Hitachi HDS723020BLA642 Hitachi HUA722010CLA330 WDC WD10EARS-00Z5B1 TSSTcorp CDDVDW SH-S223B 
CoolingCoolingOSMonitor
Phanteks PH-TC14PE with TY-140's Lamptron FCv5 (x2) Windows 8 Pro 64-bit Dell U2412M 
MonitorMonitorMonitorKeyboard
Dell U2412M Dell U2212HM Dell U2713HM Topre Realforce 87UB | Ducky DK9087 G2 Pro 
PowerCaseMouseMouse Pad
Corsair AX-750 Corsair Obsidian 650D Logitech G700 XTRAC Ripper XXL 
AudioAudioAudioAudio
Beyerdynamic DT-770 Pro 250ohm Schiit Bifrost DAC Schiit Asgard 2 HiVi Swan M50W 2.1 
CPUMotherboardRAMHard Drive
Intel Xeon E5-2620 Super Micro X9SRL-F-B 128GB 1333MHz LSI 9271-8i 
OSPowerCase
VMware ESXi 5.5 SeaSonic SS-400FL2 Fractal Define R3 
CPUMotherboardGraphicsRAM
Intel Core i5-3437U HP EliteBook Folio 9470m  Intel HD Graphics 4000  16GB DDR3 SDRAM 
Hard DriveOS
256GB SSD Windows 10 Insider Preview 
  hide details  
Reply
Ol' Sandy
(28 items)
 
"Zeus"
(12 items)
 
Elite Preview
(6 items)
 
CPUMotherboardGraphicsRAM
Intel Xeon E3-1230v3 Gigabyte GA-Z97X-UD5H-BK MSI Gaming GTX 980 Kingston 32GB (4x8) 
Hard DriveHard DriveHard DriveHard Drive
Plextor PX-256M5S 256GB Samsung EVO 1TB Hitachi HDS721010CLA332 Hitachi HDS723020BLA642 
Hard DriveHard DriveHard DriveOptical Drive
Hitachi HDS723020BLA642 Hitachi HUA722010CLA330 WDC WD10EARS-00Z5B1 TSSTcorp CDDVDW SH-S223B 
CoolingCoolingOSMonitor
Phanteks PH-TC14PE with TY-140's Lamptron FCv5 (x2) Windows 8 Pro 64-bit Dell U2412M 
MonitorMonitorMonitorKeyboard
Dell U2412M Dell U2212HM Dell U2713HM Topre Realforce 87UB | Ducky DK9087 G2 Pro 
PowerCaseMouseMouse Pad
Corsair AX-750 Corsair Obsidian 650D Logitech G700 XTRAC Ripper XXL 
AudioAudioAudioAudio
Beyerdynamic DT-770 Pro 250ohm Schiit Bifrost DAC Schiit Asgard 2 HiVi Swan M50W 2.1 
CPUMotherboardRAMHard Drive
Intel Xeon E5-2620 Super Micro X9SRL-F-B 128GB 1333MHz LSI 9271-8i 
OSPowerCase
VMware ESXi 5.5 SeaSonic SS-400FL2 Fractal Define R3 
CPUMotherboardGraphicsRAM
Intel Core i5-3437U HP EliteBook Folio 9470m  Intel HD Graphics 4000  16GB DDR3 SDRAM 
Hard DriveOS
256GB SSD Windows 10 Insider Preview 
  hide details  
Reply
post #3 of 23
If he's new the class he's in might not have taught for loops yet. Either way it's probably better showing him the error he made instead of giving him new code:

You have multiple errors:

Firstly, you never create an hours array so you are trying to add an element to something that doesn't exist.

Also, when you do finally get the first exception fixed you will find an infinite loop since you never increment j. Just add 1 to j and you should be fine.

The next exception will be an index out of bounds exception. This is because arrays in Java start at zero. You start j at one but arrays start at zero and end at (length -1). TO fix your problem simply set j equal to zero.
Edited by Fullinator - 3/10/14 at 10:22am
The Rig of Power
(18 items)
 
First Build
(13 items)
 
 
CPUMotherboardGraphicsGraphics
Intel i7 3930k Asus P9X79 Pro nVidia 9800 GT nVidia 9800 GT 
RAMHard DriveHard DriveHard Drive
Corsair XMS3 WD Black WD Blue WD Raptor 10,000 RPM 
Hard DriveHard DriveCoolingOS
Corsair Force 3 SSD Seagate Corsiar H80 Windows 7 Ultimate 64-bit 
MonitorKeyboardPowerCase
Dell U2311H Logitech G19 Corsair TX750 Corsair 650D 
MouseAudio
Logitech G500 Logitech G51 
CPUMotherboardGraphicsRAM
Amd Phenom II X3 Asus M4a785TD-V EVO NVIDIA 9800GTX 4 GB G.skill DDR3 @ 1333 mhz 
Hard DriveOSMonitorKeyboard
WD blue250,350(boot,games) WD 1TB black(storage) windows 7 Ultimate 64-bit Dell U2311h Logitech G19 
PowerCaseMouse
500 Watt smilidon Logitech G500 
  hide details  
Reply
The Rig of Power
(18 items)
 
First Build
(13 items)
 
 
CPUMotherboardGraphicsGraphics
Intel i7 3930k Asus P9X79 Pro nVidia 9800 GT nVidia 9800 GT 
RAMHard DriveHard DriveHard Drive
Corsair XMS3 WD Black WD Blue WD Raptor 10,000 RPM 
Hard DriveHard DriveCoolingOS
Corsair Force 3 SSD Seagate Corsiar H80 Windows 7 Ultimate 64-bit 
MonitorKeyboardPowerCase
Dell U2311H Logitech G19 Corsair TX750 Corsair 650D 
MouseAudio
Logitech G500 Logitech G51 
CPUMotherboardGraphicsRAM
Amd Phenom II X3 Asus M4a785TD-V EVO NVIDIA 9800GTX 4 GB G.skill DDR3 @ 1333 mhz 
Hard DriveOSMonitorKeyboard
WD blue250,350(boot,games) WD 1TB black(storage) windows 7 Ultimate 64-bit Dell U2311h Logitech G19 
PowerCaseMouse
500 Watt smilidon Logitech G500 
  hide details  
Reply
post #4 of 23
Quote:
Originally Posted by Fullinator View Post

If he's new the class he's in might not have taught for loops yet. Either way it's probably better showing him the error he made instead of giving him new code:

You have multiple errors:

Firstly, you never create an hours array so you are trying to add an element to something that doesn't exist.

Also, when you do finally get the first exception fixed you will find an infinite loop since you never increment j. Just add 1 to j and you should be fine.

The next exception will be an index out of bounds exception. This is because arrays in Java start at zero. You start j at one but arrays start at zero and end at (length -1). TO fix your problem simply set j equal to zero.

The correct way to solve that question would be with a for loop and the correct way to work with arrays are with for loops. What's more, for loops are simpler to learn than arrays so he should have learned how to use for loops before being set that question. In fact, if he hasn't been taught for loops by now, then his course is doing things backwards. So I'd argue that regardless of what he's been taught at uni, tompsonn's advice makes sense.
post #5 of 23
Quote:
Originally Posted by Plan9 View Post

The correct way to solve that question would be with a for loop and the correct way to work with arrays are with for loops. What's more, for loops are simpler to learn than arrays so he should have learned how to use for loops before being set that question. In fact, if he hasn't been taught for loops by now, then his course is doing things backwards. So I'd argue that regardless of what he's been taught at uni, tompsonn's advice makes sense.

Of course uni tompsonn's way is a more correct way of solving the problem. That's not the point though. If someone asks why their code won't work it's better to show them/explain what's wrong and then give them advice/ teach them how to do it correctly than to simply tell them the better way to do it and not answer their previous question. Uni Tompsonn already gave the better way to do it so me saying anything similar is just a waste of words. Heat Miser made a lot of basic mistakes and in my mind (and the department head who taught me back in college) was that the first introductory programming course doesn't focus too much on the "right" way but more on getting them used to the language and being able to start forming basic algorithms and debug simple code.
The Rig of Power
(18 items)
 
First Build
(13 items)
 
 
CPUMotherboardGraphicsGraphics
Intel i7 3930k Asus P9X79 Pro nVidia 9800 GT nVidia 9800 GT 
RAMHard DriveHard DriveHard Drive
Corsair XMS3 WD Black WD Blue WD Raptor 10,000 RPM 
Hard DriveHard DriveCoolingOS
Corsair Force 3 SSD Seagate Corsiar H80 Windows 7 Ultimate 64-bit 
MonitorKeyboardPowerCase
Dell U2311H Logitech G19 Corsair TX750 Corsair 650D 
MouseAudio
Logitech G500 Logitech G51 
CPUMotherboardGraphicsRAM
Amd Phenom II X3 Asus M4a785TD-V EVO NVIDIA 9800GTX 4 GB G.skill DDR3 @ 1333 mhz 
Hard DriveOSMonitorKeyboard
WD blue250,350(boot,games) WD 1TB black(storage) windows 7 Ultimate 64-bit Dell U2311h Logitech G19 
PowerCaseMouse
500 Watt smilidon Logitech G500 
  hide details  
Reply
The Rig of Power
(18 items)
 
First Build
(13 items)
 
 
CPUMotherboardGraphicsGraphics
Intel i7 3930k Asus P9X79 Pro nVidia 9800 GT nVidia 9800 GT 
RAMHard DriveHard DriveHard Drive
Corsair XMS3 WD Black WD Blue WD Raptor 10,000 RPM 
Hard DriveHard DriveCoolingOS
Corsair Force 3 SSD Seagate Corsiar H80 Windows 7 Ultimate 64-bit 
MonitorKeyboardPowerCase
Dell U2311H Logitech G19 Corsair TX750 Corsair 650D 
MouseAudio
Logitech G500 Logitech G51 
CPUMotherboardGraphicsRAM
Amd Phenom II X3 Asus M4a785TD-V EVO NVIDIA 9800GTX 4 GB G.skill DDR3 @ 1333 mhz 
Hard DriveOSMonitorKeyboard
WD blue250,350(boot,games) WD 1TB black(storage) windows 7 Ultimate 64-bit Dell U2311h Logitech G19 
PowerCaseMouse
500 Watt smilidon Logitech G500 
  hide details  
Reply
post #6 of 23
Quote:
Originally Posted by Fullinator View Post

If he's new the class he's in might not have taught for loops yet. Either way it's probably better showing him the error he made instead of giving him new code:

You have multiple errors:

Firstly, you never create an hours array so you are trying to add an element to something that doesn't exist.

Also, when you do finally get the first exception fixed you will find an infinite loop since you never increment j. Just add 1 to j and you should be fine.

The next exception will be an index out of bounds exception. This is because arrays in Java start at zero. You start j at one but arrays start at zero and end at (length -1). TO fix your problem simply set j equal to zero.

I disagree. Not with you but with the class, if you are correct. Teaching arrays without teaching loops is dumb and is the reason why I DID NOT go to university (so you can stop calling me that now smile.gif )

The for loop is easy. A while loop, well that's used for different things. By demonstrating the for loop construct, you can eliminate all of the basic mistakes in one fell swoop.

Quote:
Originally Posted by Fullinator View Post

Of course uni tompsonn's way is a more correct way of solving the problem. That's not the point though. If someone asks why their code won't work it's better to show them/explain what's wrong and then give them advice/ teach them how to do it correctly than to simply tell them the better way to do it and not answer their previous question. Uni Tompsonn already gave the better way to do it so me saying anything similar is just a waste of words. Heat Miser made a lot of basic mistakes and in my mind (and the department head who taught me back in college) was that the first introductory programming course doesn't focus too much on the "right" way but more on getting them used to the language and being able to start forming basic algorithms and debug simple code.

I believe in teaching through code and explaining through code. My first teaching step is to write code. For beginners I usually write pseudo-code because I can tailor it and make it very easy to understand. Why? This prompts questions from the student. The reason why I want them to ask questions is because without them, what do I teach? I could go on for hours about arrays and loops and how and when to use them via English but I'd rather demonstrate them via code then back them by answers to any questions. Code is like a picture - its 1000 words.

The second reason for using pseudo-code is to weed out those who shouldn't be programming because if you cannot follow the logic and flow of it then the industry isn't for you - but questions are allowed.
Ol' Sandy
(28 items)
 
"Zeus"
(12 items)
 
Elite Preview
(6 items)
 
CPUMotherboardGraphicsRAM
Intel Xeon E3-1230v3 Gigabyte GA-Z97X-UD5H-BK MSI Gaming GTX 980 Kingston 32GB (4x8) 
Hard DriveHard DriveHard DriveHard Drive
Plextor PX-256M5S 256GB Samsung EVO 1TB Hitachi HDS721010CLA332 Hitachi HDS723020BLA642 
Hard DriveHard DriveHard DriveOptical Drive
Hitachi HDS723020BLA642 Hitachi HUA722010CLA330 WDC WD10EARS-00Z5B1 TSSTcorp CDDVDW SH-S223B 
CoolingCoolingOSMonitor
Phanteks PH-TC14PE with TY-140's Lamptron FCv5 (x2) Windows 8 Pro 64-bit Dell U2412M 
MonitorMonitorMonitorKeyboard
Dell U2412M Dell U2212HM Dell U2713HM Topre Realforce 87UB | Ducky DK9087 G2 Pro 
PowerCaseMouseMouse Pad
Corsair AX-750 Corsair Obsidian 650D Logitech G700 XTRAC Ripper XXL 
AudioAudioAudioAudio
Beyerdynamic DT-770 Pro 250ohm Schiit Bifrost DAC Schiit Asgard 2 HiVi Swan M50W 2.1 
CPUMotherboardRAMHard Drive
Intel Xeon E5-2620 Super Micro X9SRL-F-B 128GB 1333MHz LSI 9271-8i 
OSPowerCase
VMware ESXi 5.5 SeaSonic SS-400FL2 Fractal Define R3 
CPUMotherboardGraphicsRAM
Intel Core i5-3437U HP EliteBook Folio 9470m  Intel HD Graphics 4000  16GB DDR3 SDRAM 
Hard DriveOS
256GB SSD Windows 10 Insider Preview 
  hide details  
Reply
Ol' Sandy
(28 items)
 
"Zeus"
(12 items)
 
Elite Preview
(6 items)
 
CPUMotherboardGraphicsRAM
Intel Xeon E3-1230v3 Gigabyte GA-Z97X-UD5H-BK MSI Gaming GTX 980 Kingston 32GB (4x8) 
Hard DriveHard DriveHard DriveHard Drive
Plextor PX-256M5S 256GB Samsung EVO 1TB Hitachi HDS721010CLA332 Hitachi HDS723020BLA642 
Hard DriveHard DriveHard DriveOptical Drive
Hitachi HDS723020BLA642 Hitachi HUA722010CLA330 WDC WD10EARS-00Z5B1 TSSTcorp CDDVDW SH-S223B 
CoolingCoolingOSMonitor
Phanteks PH-TC14PE with TY-140's Lamptron FCv5 (x2) Windows 8 Pro 64-bit Dell U2412M 
MonitorMonitorMonitorKeyboard
Dell U2412M Dell U2212HM Dell U2713HM Topre Realforce 87UB | Ducky DK9087 G2 Pro 
PowerCaseMouseMouse Pad
Corsair AX-750 Corsair Obsidian 650D Logitech G700 XTRAC Ripper XXL 
AudioAudioAudioAudio
Beyerdynamic DT-770 Pro 250ohm Schiit Bifrost DAC Schiit Asgard 2 HiVi Swan M50W 2.1 
CPUMotherboardRAMHard Drive
Intel Xeon E5-2620 Super Micro X9SRL-F-B 128GB 1333MHz LSI 9271-8i 
OSPowerCase
VMware ESXi 5.5 SeaSonic SS-400FL2 Fractal Define R3 
CPUMotherboardGraphicsRAM
Intel Core i5-3437U HP EliteBook Folio 9470m  Intel HD Graphics 4000  16GB DDR3 SDRAM 
Hard DriveOS
256GB SSD Windows 10 Insider Preview 
  hide details  
Reply
post #7 of 23
Quote:
Originally Posted by tompsonn View Post

I disagree. Not with you but with the class, if you are correct. Teaching arrays without teaching loops is dumb and is the reason why I DID NOT go to university (so you can stop calling me that now smile.gif )

I was taught both loops at the same time if I remember correctly. It does seem silly not to but some professors are weird. I had a colleague who was not allowed to use an IDE and had to use notepad for Java code in his first ever class. I went for more than computer science otherwise I probably would not have gone either.
Quote:
Originally Posted by tompsonn View Post

The for loop is easy. A while loop, well that's used for different things. By demonstrating the for loop construct, you can eliminate all of the basic mistakes in one fell swoop.
I believe in teaching through code and explaining through code. My first teaching step is to write code. For beginners I usually write pseudo-code because I can tailor it and make it very easy to understand. Why? This prompts questions from the student. The reason why I want them to ask questions is because without them, what do I teach?

There are so many different teaching methods. The one I used is the one I liked best. When I had a problem it allowed me to learn why what I did didn't work and then how to do it better. Not having psuedo code really helped in my creativity in solving problems I think. (Not that psuedo code is bad in the slightest. I used it a lot and still use it a lot. I love it)
The Rig of Power
(18 items)
 
First Build
(13 items)
 
 
CPUMotherboardGraphicsGraphics
Intel i7 3930k Asus P9X79 Pro nVidia 9800 GT nVidia 9800 GT 
RAMHard DriveHard DriveHard Drive
Corsair XMS3 WD Black WD Blue WD Raptor 10,000 RPM 
Hard DriveHard DriveCoolingOS
Corsair Force 3 SSD Seagate Corsiar H80 Windows 7 Ultimate 64-bit 
MonitorKeyboardPowerCase
Dell U2311H Logitech G19 Corsair TX750 Corsair 650D 
MouseAudio
Logitech G500 Logitech G51 
CPUMotherboardGraphicsRAM
Amd Phenom II X3 Asus M4a785TD-V EVO NVIDIA 9800GTX 4 GB G.skill DDR3 @ 1333 mhz 
Hard DriveOSMonitorKeyboard
WD blue250,350(boot,games) WD 1TB black(storage) windows 7 Ultimate 64-bit Dell U2311h Logitech G19 
PowerCaseMouse
500 Watt smilidon Logitech G500 
  hide details  
Reply
The Rig of Power
(18 items)
 
First Build
(13 items)
 
 
CPUMotherboardGraphicsGraphics
Intel i7 3930k Asus P9X79 Pro nVidia 9800 GT nVidia 9800 GT 
RAMHard DriveHard DriveHard Drive
Corsair XMS3 WD Black WD Blue WD Raptor 10,000 RPM 
Hard DriveHard DriveCoolingOS
Corsair Force 3 SSD Seagate Corsiar H80 Windows 7 Ultimate 64-bit 
MonitorKeyboardPowerCase
Dell U2311H Logitech G19 Corsair TX750 Corsair 650D 
MouseAudio
Logitech G500 Logitech G51 
CPUMotherboardGraphicsRAM
Amd Phenom II X3 Asus M4a785TD-V EVO NVIDIA 9800GTX 4 GB G.skill DDR3 @ 1333 mhz 
Hard DriveOSMonitorKeyboard
WD blue250,350(boot,games) WD 1TB black(storage) windows 7 Ultimate 64-bit Dell U2311h Logitech G19 
PowerCaseMouse
500 Watt smilidon Logitech G500 
  hide details  
Reply
post #8 of 23
I remember doing Turbo Pascal in college. It's technically an IDE but it might as well have been Notepad with a Pascal compiler. But one thing is for sure, loops and arrays came in the right order wink.gif
Ol' Sandy
(28 items)
 
"Zeus"
(12 items)
 
Elite Preview
(6 items)
 
CPUMotherboardGraphicsRAM
Intel Xeon E3-1230v3 Gigabyte GA-Z97X-UD5H-BK MSI Gaming GTX 980 Kingston 32GB (4x8) 
Hard DriveHard DriveHard DriveHard Drive
Plextor PX-256M5S 256GB Samsung EVO 1TB Hitachi HDS721010CLA332 Hitachi HDS723020BLA642 
Hard DriveHard DriveHard DriveOptical Drive
Hitachi HDS723020BLA642 Hitachi HUA722010CLA330 WDC WD10EARS-00Z5B1 TSSTcorp CDDVDW SH-S223B 
CoolingCoolingOSMonitor
Phanteks PH-TC14PE with TY-140's Lamptron FCv5 (x2) Windows 8 Pro 64-bit Dell U2412M 
MonitorMonitorMonitorKeyboard
Dell U2412M Dell U2212HM Dell U2713HM Topre Realforce 87UB | Ducky DK9087 G2 Pro 
PowerCaseMouseMouse Pad
Corsair AX-750 Corsair Obsidian 650D Logitech G700 XTRAC Ripper XXL 
AudioAudioAudioAudio
Beyerdynamic DT-770 Pro 250ohm Schiit Bifrost DAC Schiit Asgard 2 HiVi Swan M50W 2.1 
CPUMotherboardRAMHard Drive
Intel Xeon E5-2620 Super Micro X9SRL-F-B 128GB 1333MHz LSI 9271-8i 
OSPowerCase
VMware ESXi 5.5 SeaSonic SS-400FL2 Fractal Define R3 
CPUMotherboardGraphicsRAM
Intel Core i5-3437U HP EliteBook Folio 9470m  Intel HD Graphics 4000  16GB DDR3 SDRAM 
Hard DriveOS
256GB SSD Windows 10 Insider Preview 
  hide details  
Reply
Ol' Sandy
(28 items)
 
"Zeus"
(12 items)
 
Elite Preview
(6 items)
 
CPUMotherboardGraphicsRAM
Intel Xeon E3-1230v3 Gigabyte GA-Z97X-UD5H-BK MSI Gaming GTX 980 Kingston 32GB (4x8) 
Hard DriveHard DriveHard DriveHard Drive
Plextor PX-256M5S 256GB Samsung EVO 1TB Hitachi HDS721010CLA332 Hitachi HDS723020BLA642 
Hard DriveHard DriveHard DriveOptical Drive
Hitachi HDS723020BLA642 Hitachi HUA722010CLA330 WDC WD10EARS-00Z5B1 TSSTcorp CDDVDW SH-S223B 
CoolingCoolingOSMonitor
Phanteks PH-TC14PE with TY-140's Lamptron FCv5 (x2) Windows 8 Pro 64-bit Dell U2412M 
MonitorMonitorMonitorKeyboard
Dell U2412M Dell U2212HM Dell U2713HM Topre Realforce 87UB | Ducky DK9087 G2 Pro 
PowerCaseMouseMouse Pad
Corsair AX-750 Corsair Obsidian 650D Logitech G700 XTRAC Ripper XXL 
AudioAudioAudioAudio
Beyerdynamic DT-770 Pro 250ohm Schiit Bifrost DAC Schiit Asgard 2 HiVi Swan M50W 2.1 
CPUMotherboardRAMHard Drive
Intel Xeon E5-2620 Super Micro X9SRL-F-B 128GB 1333MHz LSI 9271-8i 
OSPowerCase
VMware ESXi 5.5 SeaSonic SS-400FL2 Fractal Define R3 
CPUMotherboardGraphicsRAM
Intel Core i5-3437U HP EliteBook Folio 9470m  Intel HD Graphics 4000  16GB DDR3 SDRAM 
Hard DriveOS
256GB SSD Windows 10 Insider Preview 
  hide details  
Reply
post #9 of 23
I used Eclipse for my first few classes. It's nice but does a lot very wrong. As soon as I got out of Java and into other languages I just picked up Vim.
The Rig of Power
(18 items)
 
First Build
(13 items)
 
 
CPUMotherboardGraphicsGraphics
Intel i7 3930k Asus P9X79 Pro nVidia 9800 GT nVidia 9800 GT 
RAMHard DriveHard DriveHard Drive
Corsair XMS3 WD Black WD Blue WD Raptor 10,000 RPM 
Hard DriveHard DriveCoolingOS
Corsair Force 3 SSD Seagate Corsiar H80 Windows 7 Ultimate 64-bit 
MonitorKeyboardPowerCase
Dell U2311H Logitech G19 Corsair TX750 Corsair 650D 
MouseAudio
Logitech G500 Logitech G51 
CPUMotherboardGraphicsRAM
Amd Phenom II X3 Asus M4a785TD-V EVO NVIDIA 9800GTX 4 GB G.skill DDR3 @ 1333 mhz 
Hard DriveOSMonitorKeyboard
WD blue250,350(boot,games) WD 1TB black(storage) windows 7 Ultimate 64-bit Dell U2311h Logitech G19 
PowerCaseMouse
500 Watt smilidon Logitech G500 
  hide details  
Reply
The Rig of Power
(18 items)
 
First Build
(13 items)
 
 
CPUMotherboardGraphicsGraphics
Intel i7 3930k Asus P9X79 Pro nVidia 9800 GT nVidia 9800 GT 
RAMHard DriveHard DriveHard Drive
Corsair XMS3 WD Black WD Blue WD Raptor 10,000 RPM 
Hard DriveHard DriveCoolingOS
Corsair Force 3 SSD Seagate Corsiar H80 Windows 7 Ultimate 64-bit 
MonitorKeyboardPowerCase
Dell U2311H Logitech G19 Corsair TX750 Corsair 650D 
MouseAudio
Logitech G500 Logitech G51 
CPUMotherboardGraphicsRAM
Amd Phenom II X3 Asus M4a785TD-V EVO NVIDIA 9800GTX 4 GB G.skill DDR3 @ 1333 mhz 
Hard DriveOSMonitorKeyboard
WD blue250,350(boot,games) WD 1TB black(storage) windows 7 Ultimate 64-bit Dell U2311h Logitech G19 
PowerCaseMouse
500 Watt smilidon Logitech G500 
  hide details  
Reply
post #10 of 23
Thread Starter 
Quote:
Originally Posted by tompsonn View Post

Pseudo-code:
Code:
/* set up our constants */
let const minPrice : 5
let const  maxPrice : 12
let const  minHours : 2
let const  hourIncrementPrice : 1

/* declares an array */
let cars : []

for n 1 to 5
  print "Enter the hours parked for car <n>:"

  /* make sure the input is never less than minimum time. _input is a pseudo variable that captures the user input */
  if _input < minHours
    _input : minHours

  /* calculate the price for parking
   * this adds the minimum price ($5.00) + any additional hours multiplied by the hourly increment ($1.00) 
   */
  cars[n] : minPrice + ( ( _input - minHours ) * hourIncrementPrice )

  /* if the price goes above max price, cap it at max price */
  if cars[n] > maxPrice
    cars[n] : maxPrice
  
end

You should be using a for loop in your Java code, not a while loop:
Code:
for ( j = 0; j < 5; ++j )
{
        /* ... */
}
Ah, so should I redo my entire code then? sadsmiley.gif
My System
(15 items)
 
  
CPUMotherboardGraphicsRAM
i7-2600k ASUS P8P67 Deluxe EVGA GTX 570 SC G.SKILL Ripjaws X 8GB 
Hard DriveHard DriveCoolingOS
Crucial M4 Samsung Spinpoint F3 Prolimatech Megahalems Windows 7 Professional 
MonitorKeyboardPowerCase
Samsung P2450H 24" Ducky Shine Blue LED w/ Cherry MX Reds Corsair HX850 FT02B-W 
Mouse
Razer Death Adder 
  hide details  
Reply
My System
(15 items)
 
  
CPUMotherboardGraphicsRAM
i7-2600k ASUS P8P67 Deluxe EVGA GTX 570 SC G.SKILL Ripjaws X 8GB 
Hard DriveHard DriveCoolingOS
Crucial M4 Samsung Spinpoint F3 Prolimatech Megahalems Windows 7 Professional 
MonitorKeyboardPowerCase
Samsung P2450H 24" Ducky Shine Blue LED w/ Cherry MX Reds Corsair HX850 FT02B-W 
Mouse
Razer Death Adder 
  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 › Need help with arrays in Java