Topic: 报错,不知道原因 ?

  Print this page

1.报错,不知道原因 ? Copy to clipboard
Posted by: heartache
Posted on: 2006-03-23 13:30


import java.util.Arrays;

public class TestSort{
public static void main(String[] args)
{
int[]a={45,10,89,71,90,45,98};
int[]b={};

for(int i=0;i<a.length;i++)
{
System.out.println(a[i]);
}
String[] c={"adcaaasxaaf"}; //这个有错误 ?
for(int i=0;i<12;i++) //想替换C中所有的字母a,用b代替
{
char ch=charAt(c[i]); //这个有错误
if (ch.equals(c)) //这个有错误
c[i]='b'; //这个有错误
System.out.println(c[i]);
}

}
}


{ use [code ], use "Disable Smileys", use GIF and don't use BMP --why }

2.Re:报错,不知道原因 ? [Re: heartache] Copy to clipboard
Posted by: Jcat
Posted on: 2006-03-23 16:54

请先分清楚以下三个东西:

String[]

String

char[]

3.Re:报错,不知道原因 ? [Re: heartache] Copy to clipboard
Posted by: arroyo
Posted on: 2006-04-05 11:24

基本概念都没弄清楚,多看看书吧

4.Re:报错,不知道原因 ? [Re: heartache] Copy to clipboard
Posted by: why
Posted on: 2006-04-05 18:15

怎麼把這個翻出來Embaressed


String c = "adcaaasxaaf1"; // 这个有错误 ?
for (int i = 0; i < 12; i++) // 想替换C中所有的字母a,用b代替
{
char ch = c.charAt( i ); // 这个有错误
if (ch == 'c') {// 这个有错误
// c[i]='b'; //这个有错误 -- Java's String is immutable, consider StringBuffer
System.out.println(ch);
}
}


i.e. something like

StringBuffer sb = new StringBuffer("adcaaasxaaf1");
for (int i = 0; i < sb.length(); i++)
{
char ch = sb.charAt( i );
if (ch == 'c') {
sb.setCharAt(i, 'b');
System.out.println(ch);
}
}


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923