Created
April 11, 2024 16:29
-
-
Save princesanjivy/1dd26bc5dfc51b686d375e9da211ca97 to your computer and use it in GitHub Desktop.
Example micro-app program in Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
public class Main { | |
public static void main(String[] args) { | |
// Create a Scanner object to read input from the user | |
Scanner scanner = new Scanner(System.in); | |
// Ask the user to enter the first number | |
System.out.print("Enter the first number: "); | |
System.out.println("<get-input>");int num1 = scanner.nextInt(); | |
// Ask the user to enter the second number | |
System.out.print("Enter the second number: "); | |
System.out.println("<get-input>");int num2 = scanner.nextInt(); | |
// Close the scanner to prevent resource leak | |
scanner.close(); | |
// Calculate the sum | |
int sum = num1 + num2; | |
// Display the result | |
System.out.println("The sum of " + num1 + " and " + num2 + " is " + sum); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment