Football season is just getting started. In football, when a player breaks loose
ID: 3887331 • Letter: F
Question
Football season is just getting started. In football, when a player breaks loose and will apparently score, the TV/Radio announcer will announce which yard line the player is on in 5-yard increments.
A) Write a FOR loop that displays the name of your favorite player, and which yard line he is on, starting at the 50, and decrementing to the 5. When the player crosses the goal line, you should display “Touchdown <name of your favorite team>. Store the name of your favorite player, and your favorite team in string variables. Name this class TouchdownFor.java. For example, if your favorite team is Kentucky, and your favorite player is Towles, the output should look like this:
B) Modify your program to work as a WHILE loop and display the same information. Name this TouchdownWhile.java.
UsersBrianDesktopJava Touch down For Towles is at the 50 Towles is at the 45 Towles is at the 40 Towles is at the 35 Towles is at the 30 Towles is at the 25 Towles is at the 20 Towles is at the 15 Towles is at the 10 Towles is at the 5 Touchdown Kentucky!Explanation / Answer
TouchdownFor.java
public class TouchdownFor {
public static void main(String[] args) {
String teamName = "Kentucky";
String playerName = "Towles";
for(int i=50;i>0;i-=5){
System.out.println(playerName+" is at the "+i+"!");
}
System.out.println("Touchdown "+teamName+"!");
}
}
Output:
Towles is at the 50!
Towles is at the 45!
Towles is at the 40!
Towles is at the 35!
Towles is at the 30!
Towles is at the 25!
Towles is at the 20!
Towles is at the 15!
Towles is at the 10!
Towles is at the 5!
Touchdown Kentucky!
TouchdownWhile.java
public class TouchdownWhile {
public static void main(String[] args) {
String teamName = "Kentucky";
String playerName = "Towles";
int i=50;
while(i>0){
System.out.println(playerName+" is at the "+i+"!");
i-=5;
}
System.out.println("Touchdown "+teamName+"!");
}
}
Output:
Towles is at the 50!
Towles is at the 45!
Towles is at the 40!
Towles is at the 35!
Towles is at the 30!
Towles is at the 25!
Towles is at the 20!
Towles is at the 15!
Towles is at the 10!
Towles is at the 5!
Touchdown Kentucky!