- 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"); } }
3 ответов
+ 3
Read the problem again carefully.
High Five when over 10
means a > 10
(not equal)
+ 2
Thank you for your comment! Tibor Santa
I could solve it.
+ 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));
}
}
}