1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
|
import java.util.Scanner;
import java.util.regex.Pattern;
/**
* Helper to program prototype Pep/8 program in Java.
*
* @author Jean Privat
* @version 2013-01-08
*
* This class provides some static method to mimic some instructions of the
* Pep/8 system.
*
*/
public class Snake {
private static Scanner sc = new Scanner(System.in);
/**
* DECI: Read the next integer from the input.
*/
public static int deci() {
if (!sc.hasNextInt()) {
System.out.println("Not a valid DECI input");
System.exit(0);
}
int res = sc.nextInt();
return res;
}
/**
* DECO: Write an integer on the output.
*/
public static void deco(int val) {
System.out.print(val);
}
/**
* CHARI: Read the next character on the input.
*/
public static char chari() {
Pattern olddel = sc.delimiter();
sc.useDelimiter("");
if (!sc.hasNext()) {
sc.useDelimiter(olddel);
return 0;
}
String res = sc.next();
sc.useDelimiter(olddel);
return res.charAt(0);
}
/**
* CHARO: Write a character on the output.
*/
public static void charo(char val) {
System.out.print(val);
}
/**
* STRO: Write a string on the output.
*/
public static void stro(String val) {
System.out.print(val);
}
/**
* STRO: Write a string on the output. version with a array of char.
*/
public static void stro(char[] val) {
int len = 0;
while (len < val.length && val[len] != '\0') {
len++;
}
char[] out = new char[len];
for (int i = 0; i < len; i++) {
out[i] = val[i];
}
System.out.print(new String(out));
}
/**
* STOP: Terminate the program.
*/
public static void stop() {
System.exit(0);
}
} |
Partager