- 1
For loop code coach problem
I can not understand the meaning of the problem How to solve it normally? https://code.sololearn.com/cfj26I1DB7R6/?ref=app
13 Respuestas
+ 6
Thank you :)
In your if statement you have to use Logical or(||) .
Like this
if(i == firstBadGuy || i == secondBadGuy )
+ 4
Yaroslav Yatsyk try this way,
for(int i = 1; i <= 7; i++) {
if(i == firstBadGuy || i == secondBadGuy ) {
System.out.println("Bad guy");
}
else {
System.out.println("Good guy");
}
+ 3
Can you please share the problem description as well?
+ 3
Yaroslav Yatsyk Why did you change your for loop?
It was correct before 😅
+ 3
Ohh... Okay!! 👍
Hope now your problem is solved )
+ 1
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner read = new Scanner(System.in);
int firstBadGuy = read.nextInt();
int secondBadGuy = read.nextInt();
//your code goes here
for(int i = 1; i <= 7; i++) {
if(i == firstBadGuy || i == secondBadGuy ) {
System.out.println("Bad guy");
}
else {
System.out.println("Good guy");
}
}
}
}
0
Ok thanks)
0
Oh yeah, it has worked. Thanks a lot)
0
I changed a condition at code coach section)
0
Yes, sure)
0
for(int i = 1; i <= 7; i++) {
if(i == firstBadGuy || i == secondBadGuy ) {
System.out.println("Bad guy");
}
else {
System.out.println("Good guy");
}
understand this code but whenI read it i dont get how it works for the value of "4"? can anyone explain that
0
//your code goes here
for( int x=1,y=1 ; x<=7 && y<=7 ; x++,y++) {
if(firstBadGuy==x) {
System.out.println("Bad guy");
}
if (secondBadGuy==y){
System.out.println("Bad guy");
}
if(firstBadGuy!=x && secondBadGuy!=y){
System.out.println("Good guy");
}
}
- 1
Here is
You are a game developer and the game you currently working on a deck dealer which deals 7 cards representing the players’ roles.
5 of them are good guys and 2 of them are bad guys.
Write a program that will take the bad guys numbers as input and output all the roles accordingly.
Sample Input
1
4
Sample Output
Bad guy
Good guy
Good guy
Bad guy
Good guy
Good guy
Good guy
Explanation
The 1st and the 4th role is "Bad guy".