Skip to content

Instantly share code, notes, and snippets.

@FerPerales
Created September 24, 2012 18:26
Show Gist options
  • Save FerPerales/3777473 to your computer and use it in GitHub Desktop.
Save FerPerales/3777473 to your computer and use it in GitHub Desktop.
Software Gurú
public class Operaciones {
/**
* @param args
*/
public static void main(String[] args) {
char operacion = args[0].charAt(0);
int valor = Integer.parseInt(args[1]);
suma(valor, operacion);
}
private static void suma(int valor, char operacion) {
StringBuffer buffer = new StringBuffer();
buffer.append(operacion + " |");
for (int i = 0;i <= valor; i++){
buffer.append(" " + i);
}
int resultado;
buffer.append("\n---------------------------------\n");
for (int i = 0;i <= valor; i++){
buffer.append(i + " |");
for (int j = 0;j <= valor; j++){
switch (operacion){
case '+': resultado = i + j;
buffer.append(" " + resultado);
break;
case '-': resultado = i - j;
buffer.append(" " + resultado);
break;
case '*': resultado = i * j;
buffer.append(" " + resultado);
break;
case '/': if(j == 0){
buffer.append(" -");
}else{
resultado =i / j;
buffer.append(" " + resultado);
}
break;
}
}
buffer.append("\n");
}
System.out.println(buffer);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment