+ 4
Coding challenges
Hi, guys! I'm struggeling a lot with the general setting of coding challenges... I'm given a specified type of input and I am required to create a specified output depending on the input. My problem is that I don't get, how to deal with the input. I am not given a specific method (with a name) to implement, so, where does the input need to be plugged in? All the stuff I tried failed: -implement a static method, which takes the input and returns the output -implement a method in the main which does... -implement a method for an object of the class, which does the required things. I don't see other options, which seem to be meaningful. Maybe it's obvious and you'll tell me that I'm stupid but, anyway, I can't get it 😅
15 Respuestas
0
The input will be a number, so we will use int.
int yards = input.nextInt();
Now, the variable yards has stored the number, so you can use it in your conditionals.
Another tip: remember that the output of your code is case sensitive. So if you output ra! instead of Ra!, It will fail.
+ 4
import java.util.*;
public class Program
{
public static void main(String[] args) {
Scanner sa=new Scanner(System.in);
int sb=sa.nextInt();
if(sb>10){
System.out.println("High Five");}
if(sb<1){
System.out.println("shh");}
else{for(int i=1;i<=sb;i++){
System.out.print("Ra!");}}
}
}
the third case are not completed and this third case are hidden how can i solve this plz solve my query
+ 2
You are making a program for a bus service.
A bus can transport 50 passengers at once.
Given the number of passengers waiting in the bus station as input, you need to calculate and output how many empty seats the last bus will have.
Can anyone solve this sololearn challenge ?
+ 1
Yes, the Challenges are from SoloLearn and I try to program in java!
+ 1
Ah, ok. For any reasons I haven't thought of an explicit input function... As a beginner I haven't dealt with such tasks much...
Thanks a lot, that makes everything obvious!
+ 1
Don't forget to import the Scanner class.
import java.util.Scanner;
+ 1
Yeah, thanks! I would have actually forgotten it 😂
+ 1
No problem, if you need a hand, just ask!
0
You are cheering on your favorite team. After each play, if your team got over 10 yards further down the field, you stand up and give your friend a high five. If they don't move forward by at least a yard you stay quiet and say 'shh', and if they move forward 10 yards or less, you say 'Ra!' for every yard that they moved forward in that play.
Task
Given the number of yards that your team moved forward, output either 'High Five' (for over 10), 'shh' (for <1), or a string that has a 'Ra!' for every yard that they gained.
Input Format
An integer value that represents the number of yards gained or lost by your team.
Output Format
A string of the appropriate cheer.
Sample Input
3
Sample Output
Ra!Ra!Ra!
0
This is what I'm trying to do.
The program logic itself is very easy, it's not the thing I am struggling with.
I just don't know, how the testing method plugs in the values....
0
Btw it's called "Cheer Creator"
0
#include <iostream>
using namespace std;
int main() {
int no_of_yards;
cin>>no_of_yards;
if(no_of_yards <1){
cout<<"shh";
}
if(no_of_yards >=1){
for(int x = 1; x<= no_of_yards ;x++){
cout<<"Ra!";
}
}
if(no_of_yards ==10){
cout<<"High Five";
}
return 0;
}
Can anyone can give me
Solution of this
My code pass test 1, 2, 5 but not 3,4
Please help me
0
I do it
0
Can you tell me that code
- 1
In what programming language? Can you add an example of the challenge? Are the challenges from Sololearn?