Skip to content

Instantly share code, notes, and snippets.

@MrRahulR
Last active May 25, 2021 16:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MrRahulR/ee292b72fe4554189008ee2b90db5dd2 to your computer and use it in GitHub Desktop.
Save MrRahulR/ee292b72fe4554189008ee2b90db5dd2 to your computer and use it in GitHub Desktop.
VariableDemo,java
public class VariableDemo {
public static void main(String[] args) {
double profit, principle = 1000, interestRate = 0.0625; // it is possible to initialize at creation time
int numOfYears = 5;
// Calculate profit after the given number of years
// Notice that until this point, profit is still uninitialized
profit = principle * interestRate * numOfYears;
System.out.println("The profit after " + numOfYears + " years is: " + profit + "$.");
}
}
/*
Output : The profit after 5 years is: 312.5$
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment