| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 419 人关注过本帖
标题:求助
只看楼主 加入收藏
s_k_y
Rank: 1
等 级:新手上路
帖 子:113
专家分:0
注 册:2008-2-2
结帖率:44.44%
收藏
 问题点数:0 回复次数:3 
求助
文本文件中有几个数字,对他进行排序再重新输入到文本中 但是有问题

                      Integer.parseInt(a1[j])=Integer.parseInt(a1[i]);
                  Integer.parseInt(a1[i])=temp;
        这两行编译器说意外的类型 文本里是数字这没问题。请大家帮看看

import *;

public class Test1{

 public static void main(String args[]){
     int temp=0;
     try{
     
          FileReader rf=new FileReader("b.txt");
          BufferedReader ax=new BufferedReader(rf);
     
          String a=ax.readLine();
          String a1[]=a.split(" ");
     
     
           int j;
           int i;
            for(i=0;i<a1.length;i++)
          for(j=i;j<a1.length;j++)
                 if(Integer.parseInt(a1[i])<Integer.parseInt(a1[j]))
                {
                  temp=Integer.parseInt(a1[j]);
                  Integer.parseInt(a1[j])=Integer.parseInt(a1[i]);
                  Integer.parseInt(a1[i])=temp;                   
                }
          i=0;
          String c="";
          while(i<a1.length)
              {   c=c+a1[i]+" ";
              i++;
          }
        
          FileWriter r=new FileWriter("b.txt");
          r.write(c);
     
          ax.close();
          r.close();
     
           }catch(IOException e){
           System.out.println(e);}
            catch(Exception e){
            System.out.println(e);
        }

    
    
    }    
    
    
    
  }
搜索更多相关主题的帖子: 文本文件 public import 编译器 
2008-08-26 20:24
dcuzhang
Rank: 1
等 级:新手上路
帖 子:20
专家分:0
注 册:2008-3-13
收藏
得分:0 
给你改了,
1。 temp 换成 String
2.  你有问题的两句。  

但你的程序可以更好的设计一下。



import *;

public class Test1{

public static void main(String args[]){
    String temp;
    try{
   
         FileReader rf=new FileReader("b.txt");
         BufferedReader ax=new BufferedReader(rf);
   
         String a=ax.readLine();
         String a1[]=a.split(" ");
   
   
         int j;
         int i;
         for(i=0;i<a1.length;i++)
         for(j=i;j<a1.length;j++)
                if(Integer.parseInt(a1[i])<Integer.parseInt(a1[j]))
               {
                 temp=a1[j];
                 a1[j]=a1[i];
                 a1[i]=temp;                  
               }
         i=0;
         String c="";
         while(i<a1.length)
              {   c=c+a1[i]+" ";
             i++;
         }
        
         FileWriter r=new FileWriter("b.txt");
         r.write(c);
   
         ax.close();
         r.close();
   
           }catch(IOException e){
          System.out.println(e);}
            catch(Exception e){
            System.out.println(e);
        }

   
   
    }   
   
   
   
  }
2008-08-26 22:26
meteor57
Rank: 1
来 自:银河系
等 级:新手上路
帖 子:267
专家分:0
注 册:2007-9-29
收藏
得分:0 
Integer.parseInt(a1[j])=Integer.parseInt(a1[i]);
Integer.parseInt(a1[i])=temp;
这两个赋值表达式左边要是变量,而不是表达式.
比如:Integer.parseInt(a1[j]) == 3; Integer.parseInt(a1[i]) == 4
Integer.parseInt(a1[j])=Integer.parseInt(a1[i]);就变成 3 = 4;
当然有问题了.
2008-08-26 22:41
s_k_y
Rank: 1
等 级:新手上路
帖 子:113
专家分:0
注 册:2008-2-2
收藏
得分:0 
谢谢
谢谢楼上的两位朋友
2008-08-27 13:54
快速回复:求助
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015325 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved