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
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
+ 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.
+ 1
Post your question here
+ 1
I said question the explanation provided . Don't post you code again and again
+ 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".
+ 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"
+ 1
ChaoticDawg
The values are given as integers in this task.
0
You are not using the variables firstbadguy and secondbadguy
0
Post your question too
0
I think use “break” and “continue”
Yeah?
0
???
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".
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");
}
}
}
😆😆😆
0
.........
0
I didn't succeed, I don't have enough brains to figure out how to substitute the method variables
0
Common, give me something
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