id/email
password
forgot password | create account
about | help | code help+videos | done | prefs
CodingBat code practice

 

jebbert@volusia.k12.fl.us > yodaLightSaber
prev  |  next  |  chance

Yoda has asked you to write a method to determine who will win a light saber battle. Two players will enter a simulated battle. Each player will have an attack and defense value. Each player's attack value decreases the other player's defense value. The player with the higher remaining defense value wins. Return 1 if player 1 wins, 2 if player 2 wins, or 0 if there is a tie.


yodaLightSaber(5, 7, 1, 8) → 1
yodaLightSaber(3, 12, 4, 11) → 0
yodaLightSaber(5, 10, 3, 20) → 2

...Save, Compile, Run (ctrl-enter)

public int yodaLightSaber(int attack1, int defense1, int attack2, int defense2) { }

Editor font size %:
Shorter output


Forget It! -- delete my code for this problem

Progress graphs:
 Your progress graph for this problem
 Random user progress graph for this problem
 Random Epic Progress Graph

Java Help

Misc Code Practice

Difficulty: 230

Copyright Nick Parlante 2017 - privacy