Java tutorial for beginners with clear explanations – Easy-to-follow Java programming




Java tutorial for beginners with easy-to-follow content. Buy the complete Java programming course (15 more Java tutorials) at Duckademy: …

Original source


31 responses to “Java tutorial for beginners with clear explanations – Easy-to-follow Java programming”

  1. Hi! I have a question. I tried to modify the "Fightning" code from your example by adding a loop while either the character's or monster's HP is different than 0, but I don't know how to make the remaining HP from the first fight counts for the consecutive fights (ex: if the first fight I got attacked and 90 HP remained from 100, the damage from the next battle will be taken from 90 and not 100). I will copy my code here, Thanks!

    import java.util.Scanner;
    import java.util.Random;
    public class Fightning {

    public static void main(String[] args) {
    Scanner sc= new Scanner(System.in);
    System.out.println("Attack value of monster: ");
    int monsterAttack= sc.nextInt();
    System.out.println("Defense value of monster: ");
    int monsterDefense= sc.nextInt();
    System.out.println("Life points of monster: ");
    int monsterLP= sc.nextInt();

    System.out.println("Attack value of character: ");
    int characterAttack= sc.nextInt();
    System.out.println("Defense value of character: ");
    int characterDefense= sc.nextInt();
    System.out.println("Life points of character: ");
    int characterLP= sc.nextInt();

    int characterremainingLP= characterLP – (monsterAttack – characterDefense);
    int monsterremainingLP= monsterLP – (characterAttack – monsterDefense);

    Random generator= new Random();
    int characterDice = generator.nextInt(6)+1 + generator.nextInt(6)+1;
    System.out.println("You rolled: "+ characterDice);
    int monsterDice = generator.nextInt(6)+1 + generator.nextInt(6)+1;
    System.out.println("Your opponent rolled: "+ monsterDice);
    if (characterDice > monsterDice){
    System.out.println("You attack!");
    if (characterAttack > monsterDefense){
    System.out.println("Nice hit! nMonster remaining LP: "+ monsterremainingLP);
    if (monsterremainingLP <= 0)
    System.out.println("Congratulations! You defeated the enemy");
    }else{
    System.out.println("You did no damage!");
    }
    }
    else{
    System.out.println("Monster attacks!");

    if (monsterAttack > characterDefense)
    System.out.println("Ouch! That hurts! nRemaining LP: "+ characterremainingLP);
    if (characterremainingLP <= 0){
    System.out.println("You died");
    }else{
    System.out.println("You received no damage");
    }
    }
    }
    }

  2. This guy's Java presentations are excellent and have no competitors that I can find. My only negative hardly counts over against the clarity, consideration, and outstanding content of his videos; yes, for less that a mere $20 bucks (US) you can download his excellent videos on Java.
    I started my search for Java resources a week ago, which includes a subscription to Lynda.com, and believe me Fisher's Java presentation does not hold a candle to this guys content and presentation skills. My negative, his accent. Otherwise, I STRONGLY RECOMMEND making this Duckademy IT course part of you education.
    eddie evans – ClimateDeception.Net

Leave a Reply