Efficient use of regular expression and string manipulation
When using the re module, make sure to use strings marked with a leading 'r' as I do in the code below. This tells the interpreter to not try and interpolate any escaped strings.

By using findall to test for matches too we end up with more succinct code that still does exactly what we want in a clear fashion.

By putting the logic in a function you get the ability to write unit tests or do something other than print the result.

Using an exception for the failure cases makes the code clear and is more Pythonic in style.

Here is how I would have coded it.

import re
import sys

cpp = re.compile(r"(_[a-z]*)")
java= re.compile(r"([A-Z]+[a-z]*)")

class InvalidStyle(Exception):
    pass


def style_transform(input):
    if input[0].isupper():
        raise InvalidStyle(input)

    m = cpp.findall(input)
    if m:
        # import pdb; pdb.set_trace()
        if any(re.match(r"^[A-Z_]$", w) for w in m):
            raise InvalidStyle(input)

        pos = input.find(m[0])

        return input[:pos] + "".join(w.capitalize() for w in m)

    m = java.findall(input)
    if m:
        # import pdb; pdb.set_trace()
        pos = input.find(m[0])
        words = [input[:pos]] + [w.lower() for w in m]
        return "_".join(words)

    if input.lower() == input:
        return input
    else:
        raise InvalidStyle(input)


if __name__ == "__main__":
    if len(sys.argv) == 2:  # allows for debugging via pdb
        fp = open(sys.argv[1])
    else:
        fp = sys.stdin

    for line in fp.readlines():
        line = line.strip()
        if not line:
            continue

        try:
            print style_transform(line)
        except InvalidStyle as e:
            # print e, uncomment to see errors
            print "Error!"