#Why does my value get added in the loop

18 messages · Page 1 of 1 (latest)

bright atlas
#

i want to count how many times the loop is run but every time i run the program it always prints the initial value of 0.

heres the original problem incase its necessary https://dmoj.ca/problem/ccc20j2

`import java.util.Scanner;

public class epidemiology
{
public static void main (String [] args)
{
Scanner scan = new Scanner (System.in);
int P=scan.nextInt();
scan.nextLine();
int N=scan.nextInt();
scan.nextLine();
int R = scan.nextInt();
scan.nextLine();
int dayz=NR;
int count=0;
for(int infections=0;infections>=P;) {
infections=dayz
R;
count++;
}
System.out.println(count);
scan.close();

}

}`
boreal oysterBOT
#

This post has been reserved for your question.

Hey @bright atlas! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

silk rain
#

when a orogram is stopped, everything it has in memory is erased

#

in order for something to be persisted, you need to store it on disk (and load it again)

bright atlas
#

ok how can i do that

silk rain
#

you write it to a file

#

First, you need to think about tze location to store it (file path) and what you actually want to persist

#

e.g. you could store it right where you run the program

bright atlas
#

is there any other way

#

im relatively new so i dont know how to use files

silk rain
#

files are the easiest way to do it

bright atlas
#

ok thanks ig

silk rain
bright atlas
#

thats fine

#

i cant rn anyways

#

but thansk for your help

light sand
#

Hi @bright atlas , with "i want to count how many times the loop is run" you are trying to solve the original problem or is a following question? Because you don't need that in order to solve the exercise.