Dúvidas ao chamar uma classe e metodo

1 resposta
rtva

Ola, estou iniciaindo no mundo Java e tenho minha primeira dúvida.

tenho o Util,java, dentro dele tenho o método lpad

//-------

public static String lpad(String str, String chr, int size) {
if(str == null) str = "";
if(chr == null || "".equals(chr) || str.length() == size) return str;
if(str.length() > size) return str.substring(0, size);
String novo = "";
for(int i=0; i<(((size-str.length())/chr.length())+1); i++) {
    novo += chr;
}
novo = novo.substring(0,size-str.length()) + str;
//System.out.println("LPad: " + novo.length() + "  Req" + size);
return novo;
}

//--------

Quero chamado esse metodo dentro de DerbyScriptRunner.java

//-----------------

if (rs != null){

while(rs.next())

{

int vers = rs.getInt(version);

int ditr = rs.getInt(distrib);

int comp = rs.getInt(comp);

int rele = rs.getInt(release);

lpad lp = new lpad();

lp.str = vers;

lp.chr = 0;

lp.size = 2;

vers = lp.novo();

dbversion = (UPD-+vers+"."+ditr+"."+comp+"."+rele+".SQL");

System.out.println("Versão atual do banco " +dbversion);

log.log("Versão atual do banco " +dbversion);

}

}

//----------------------------

mas o lpad no eclipse mostra sublinhado em vermelho dizendo que tenho que criar a class lpad.

O que estou fazendo de errado???

Grato
Rtva

1 Resposta

B

Sendo um método estático, para chamá-lo basta fazer Util.lpad(str, chr, size)

Criado 30 de julho de 2009
Ultima resposta 30 de jul. de 2009
Respostas 1
Participantes 2