Skip to content

Instantly share code, notes, and snippets.

@cypres
Forked from brunsgaard/gist:1395842
Created November 26, 2011 15:46
Show Gist options
  • Save cypres/1395886 to your computer and use it in GitHub Desktop.
Save cypres/1395886 to your computer and use it in GitHub Desktop.
Less than 80 chars
___________
< text here >
-----------
two lines
________________________________
/ text goes here text goes here \
\ text goes here text goes here /
--------------------------------
More than two lines
________________________________
/ text goes here text goes here \
| |
\ text goes here text goes here /
--------------------------------
// compile with: javac t.java
// run with: java CowSay hello world
class CowSay
{
final static int WRAP = 80;
public static String getLine(char c, int l)
{
String line = " ";
for (int i=0; i<l+2; i++) {
line += c;
}
return line;
}
public static void main(String [ ] args)
{
String msg = "";
for (int i=0; i<args.length; i++) {
msg += args[i] + " ";
}
msg = msg.trim();
int len = msg.length();
if (len < WRAP) {
System.out.println(CowSay.getLine('_',len));
String out = "< "+msg+" >";
System.out.println(out);
System.out.println(CowSay.getLine('-',len));
} else {
System.out.println(CowSay.getLine('_',WRAP));
for(int pos=0; pos<len; pos += WRAP) {
String line = "";
int next = (pos+WRAP);
if (next > len) next = len;
if (pos==0) {
line = "/ "+msg.substring(pos,next)+" \\";
} else if (len-pos<WRAP) {
line = "\\ "+msg.substring(pos,next);
for (int i=WRAP-(len-pos);i>0;i--) {
line += " ";
}
line += " /";
} else {
line = "| "+msg.substring(pos,next)+" |";
}
System.out.println(line);
}
System.out.println(CowSay.getLine('-',WRAP));
}
System.out.println(" \\ ^__^");
System.out.println(" \\ (oo)\\_______");
System.out.println(" (__)\\ )\\/\\");
System.out.println(" ||----w |");
System.out.println(" || ||");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment