jeudi 5 septembre 2019

Why wont this program give me the sum of two variables

I very new to coding. I have been tasked with creating a program that will allow the user to input two int variables and then use a What If statement to give me the sum of the two variables. But when I run the program, I keep getting "0" as the sum.}

import java.util.Scanner;

public class WhatIf {

public static void main(String[] args) {

    Scanner keyboard  = new Scanner(System.in);
    int firstNumber = 0 , secondNumber = 0 ;
    int sum = firstNumber + secondNumber;

        System.out.println("Enter First Number: " );
        firstNumber = keyboard.nextInt();

        System.out.println("Enter Second Number ");
        secondNumber = keyboard.nextInt();



        System.out.println("Sum of the two numbers is: " + sum);
    }

}

Aucun commentaire:

Enregistrer un commentaire