public static boolean isStrobogrammatic(String num) {
// Create a map to store the mapping of strobogrammatic digits HashMap<Character, Character> map = new HashMap<>(); map.put('0', '0'); map.put('1', '1'); map.put('6', '9'); map.put('8', '8'); map.put('9', '6');
// Use two pointers to check if the number is strobogrammatic
int left = 0, right = num.length() - 1; while (left <= right) { char leftDigit = num.charAt(left); char rightDigit = num.charAt(right); if (!map.containsKey(leftDigit) || map.get(leftDigit) != rightDigit) return false; left++; right--; } return true; }
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in); System.out.print("Enter a number: "); String num = scanner.nextLine(); scanner.close();
System.out.println(num + " is strobogrammatic: " + isStrobogrammatic(num));