Skip to content

Instantly share code, notes, and snippets.

@dideler
Created February 17, 2013 01:22
Show Gist options
  • Save dideler/4969581 to your computer and use it in GitHub Desktop.
Save dideler/4969581 to your computer and use it in GitHub Desktop.
Flip Text - flips a line of text so that it appears to be upside-down and mirrored
/**
* Copyright 2009 Dennis Ideler
*
* $ javac flipText.java
* $ java flipText
* hello world, i'm dennis
* sıuuǝp ɯ,ı 'p1ɹoʍ o11ǝɥ
*/
import java.io.*;
public class flipText
{
flipText()
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String text = "";
try { text = br.readLine(); }
catch(Exception e) { e.printStackTrace(); }
String result = flipString(text);
System.out.println(result);
}
private String flipString(String text)
{
text = text.toLowerCase();
String result = "";
for (int i = text.length() - 1; i >= 0; --i)
{
// Flip and mirror the text.
result += flipChar(text.charAt(i));
}
return result;
}
private char flipChar(char c)
{
switch (c)
{
case 'a': return '\u0250';
case 'b': return 'q';
case 'c': return '\u0254';
case 'd': return 'p';
case 'e': return '\u01DD';
case 'f': return '\u025F';
case 'g': return 'b';
case 'h': return '\u0265';
case 'i': return '\u0131'; // or \u0323
case 'j': return '\u0638';
case 'k': return '\u029E';
case 'l': return '1';
case 'm': return '\u026F';
case 'n': return 'u';
case 'o': return 'o';
case 'p': return 'd';
case 'q': return 'b';
case 'r': return '\u0279';
case 's': return 's';
case 't': return '\u0287';
case 'u': return 'n';
case 'v': return '\u028C';
case 'w': return '\u028D';
case 'x': return 'x';
case 'y': return '\u028E';
case 'z': return 'z';
case '[': return ']';
case ']': return '[';
case '(': return ')';
case ')': return '(';
case '{': return '}';
case '}': return '{';
case '?': return '\u00BF';
case '\u00BF': return '?';
case '!': return '\u00A1';
case '\'': return ',';
case ',': return '\'';
default: return c;
}
}
public static void main(String[] args) { new flipText(); }
}
@aman1887
Copy link

getting error while comile
flipText.java:7: error: unmappable character for encoding Cp1252

  • s─▒uu╟?p ╔»,─▒ 'p1╔╣o╩? o11╟?╔Ñ
    ^
    flipText.java:7: error: unmappable character for encoding Cp1252
  • s─▒uu╟?p ╔»,─▒ 'p1╔╣o╩? o11╟?╔Ñ
    ^
    flipText.java:7: error: unmappable character for encoding Cp1252
  • s─▒uu╟?p ╔»,─▒ 'p1╔╣o╩? o11╟?╔Ñ
    ^
    3 errors

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment