- 1

[Java] Please help me about cheer creator [codecoach]

This is "cheer creator" question in codecoach. Only #4 isn't solved. How to correct my code? (Sorry for poor English.) import java.util.Scanner; public class Program { int a; public static void main(String[] args) { Scanner scn = new Scanner(System.in); int a = scn.nextInt(); if(10>a&&a>=1) for(int i=0;i<a;i++) System.out.print("Ra!"); else if(10<=a) System.out.print("High Five"); else if(a<1) System.out.print("shh"); } }

14th Mar 2020, 3:01 PM
Sayaka
Sayaka - avatar
3 odpowiedzi
+ 3
Read the problem again carefully. High Five when over 10 means a > 10 (not equal)
14th Mar 2020, 3:20 PM
Tibor Santa
Tibor Santa - avatar
+ 2
Thank you for your comment! Tibor Santa I could solve it.
15th Mar 2020, 12:34 PM
Sayaka
Sayaka - avatar
+ 2
import java.util.*; public class Program { public static void main(String[] args) { int input; String str="Ra!"; Scanner sc=new Scanner(System.in); input=sc.nextInt(); if(input>10) { System.out.println("High Five"); } else if(input<=0) { System.out.println("shh"); } else { System.out.println(str.repeat(input)); } } }
13th Apr 2020, 4:41 AM
kartik narang
kartik narang - avatar