I made a simple calculator to calculate the total time of songs. Iam using a while function but I dont know how to break it. Because of this I had to make it go on forever and after each new imput from me, it writes back the total time up to this point.
Example:
12 21 12:21 31 41 44:02
the bold is what i type in and the non bold is what the eclipse writes back to me.
What I want is that i type in X amount of numbers, and when iam done I press some key, escape for example and then it would write back the total time..
here is my full code
import java.util.Scanner;
public class train {
public static void main(String[] args) {
int songM, songS, totalS=0, totalM=0, y=1;
Scanner scan = new Scanner(System.in);
System.out.println("write songs, exit with -1");
while(y > 0) {
songM = scan.nextInt();
songS = scan.nextInt();
totalM = songM + totalM;
totalS = songS + totalS;
if(totalS >59) {
totalM = totalM + 1;
totalS = totalS % 60;
}
if(totalS<=9) {
System.out.println(totalM+":0"+totalS );
} else {
System.out.println(totalM+":"+totalS );
}
}
}
}