Whenever the last reference to an object is lost the object becomes garbage---a section of memory that is no longer in use. A part of the Java system called the garbage collector periodically looks through memory for garbage, which it the makes ready for use with new objects.
Write a program that has a loop that iterates 1000 times. The loop body will use a constructor to create a String object. Click here to go back to the main menu.
Write a program that adds up five floating point numbers input from a file (or from the keyboard.) As always with input from text files, use readLine() to get a string of characters. This string must contain only characters that designate a floating point number, like -0.184 or 1.23E+12. Characters that designate an integer, like 412 will also work for floating point input. Recall how to convert a string into a floating point number:
Click here to go back to the main menu.String lineIn; double val; . . . val = ( Double.valueOf( lineIn ) ).doubleValue();
Modify the program that adds five integers so that it first asks if further prompts are desired. The user enters "yes" or "no" (just once, at the beginning). Now the loop either prompts or does not prompt for each of the integers to be input.
You will need to use the equals() method of String. Set a boolean variable to true or false depending on the user's first input string. There will be an if statement inside the loop that determines if a prompt is written.
Click here to go back to the main menu.