Ejemplo n.º 1
0
  // Sucecion de Fibonacci
  static void suce() {
    int numero, a = 1, b = 0, c;
    StringBuffer sb = new StringBuffer();
    String s1 =
        JOptionPane.showInputDialog("Ingrese el numero hasta el que desea ver la sucesion : ");
    numero = Integer.parseInt(s1);
    while (a < numero) {
      a += b;
      sb.append(a + " , ");
      b += a;
      sb.append(b + " , ");
    }

    JOptionPane.showMessageDialog(null, "Fibonacci = " + sb);

    int numero2 =
        JOptionPane.showOptionDialog(
            null,
            "Seleccione",
            "Escoja",
            JOptionPane.YES_NO_CANCEL_OPTION,
            JOptionPane.QUESTION_MESSAGE,
            null,
            new Object[] {"Opcion 1", "Opcion 2", "Opcion 3"},
            "Opcion 3");
  }
Ejemplo n.º 2
0
 String concate(String[] strings) {
   StringBuffer buffer = new StringBuffer("");
   for (String string : strings) {
     buffer.append(string);
   }
   return buffer.toString();
 }
Ejemplo n.º 3
0
  /**
   * @param section
   * @param index
   * @return
   * @throws IOException
   */
  final String getStringFromSection(final Section section, final int index) throws IOException {
    if (index > section.getSize()) {
      return "";
    }

    final StringBuffer str = new StringBuffer();
    // Most string symbols will be less than 50 bytes in size
    final byte[] tmp = new byte[50];

    this.efile.seek(section.getFileOffset() + index);
    while (true) {
      int len = this.efile.read(tmp);
      for (int i = 0; i < len; i++) {
        if (tmp[i] == 0) {
          len = 0;
          break;
        }
        str.append((char) tmp[i]);
      }
      if (len <= 0) {
        break;
      }
    }

    return str.toString();
  }
Ejemplo n.º 4
0
 /**
  * ** A String reperesentation of this URI (with arguments) ** @return A String representation of
  * this URI
  */
 public String toString() {
   StringBuffer sb = new StringBuffer(this.getURI());
   if (!ListTools.isEmpty(this.getKeyValList())) {
     sb.append("?");
     this.getArgString(sb);
   }
   return sb.toString();
 }
Ejemplo n.º 5
0
 /**
  * ** A String reperesentation of this URI (with arguments) ** @param includeBlankValues True to
  * include keys for blank values. ** @return A String representation of this URI
  */
 public String toString(boolean includeBlankValues) {
   StringBuffer sb = new StringBuffer(this.getURI());
   if (!ListTools.isEmpty(this.getKeyValList())) {
     sb.append("?");
     this.getArgString(sb, includeBlankValues);
   }
   return sb.toString();
 }
Ejemplo n.º 6
0
 public String toString() {
   StringBuffer sb = new StringBuffer();
   sb.append(this.key);
   if (this.hasValue()) {
     sb.append("=").append(this.val);
   }
   return sb.toString();
 }
Ejemplo n.º 7
0
 /**
  * @param s
  * @return
  */
 public static String mask(final String s) {
   final StringBuffer buffer = new StringBuffer(25);
   final int count = (s != null ? s.length() : 0);
   for (int n = 0; n < count; n++) {
     buffer.append('*');
   }
   return buffer.toString();
 }
