Задача Walking
При поствапне в judge ми дава 40 от 100.Къде ми е грешката?Благодаря предварително
Код:
import java.util.Scanner;
public class Wallking {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int daySteps = Integer.parseInt(scanner.nextLine());
int totalSteps = 0;
String input = scanner.nextLine();
while (totalSteps >= 10000) {
totalSteps += daySteps;
daySteps++;
break;}
System.out.println("Goal reached! Good job!");
if (input.equals("Going home")) {
int finalSteps = Integer.parseInt(scanner.nextLine());
totalSteps += finalSteps;
daySteps++;
int finalResult = 10000 - totalSteps;
System.out.printf("%d more steps to reach goal.", finalResult);
}
}
}
Здравей.Благодаря за отговора.Справих се с проблема по следния начин:
import java.util.Scanner;
public class Wallking {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String steps=scanner.nextLine();
int allSteps=0;
int krachki=0;
while (allSteps < 10000) {
if(!steps.equals("Going home")){
krachki=Integer.parseInt(steps);
allSteps+=krachki;
if (allSteps>=10000){
System.out.println("Goal reached! Good job!");
break;
}
steps=scanner.nextLine();
}else{
steps=scanner.nextLine();
krachki=Integer.parseInt(steps);
allSteps+=krachki;
if(allSteps<10000){
System.out.printf("%d more steps to reach goal.",10000-allSteps);
}else{
System.out.println("Goal reached! Good job!");
}
break;
}
}
}
}