My loop doesn't end | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

My loop doesn't end

With help of people in this forum, I managed to fix those errors. But theres one last thing. Even after using the "System.exit(0);" command but my program doesn't close. Help would be appreciated. ------------------------------------------------------------------------- package vehiclesimulator; import java.util.Scanner; public class Bycicle { static int speed = 0; static int size = 10; static int increment = 5; static int decrement = 10; static String PaintColor = ""; static int Initial = 1; static void Printstates(){ if(Initial==(1)){PaintColor = "Yellow";} else {PaintColor= "Black"; } System.out.println("speed:" + speed + "size:" + size + "color:" + PaintColor);} static void speedUp() { speed = speed + 5; } static void applyBrakes() { speed = speed - 10; } static void Paint(){ Initial = 2; } static void End(){System.exit(0);} public static Scanner scan = new Scanner(System.in); private static void programStart(){ String INPUT; INPUT = scan.nextLine(); if("Faster".equals(INPUT)){ speedUp(); programStart(); } if("Slower".equals(INPUT)){ applyBrakes(); programStart(); } if("Paint".equals(INPUT)){ Paint(); programStart(); } if("Check".equals(INPUT)){ Printstates();} programStart(); if("End".equals(INPUT)) System.exit(0); } public static void main(String[]args) { programStart(); } } --------------------------------------------------------------------------------

6th Jun 2017, 12:28 PM
MassiveMayhem
2 Answers
+ 1
Take a look at if("Check".equals(INPUT)){ Printstates();} //<-- closing bracket. programStart(); So the program never gets to the End part.
6th Jun 2017, 12:43 PM
Dennis
Dennis - avatar
+ 1
Oh! I didn't even notice that. Thanks for the advice Dennis!
7th Jun 2017, 4:53 AM
MassiveMayhem