Ejemplo n.º 8
0
  public static void main(String[] args) throws IOException {
    Scanner scanner = new Scanner(new BufferedInputStream(System.in));

    int num[][] = {
      {0, 2, 3, 5, 6, 7, 8, 9},
      {2, 3, 4, 5, 6, 8, 9},
      {0, 2, 3, 5, 6, 8, 9},
      {0, 4, 5, 6, 8, 9},
      {0, 1, 2, 3, 4, 7, 8, 9},
      {0, 2, 6, 8},
      {0, 1, 3, 4, 5, 6, 7, 8, 9}
    };

    while (scanner.hasNextInt()) {
      int a = scanner.nextInt();
      String b = scanner.next();
      if (a == 0) break;
      String data[][] = new String[5 + (a - 1) * 2][(3 + (a - 1)) * b.length()];

      for (int i = 0; i < 5 + (a - 1) * 2; i++)
        for (int j = 0; j < (3 + (a - 1)) * b.length(); j++) data[i][j] = " ";

      for (int i = 0; i < b.length(); i++) {
        for (int j = 0; j < 3; j++) {
          for (int k = 0; k < num[j].length; k++) {
            if ((int) b.charAt(i) - 48 == num[j][k]) {
              for (int h = 0; h < a; h++) data[(a + 1) * j][1 + i * (a + 2) + h] = "-";
            }
          }
        }
        for (int j = 3; j < 5; j++) {
          for (int k = 0; k < num[j].length; k++) {
            if ((int) b.charAt(i) - 48 == num[j][k]) {
              for (int h = 0; h < a; h++) data[1 + h][(j - 3) * (a + 1) + (i * (a + 2))] = "|";
            }
          }
        }
        for (int j = 5; j < 7; j++) {
          for (int k = 0; k < num[j].length; k++) {
            if ((int) b.charAt(i) - 48 == num[j][k]) {
              for (int h = 0; h < a; h++) data[a + 2 + h][(j - 5) * (a + 1) + (i * (a + 2))] = "|";
            }
          }
        }
      }
      StringBuffer sb = new StringBuffer("");
      for (int i = 0; i < 5 + (a - 1) * 2; i++) {
        for (int j = 0; j < (3 + (a - 1)) * b.length(); j++) {
          if ((j - (a + 1)) % (a + 2) == 0 && (j + 1) != (3 + (a - 1)) * b.length())
            sb.append(data[i][j] + " ");
          else sb.append(data[i][j]);
        }
        sb.append("\n");
      }
      System.out.println(sb);
    }
  }
Ejemplo n.º 9
0
 public String toString() {
   StringBuffer sb = new StringBuffer();
   sb.append(this.key);
   String v = this.val;
   if ((v != null) && !v.equals("")) {
     sb.append("=").append(v);
   }
   return sb.toString();
 }
Ejemplo n.º 10
0
 public String nextString() throws Exception {
   StringBuffer sb = new StringBuffer("");
   byte c = read();
   while (c <= ' ') c = read();
   do {
     sb.append((char) c);
     c = read();
   } while (c > ' ');
   return sb.toString();
 }
Ejemplo n.º 11
0
 public static String PrintList(ArrayList l) {
   StringBuffer sb = new StringBuffer("[ ");
   Iterator i = l.iterator();
   while (i.hasNext()) {
     Double d = (Double) i.next();
     sb.append(MDP._df.format(d.doubleValue()) + " ");
   }
   sb.append("]");
   return sb.toString();
 }
Ejemplo n.º 12
0
 private String bigIntToHexString(BigInteger bi) {
   StringBuffer buf = new StringBuffer();
   buf.append("0x");
   String val = bi.toString(16);
   for (int i = 0; i < ((2 * addressSize) - val.length()); i++) {
     buf.append('0');
   }
   buf.append(val);
   return buf.toString();
 }
Ejemplo n.º 13
0
 /**
  * String Representation
  *
  * @return info
  */
 @Override
 public String toString() {
   StringBuffer sb = new StringBuffer("MGoal[");
   sb.append(get_ID())
       .append("-")
       .append(getName())
       .append(",")
       .append(getGoalPerformance())
       .append("]");
   return sb.toString();
 } //	toString
Ejemplo n.º 14
0
 /**
  * ** Returns a String representation of all key/values ** @param sbuff The StringBuffer to write
  * the key/values to, or null ** for a new one ** @return A String representation of all
  * key/values
  */
 public StringBuffer getArgString(StringBuffer sbuff) {
   StringBuffer sb = (sbuff != null) ? sbuff : new StringBuffer();
   for (Iterator i = this.getKeyValList().iterator(); i.hasNext(); ) {
     KeyVal kv = (KeyVal) i.next();
     sb.append(kv.toString());
     if (i.hasNext()) {
       sb.append("&");
     }
   }
   return sb;
 }
Ejemplo n.º 15
0
 public static String PrintState(ArrayList state) {
   StringBuffer sb = new StringBuffer();
   Iterator i = state.iterator();
   while (i.hasNext()) {
     Object o = i.next();
     if (o instanceof Boolean) {
       Boolean val = (Boolean) o;
       sb.append((val.booleanValue() ? "." : "X"));
     }
   }
   return sb.toString();
 }
Ejemplo n.º 16
0
 public String toString() {
   StringBuffer sb = new StringBuffer();
   sb.append(this.getAccountID());
   sb.append("/");
   sb.append(this.getDeviceID());
   sb.append(" ");
   sb.append(this.getStatusCode());
   sb.append("[");
   sb.append(this.getDescription());
   sb.append("]");
   return sb.toString();
 }
