Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

public class Main {
    /**
     * Get the mnemonic from the given text. The mnemonic is marked by a leading & character.
     * @param text The mnemonic search text.
     * @return The mnemonic or -1 if no mnemonic could be found.
     */
    public static int getMnemonicKeyCode(String text) {
        for (int i = 0; i < text.length(); i++) {
            char c = text.charAt(i);
            if (c == '&') {
                try {
                    return (int) text.charAt(i + 1);
                } catch (IndexOutOfBoundsException e) {
                    return -1;
                }
            }
        }
        return -1;
    }
}