+ 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 😅

29th Jan 2020, 7:28 PM
jozhyk
jozhyk - avatar
15 Réponses
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.
29th Jan 2020, 7:50 PM
Fernando Pozzetti
Fernando Pozzetti - avatar
+ 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
25th Mar 2020, 6:27 PM
Santosh Singh
Santosh Singh - avatar
+ 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 ?
23rd Nov 2020, 1:28 PM
Premlata Kumari
Premlata Kumari - avatar
+ 1
Yes, the Challenges are from SoloLearn and I try to program in java!
29th Jan 2020, 7:44 PM
jozhyk
jozhyk - avatar
+ 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!
29th Jan 2020, 7:52 PM
jozhyk
jozhyk - avatar
+ 1
Don't forget to import the Scanner class. import java.util.Scanner;
29th Jan 2020, 7:53 PM
Odyel
Odyel - avatar
+ 1
Yeah, thanks! I would have actually forgotten it 😂
29th Jan 2020, 7:54 PM
jozhyk
jozhyk - avatar
+ 1
No problem, if you need a hand, just ask!
29th Jan 2020, 7:57 PM
Fernando Pozzetti
Fernando Pozzetti - avatar
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!
29th Jan 2020, 7:44 PM
jozhyk
jozhyk - avatar
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....
29th Jan 2020, 7:46 PM
jozhyk
jozhyk - avatar
0
Btw it's called "Cheer Creator"
29th Jan 2020, 7:48 PM
jozhyk
jozhyk - avatar
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
8th May 2020, 2:26 PM
Koshlendra Parmar
Koshlendra Parmar - avatar
0
I do it
2nd Jun 2020, 5:45 PM
Koshlendra Parmar
Koshlendra Parmar - avatar
0
Can you tell me that code
22nd Jun 2020, 5:43 AM
GANDLURU KULA KRISHNA REDDY
GANDLURU KULA KRISHNA REDDY - avatar
- 1
In what programming language? Can you add an example of the challenge? Are the challenges from Sololearn?
29th Jan 2020, 7:42 PM
Fernando Pozzetti
Fernando Pozzetti - avatar