import java.io.*;
public class UpperCase
{
/**
* Method main
*
*
* @param args
*
*/
public void toUpperCase(StringReader sr,StringWriter sw)
{
char [] buf = new char[1024];
char [] bufw = new char[1024];
int len = 0;
int j = 0;
len = sr.read(buf);
Character [] newbuf = null;
for(int i = 0;i < len;i++)
{
Character newbuf[i] = new Character(buf[i]);
if(newbuf[i].isLetter() && newbuf[i].isLowerCase())
{
bufw[j] = newbuf[i].toUpperCase(newbuf[i].charValue());
j++;
}
}
sw.write(bufw);
}
public static void main(String[] args)
{
// TODO: Add your code here
StringReader sr = new StringReader( "abcdef111111ghijklmnopqrstuvwxyz ");
StringWriter sw = new StringWriter();
UpperCase uc = new UpperCase();
uc.toUpperCase(sr,sw);
System.out.println(sw.toString());
}
}
老是提示缺少一个“[”,但是怎么看看不出来毛病,大虾帮忙!~
D:\JavaWork\UpperCase\UpperCase.java:22: '] ' expected
Character newbuf[i] = new Character(buf[i]);
------解决方案--------------------
很多错误,类型,方法都不对。
改成下面,
public void toUpperCase(StringReader sr,StringWriter sw)
{
char [] buf = new char[1024];
char [] bufw = new char[1024];
int len = 0;
int j = 0;
try
{
len = sr.read(buf);
Character newbuf ;
for(int i = 0;i < len;i++)
{
newbuf = buf[i];
if(Character.isLetter(newbuf) && Character.isLowerCase(newbuf))
{
bufw[j] = newbuf.toUpperCase(newbuf.charValue());
j++;
}
}
sw.write(bufw);
}
catch (Exception e)
{
}
}
------解决方案--------------------
我试了就是好着呢啊,我用的eclipse3.2.2
------解决方案--------------------
都搞好咯..我来接分吧