For loop code coach problem | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
- 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

31st Oct 2020, 1:54 AM
Yaroslav Yatsyk
Yaroslav Yatsyk - avatar
13 Answers
+ 6
Thank you :) In your if statement you have to use Logical or(||) . Like this if(i == firstBadGuy || i == secondBadGuy )
31st Oct 2020, 2:42 AM
Minho
Minho - avatar
+ 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"); }
31st Oct 2020, 2:44 AM
0_O-[Mägár_Sám_Äkà_Nüllpøïntêr_Èxëcéptïön]~~
0_O-[Mägár_Sám_Äkà_Nüllpøïntêr_Èxëcéptïön]~~ - avatar
+ 3
Can you please share the problem description as well?
31st Oct 2020, 2:37 AM
Minho
Minho - avatar
+ 3
Yaroslav Yatsyk Why did you change your for loop? It was correct before 😅
31st Oct 2020, 2:49 AM
Minho
Minho - avatar
+ 3
Ohh... Okay!! 👍 Hope now your problem is solved )
31st Oct 2020, 2:53 AM
Minho
Minho - avatar
+ 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"); } } } }
14th Oct 2021, 6:07 PM
Bernard Towindo
Bernard Towindo - avatar
0
Ok thanks)
31st Oct 2020, 2:43 AM
Yaroslav Yatsyk
Yaroslav Yatsyk - avatar
0
Oh yeah, it has worked. Thanks a lot)
31st Oct 2020, 2:45 AM
Yaroslav Yatsyk
Yaroslav Yatsyk - avatar
0
I changed a condition at code coach section)
31st Oct 2020, 2:51 AM
Yaroslav Yatsyk
Yaroslav Yatsyk - avatar
0
Yes, sure)
31st Oct 2020, 2:54 AM
Yaroslav Yatsyk
Yaroslav Yatsyk - avatar
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
24th Jul 2021, 3:39 PM
lemuel leriche
lemuel leriche - avatar
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"); } }
11th Sep 2021, 2:13 AM
Jaime Tovar
Jaime Tovar - avatar
- 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".
31st Oct 2020, 2:38 AM
Yaroslav Yatsyk
Yaroslav Yatsyk - avatar