Skip to content

Instantly share code, notes, and snippets.

@princesanjivy
Created April 11, 2024 16:29
Show Gist options
  • Save princesanjivy/1dd26bc5dfc51b686d375e9da211ca97 to your computer and use it in GitHub Desktop.
Save princesanjivy/1dd26bc5dfc51b686d375e9da211ca97 to your computer and use it in GitHub Desktop.
Example micro-app program in Java
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