Ejemplo n.º 17
0
 public String toString() {
   StringBuffer sb = new StringBuffer();
   sb.append(this.isHiRes() ? "H" : "L");
   sb.append(FIELD_VALUE_SEPARATOR);
   sb.append(this.getType());
   sb.append(FIELD_VALUE_SEPARATOR);
   sb.append(this.getIndex());
   sb.append(FIELD_VALUE_SEPARATOR);
   sb.append(this.getLength());
   return sb.toString();
 }
Ejemplo n.º 18
0
 /**
  * ** Returns a String representation of all key/values ** @param sbuff The StringBuffer to write
  * the key/values to, or null for a new one ** @param includeBlankValues True to include keys for
  * blank values. ** @return A String representation of all key/values
  */
 public StringBuffer getArgString(StringBuffer sbuff, boolean includeBlankValues) {
   StringBuffer sb = (sbuff != null) ? sbuff : new StringBuffer();
   int argCnt = 0;
   for (Iterator i = this.getKeyValList().iterator(); i.hasNext(); ) {
     KeyVal kv = (KeyVal) i.next();
     if (includeBlankValues || kv.hasValue()) {
       if (argCnt > 0) {
         sb.append("&");
       }
       sb.append(kv.toString());
       argCnt++;
     }
   }
   return sb;
 }
Ejemplo n.º 19
0
 public static void abcd(String str) {
   BigInteger sum = BigInteger.ZERO;
   StringBuffer n = new StringBuffer("");
   for (int i = 0; i < str.length(); i++) {
     BigInteger ab = BigInteger.valueOf(((int) str.charAt(i)) - 96);
     sum = sum.add(div.pow(str.length() - i - 1).multiply(ab));
   }
   String s = sum.toString();
   for (int i = 0; i < s.length(); i++) {
     if (i % 3 == 0 && i != 0) n.insert(0, ",");
     n.insert(0, s.charAt(s.length() - i - 1));
   }
   while (str.length() < 22) str = str + " ";
   System.out.println(str + "" + n);
 }
Ejemplo n.º 20
0
 /** @param args the command line arguments */
 public static void main(String[] args) {
   // TODO code application logic here
   try {
     Parserdoubt p = new Parserdoubt(System.in);
     int t = p.nextInt();
     StringBuffer sb = new StringBuffer();
     while (t-- > 0) {
       int a = p.nextInt();
       int b = p.nextInt();
       int c = p.nextInt();
       sb.append(find(a, b, c) + "\n");
     }
     System.out.print(sb.toString());
   } catch (Exception e) {
   }
 }
Ejemplo n.º 21
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 !");
    }
  }
Ejemplo n.º 22
0
 public static String GetPropertyString_OBDII(String dtcStr) {
   StringBuffer sb = new StringBuffer();
   sb.append(PROP_TYPE[0]).append("=").append(NAME_OBDII);
   sb.append(" ");
   if (!StringTools.isBlank(dtcStr)) {
     sb.append(PROP_MIL[0]).append("=").append("1");
     sb.append(" ");
     sb.append(PROP_DTC[0]).append("=").append(dtcStr);
   } else {
     sb.append(PROP_MIL[0]).append("=").append("0");
   }
   return sb.toString();
 }
Ejemplo n.º 23
0
 /**
  * ** Hex-encodes a URL argument ** @param sb The StringBuffer where the hex encoded String
  * argument will be placed ** @param s The URL argument to encode ** @param obfuscateAll True to
  * force hex-encoding on all argument characters ** @return The StringBuffer where the hex-encoded
  * String will be placed
  */
 public static StringBuffer encodeArg(StringBuffer sb, String s, boolean obfuscateAll) {
   if (sb == null) {
     sb = new StringBuffer();
   }
   if (s != null) {
     char ch[] = new char[s.length()];
     s.getChars(0, s.length(), ch, 0);
     for (int i = 0; i < ch.length; i++) {
       if (obfuscateAll || URIArg.shouldEncodeArgChar(ch[i])) {
         // escape non-alphanumeric characters
         sb.append("%");
         sb.append(Integer.toHexString(0x100 + (ch[i] & 0xFF)).substring(1));
       } else {
         // letters and digits are ok as-is
         sb.append(ch[i]);
       }
     }
   }
   return sb;
 }
