import java.util.Scanner;
public class HowManyToKeep {
public static void main(String[] args) {
int currentcandies;
int currentamountofpokemon;
int howmanycandiestoevolve;
int keepamount;
int x =0;
Scanner sc = new Scanner(System.in);
System.out.println("Enter how many candies you have: ");
currentcandies = sc.nextInt();
System.out.println("Enter how many pokemon you have: ");
currentamountofpokemon = sc.nextInt();
System.out.println("Enter how many candies to evolve: ");
howmanycandiestoevolve = sc.nextInt();
sc.close();
for (int i=0;i<100;i++) {
int grosstotalcandies = currentcandies + currentamountofpokemon;
int howmanycanevolve = grosstotalcandies/howmanycandiestoevolve;
int totalamountofcandies = howmanycanevolve + grosstotalcandies;
}
keepamount = totalamountofcandies/howmanycandiestoevolve;
System.out.println("The total amount you should keep is: " + keepamount);
}
}
Also meine Frage ist, warum es nicht sagen, dass die Variable „totalamountofcandies“ nicht beheben kann, wenn ich es in der Schleife definiert ? Wie soll ich es zur Arbeit bringenJava: Warum kann dieser Code Arbeit, sagt es, dass mein Variable nicht
weil es im Bereich der for-Schleife definiert ist und daher nicht mehr existiert. – SomeJavaGuy
Das Ziel dieses Codes ist es, automatisch die maximale Menge an Pokemon zu berechnen, die man in Pokemon entwickeln kann, wenn man eine große Menge Pokemon und Bonbons desselben Typs hat. –
Hinweis: Lesen Sie einige Java Code Style Guide Lines. Sie verwenden camelCase für Variablennamen, und überraschenderweise wird growTotalCandies plötzlich für Menschen lesbar! – GhostCat