Level: 5
Base Power: 100
Final Power: 248.832
import java.lang.Math;
// Function to generate random integer between a and b
public int randInt(int a, int b) {
return (int)(Math.random() * (b - a + 1)) + a;
}
// Generate random rarity and setup gold
int rarity = randInt(1, 100);
int gold = 0;
// Determine gold based on rarity
if (rarity >= 1 && rarity <= 60) {
gold = randInt(10, 30);
}
else if (rarity >= 61 && rarity <= 85) {
gold = randInt(31, 70);
}
else if (rarity >= 86 && rarity <= 100) {
gold = randInt(71, 100);
}
// Print results
System.out.println("Loot Drop!");
System.out.println("Rarity: " + rarity);
System.out.println("Collected New Item!");
System.out.println("Gold: " + gold);
Loot Drop!
Rarity: 15
Collected New Item!
Gold: 10
import java.lang.Math;
public static int healthDifference(int playerHealth, int enemyHealth) {
return Math.abs(playerHealth - enemyHealth);
}
public int randInt(int a, int b) {
return (int)(Math.random() * (b - a + 1)) + a;
}
int playerHealth = randInt(10, 200);
int enemyHealth = randInt(10, 200);
int healthDiff = healthDifference(playerHealth, enemyHealth);
System.out.println("Player Health: " + playerHealth);
System.out.println("Enemy Health: " + enemyHealth);
System.out.println("Health Difference: " + healthDiff);
Player Health: 109
Enemy Health: 152
Health Difference: 43
import java.lang.Math;
public static double damageCalculator(double base, double powerLevel) {
return base * (powerLevel / 100);
}
public int randInt(int a, int b) {
return (int)(Math.random() * (b - a + 1)) + a;
}
double base = randInt(10, 50);
double powerLevel = randInt(1, 5);
double damage = damageCalculator(base, powerLevel);
System.out.println("Base Damage: " + base);
System.out.println("Power Level: " + powerLevel);
System.out.println("Total Damage: " + damage);
Base Damage: 43.0
Power Level: 1.0
Total Damage: 0.43
import java.lang.Math;
public static int findDistance(int x1, int y1, int x2, int y2) {
return (int)(Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2)));
}
public static int randInt(int a, int b) {
return (int)(Math.random() * (b - a + 1)) + a;
}
int x1 = randInt(0, 10);
int y1 = randInt(0, 10);
int x2 = randInt(0, 10);
int y2 = randInt(0, 10);
int distance = findDistance(x1, y1, x2, y2);
System.out.println("Point 1: (" + x1 + ", " + y1 + ")");
System.out.println("Point 2: (" + x2 + ", " + y2 + ")");
System.out.println("Distance: " + distance);
Point 1: (2, 10)
Point 2: (4, 3)
Distance: 7
Loot Found!
Loot Value: 22