Exemple #1
0
 public static void num(String str) {
   BigInteger a = new BigInteger(str);
   StringBuffer sb = new StringBuffer("");
   StringBuffer n = new StringBuffer("");
   while (!(a.divide(div).equals(zero))) {
     sb.insert(0, (char) (a.mod(div).intValue() + 96));
     a = a.divide(div);
   }
   sb.insert(0, (char) (a.intValue() + 96));
   for (int i = 0; i < str.length(); i++) {
     if (i % 3 == 0 && i != 0) n.insert(0, ",");
     n.insert(0, str.charAt(str.length() - i - 1));
   }
   while (sb.length() < 22) sb.append(" ");
   System.out.println(sb + "" + n);
 }
Exemple #2
0
  // crear una sucesion de cuadrados
  static void cuadrado() {
    // 1, 4, 9, 16, 25, 36, 49, 64, 81,
    try {
      String s1 =
          JOptionPane.showInputDialog(
              "Ingrese un numero hasta la que desea ver la sucesion de cuadrados :");
      int limite = Integer.parseInt(s1);
      StringBuffer sb = new StringBuffer();
      for (int numero = 1, sqrt = 1; numero < limite; sqrt = ++numero * numero) {
        sb.append(sqrt + " , ");
      }

      int largo = sb.length();
      JOptionPane.showMessageDialog(null, "Sucesion sqrt = " + sb.delete(largo - 2, largo));
    } catch (NumberFormatException e) {
      JOptionPane.showMessageDialog(null, "No ha ingresado un numero !");
    }
  }