0

Cheer Creator Challenge

import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner input = new Scanner(System.in); double yards = input.nextDouble(); if (yards > 10.00){ System.out.println("High Five"); } if (yards < 1.00){ System.out.println("shh"); } if (yards >1.00 && yards < 10.00){ while (yards > 1.00 && yards < 10.00){ System.out.println("Ra!"); yards++; } } } } I am having trouble with this code. I got all of the samples right accept one of the ones I cannot see.

11th Dec 2020, 4:15 PM
Ben Szydlowski
6 Antworten
+ 1
Ben Szydlowski , for the last case try the String repeat method. The code could look like: import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner input = new Scanner(System.in); int yards = input.nextInt(); if (yards < 1){ System.out.print("shh"); } else if (yards > 10){ System.out.print("High Five"); } else { String msg = "Ra!".repeat(yards); System.out.print(msg); } } }
11th Dec 2020, 5:02 PM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar
+ 1
Ben Szydlowski That's normal, the purpose of having hidden test cases is so that a solver will create a code or an algorithm that satisfies and works with every inputs. If test cases were available to be seen by users, then the outputs will just be easily print out instead of creating algorithms and patterns.
11th Dec 2020, 5:24 PM
noteve
noteve - avatar
+ 1
《 Nicko12 》 that makes sense i just dont know which part to fix haha
11th Dec 2020, 5:27 PM
Ben Szydlowski
0
TheWh¡teCat 🇧🇬 Simba i dont think the problem is with the last repeating case because one of the samples i can see, it repeats it successfully. The problem is with one of the sample i cannot see so i dont know whats wrong
11th Dec 2020, 5:23 PM
Ben Szydlowski
0
I got it! I had to switch to yards-- and set the while to <= 10
11th Dec 2020, 5:50 PM
Ben Szydlowski
0
import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner input = new Scanner(System.in); double yards = input.nextDouble(); if (yards > 10.00){ System.out.println("High Five"); } else if (yards < 1.00){ System.out.println("shh"); } else if (yards >= 1.00 && yards <= 10.00){ while (yards >= 1.00 && yards <= 10.00){ System.out.println("Ra!"); yards--; } } } }
11th Dec 2020, 5:50 PM
Ben Szydlowski