帮忙改一下java程序中的错误,在线等。。。。。谢谢

importjava.util.Scanner;publicclassEx3_1{publicstaticvoidmain(Strings[]args){Stringse... import java.util.Scanner;
public class Ex3_1{
public static void main(Strings[] args){
String sentence = new String("The past is gone and static. Nothing we can do will change it.Thefuture is before us and dynamic. Everything we do will affect it.");
int a=sentence.length();
Scanner sc = new Scanner(System.in);
b = sc.next();
int c=0;
for(int i=0;i<=a;i++)
{char ch1=sentence.charAt(i);
char ch2=b;
if(ch1=ch2)
{c=c++;}
}
System.out.println("+b+出现的频率是"+c);
}
}
展开
 我来答
武汉小朱
2014-04-14 · TA获得超过2762个赞
知道小有建树答主
回答量:1212
采纳率:50%
帮助的人:889万
展开全部
很明显的错误
main(Strings[] args){

改成
main(String[] args){

b = sc.next();

b这个变量没有类型。
追问
一定要写在他后面吗,我在后面写的,改了还是不行啊
追答
public static void main(String[] args){
 String sentence = new String("The past is gone and static. Nothing we can do will change it.Thefuture is before us and dynamic. Everything we do will affect it.");
 int a=sentence.length();
 Scanner sc = new Scanner(System.in);
 System.out.println("请输入要查询的字符:");
 String b = sc.next();
 int c=0;
 for(int i=0;i<a;i++){
 char ch1=sentence.charAt(i);
//  System.out.println(b+":"+String.valueOf(ch1)+":"+b.equals(String.valueOf(ch1)));
 if(b.equals(String.valueOf(ch1))){
 c++;
 }
 }
  System.out.println(b+"出现的频率是"+c);
}


我给你改了一下。。

chengbin775
2014-04-14 · TA获得超过104个赞
知道答主
回答量:61
采纳率:0%
帮助的人:53.6万
展开全部
public static void main(String[] args) {
String sentence = new String(
"The past is gone and static. Nothing we can do will change it.Thefuture is before us and dynamic. Everything we do will affect it.");
int a = sentence.length();
Scanner sc = new Scanner(System.in);
String b = sc.next();
int c = 0;
for (int i = 0; i < a; i++) {
String ch1 = sentence.substring(i, i+1);
// 搜索

if (ch1.equals(b)) {
c +=1;
}
}
System.out.println("+b+出现的频率是" + c);
}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
wadeMhglv
2014-04-14 · TA获得超过1255个赞
知道小有建树答主
回答量:1478
采纳率:60%
帮助的人:684万
展开全部
import java.util.Scanner;

public class Ex3_1
{
    public static void main(String[] args)
    {
        String sentence = new String("The past is gone and static. Nothing we can do will change it.Thefuture is before us and dynamic. Everything we do will affect it.");
        int a = sentence.length();
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入一个字母:");
        String b = sc.next();
        int c = 0;
        for (int i = 0; i < a; i++)
        {
            String str1=String.valueOf(sentence.charAt(i));
           
            if (str1.equals(b))
            {
                c++;
            }
        }
        System.out.println(b+"出现的频率是:" + c);
    }
}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
百度网友508fe89
2014-04-14 · 超过12用户采纳过TA的回答
知道答主
回答量:25
采纳率:100%
帮助的人:21万
展开全部
这个是要实现查找出现次数吗?
追问
是的
追答
这段程序错误不少,比如b = sc.next();的b应该是String(next()的返回值),但是 char ch2=b赋值是类型不对; if(ch1=ch2)中应该是==;for(int i=0;i<=a;i++)中i=a,也就是String长度时,必然会抛出越界。好像c=c++也不太对,你可以试一下,可能c的值不变,这个和自增运算的优先度有关,一般不这么写。
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 1条折叠回答
收起 更多回答(2)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式