Ejemplo n.º 24
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);
 }
 private InputStream getReport(
     HttpServletRequest request,
     HttpServletResponse response,
     Tab tab,
     TableModel tableModel,
     Integer columnCountLimit)
     throws ServletException, IOException {
   StringBuffer suri = new StringBuffer();
   suri.append("/xava/jasperReport");
   suri.append("?language=");
   suri.append(Locales.getCurrent().getLanguage());
   suri.append("&widths=");
   suri.append(Arrays.toString(getWidths(tableModel)));
   if (columnCountLimit != null) {
     suri.append("&columnCountLimit=");
     suri.append(columnCountLimit);
   }
   response.setCharacterEncoding(XSystem.getEncoding());
   return Servlets.getURIAsStream(request, response, suri.toString());
 }
Ejemplo n.º 26
0
 /**
  * Gets the instances of <CODE>Template</CODE> that have an ID that is already in the database.
  *
  * @return An <CODE>ArrayList</CODE> containing the instances of <CODE>Template</CODE> already in
  *     the database.
  * @throws java.sql.SQLException Thrown on sql exception.
  */
 public ArrayList findTemplatesInDatabase() throws java.sql.SQLException {
   ArrayList templatesInDatabase = new ArrayList();
   Connection oracleConnection = getDataSource().getConnection();
   try {
     Statement query = oracleConnection.createStatement();
     try {
       StringBuffer sql = new StringBuffer("SELECT TMPL_ID FROM ");
       sql.append(MPSBrowserView.SCHEMA);
       sql.append(".TEMPLATE WHERE TMPL_ID IN (");
       ArrayList templates = getTemplates();
       int templateCount = templates.size();
       for (int i = 0; i < templateCount; i++) {
         if (i > 0) sql.append(", ");
         sql.append("'");
         sql.append(((Template) templates.get(i)).getID());
         sql.append("'");
       }
       sql.append(")");
       ResultSet result = query.executeQuery(sql.toString());
       try {
         while (result.next()) {
           String templateID = result.getString("TMPL_ID");
           for (int i = 0; i < templateCount; i++) {
             Template currentTemplate = (Template) templates.get(i);
             if (templateID.equals(currentTemplate.getID())) {
               templatesInDatabase.add(currentTemplate);
               currentTemplate.setInDatabase(true);
             }
           }
         }
       } finally {
         result.close();
       }
     } finally {
       query.close();
     }
   } finally {
     oracleConnection.close();
   }
   return templatesInDatabase;
 }
Ejemplo n.º 27
0
 /**
  * ** Decodes the specified hex-encoded argument (not yet fully tested) ** @param sb The
  * StringBuffer where the decoded String argument will be placed ** @param s The String to decode
  * ** @return The StringBuffer where the decoded String will be placed
  */
 public static StringBuffer decodeArg(StringBuffer sb, String s) {
   if (sb == null) {
     sb = new StringBuffer();
   }
   if (s != null) {
     char ch[] = new char[s.length()];
     s.getChars(0, s.length(), ch, 0);
     for (int i = 0; i < ch.length; i++) {
       if (ch[i] == '%') {
         if ((i + 2) < ch.length) {
           int ch1 = StringTools.hexIndex(ch[i + 1]);
           int ch2 = StringTools.hexIndex(ch[i + 2]);
           sb.append((char) (((ch1 << 4) | ch2) & 0xFF));
           i += 2;
         } else {
           i = ch.length - 1;
         }
       } else {
         sb.append(ch[i]);
       }
     }
   }
   return sb;
 }
Ejemplo n.º 28
0
 /**
  * ** Decodes the specified hex-encoded argument (not yet fully tested) ** @param s The String to
  * decode ** @return The decoded String
  */
 private String decodeArg(String s) {
   StringBuffer sb = URIArg.decodeArg(null, s);
   return sb.toString();
 }
Ejemplo n.º 29
0
 /**
  * ** Hex-encodes a URL argument ** @param s The URL argument to encode ** @param obfuscateAll
  * True to force hex-encoding on all argument characters ** @return The hex-encoded String
  */
 private String encodeArg(String s, boolean obfuscateAll) {
   StringBuffer sb = URIArg.encodeArg(null, s, obfuscateAll);
   return sb.toString();
 }
Ejemplo n.º 30
0
 public String toString() {
   StringBuffer sb = new StringBuffer("X_AD_ComponentVersion[").append(getID()).append("]");
   return sb.toString();
 }