Posts

Showing posts with the label while-loop

How to repeat input using a while loop with a sentinal

How to repeat input using a while loop with a sentinal I need help with regards to where to put a while loop on this code. I just began studying Java a few weeks ago. I would like to write in a sentinel value of -1, if entered, the program shall exit. As long as user input is not -1, keep asking repeating the program. When I put the while loop, "while(currentPop != -1)" , below the first question, "Enter current population", the program runs its first course successfully. However, it does not loop back to the first question. Instead, it goes directly to the second question, "Enter birth rate:". How shall I proceed and make sure that the first question keeps getting asked after running through the loops? Thank you all! import java.util.Scanner; public class Population { public static void main(String args) { Scanner scan = new Scanner(System.in); double birthRate, deathRate; double currentPop = 0; double newPop; ...

Using Eclipse Java Photon I have written a code with a While loop that is ending after one loop [closed]

Using Eclipse Java Photon I have written a code with a While loop that is ending after one loop [closed] I am writing a code in Eclipse for a class. The code contains a while loop but is not looping. As far as I know the parameters of the loop are being met. This is a program for a Finch robot. After the fist loop I get a message that says "Picked up _JAVA_OPTIONS_: -Xmx512M. I found a post that said to delete that for the system environment but it didn't work. import java.util.*; import edu.cmu.ri.createlab.terk.robot.finch.Finch; /** * Created by: * Date: * A starter file to use the Finch */ public class FinchTemplateFile { public static void main(final String args) { // Instantiating the Finch object Finch myFinch = new Finch(); //Read clock to call out time Date d1 = new Date(); // Light sensor feedback for program start // Continues as long as finch is beak up while (myFinch.isBeakUp() && (myFinch.getRightLightSensor() > 1)); { //Say ...