0

17.2 Java please help, I don’t understand

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(); for(int c=1; c<=7; c++) { System.out.println("Good Guy"); } } } That’s all😔 please do not write an answer, try to explain how to do it

20th Apr 2021, 5:26 PM
Igaman Igaman
Igaman Igaman - avatar
17 Antworten
+ 2
When you click on the question the question is divided into 3 sections. Problem,code and result. I am asking you to copy the problem section and paste it here
20th Apr 2021, 5:46 PM
Atul [Inactive]
+ 2
@Denise Roßberg Ok, I was wondering, because in the explanation it shows them as strings, but his code shows getting ints. Anyway similar principle just loop and compare ints instead, without the use of the array.
20th Apr 2021, 6:28 PM
ChaoticDawg
ChaoticDawg - avatar
+ 1
Post your question here
20th Apr 2021, 5:38 PM
Atul [Inactive]
+ 1
I said question the explanation provided . Don't post you code again and again
20th Apr 2021, 5:40 PM
Atul [Inactive]
+ 1
Igaman Igaman What you need inside your loop is an if/else statement. compare the value of c with the values of firstBadGuy and secondBadGuy -> equal? print "Bad Guy" else print "Good Guy".
20th Apr 2021, 6:18 PM
Denise Roßberg
Denise Roßberg - avatar
+ 1
Igaman Igaman Try making a String array with the values "one", "two", "three"... etc. Then loop over the array using an enhanced for loop. In the loop check the current value of the array against the values of firstBadGuy and secondBadGuy. If firstBadGuy or secondBadGuy is equal() to the current value of the array, then output "Bad guy" else output "Good guy"
20th Apr 2021, 6:23 PM
ChaoticDawg
ChaoticDawg - avatar
+ 1
ChaoticDawg The values are given as integers in this task.
20th Apr 2021, 6:25 PM
Denise Roßberg
Denise Roßberg - avatar
0
You are not using the variables firstbadguy and secondbadguy
20th Apr 2021, 5:35 PM
Atul [Inactive]
0
Post your question too
20th Apr 2021, 5:35 PM
Atul [Inactive]
0
I think use “break” and “continue” Yeah?
20th Apr 2021, 5:36 PM
Igaman Igaman
Igaman Igaman - avatar
0
???
20th Apr 2021, 5:43 PM
Igaman Igaman
Igaman Igaman - avatar
0
You are playing and now you are working on a game that deals 7 cards that indicate the roles of the players. 5 of them give the role of the good guys, and 2 - the bad. Write a bad program that will accept password numbers as input and enter all roles accordingly. Sample input one four Result example Bad guy Good guy Good guy Bad guy Good guy Good guy Good guy Explanation 1st and 4th roles - "Bad guy".
20th Apr 2021, 5:49 PM
Igaman Igaman
Igaman Igaman - avatar
0
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(); for (int x = 0; x <=7; x++) { if (x >= 5) { break; } System.out.println("Good guy"); if ( x >= 2) { continue; } System.out.println("Bad guy"); } } } 😆😆😆
20th Apr 2021, 6:22 PM
Igaman Igaman
Igaman Igaman - avatar
0
.........
20th Apr 2021, 7:42 PM
Igaman Igaman
Igaman Igaman - avatar
0
I didn't succeed, I don't have enough brains to figure out how to substitute the method variables
21st Apr 2021, 4:16 AM
Igaman Igaman
Igaman Igaman - avatar
0
Common, give me something
21st Apr 2021, 2:48 PM
Igaman Igaman
Igaman Igaman - avatar
0
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 x = 1; x<=7; x++){ if(x == firstBadGuy || x == secondBadGuy){ System.out.println("Bad guy"); } else{ System.out.println("Good guy"); } } } } make an if else statement that runs "bad guy"if x == firstBadGuy || x == secondBadGuy. The else part is if x isn't == to
23rd Feb 2022, 11:59 PM
Naveel Naveed