zoukankan      html  css  js  c++  java
  • 个人作业续

    package 一;
    import java.io.BufferedReader;
    import java.io.BufferedWriter;
    import java.io.File;
    import java.io.FileNotFoundException;
    import java.io.FileReader;
    import java.io.FileWriter;
    import java.io.IOException;
    import java.util.Scanner;
    import java.util.Random;
    public class Maxshuzu 
    {
        public static void main(String args[])
        {
        	Random rd=new Random();
        	
            long Array[][]=new long[1000000][2];
            int count=0,length=0;
            File file = new File("shuzu.txt");
            BufferedWriter writer = null;
    		try {
    			writer = new BufferedWriter(new FileWriter(file));
    		} catch (IOException e1) {
    			// TODO Auto-generated catch block
    			e1.printStackTrace();
    		}
            for(long k=0;k<10000;k++){
            long   l   =   (long)(Math.random()*1000);
            String   s   =   ""+l;
            int   i   =   s.length();
           
    //        for(int   j=0;j <2-i;j++){
    //          s   =   "0"+s;
    //        }
            int z;
            if((z=(int) (Math.random()*100))%2==0) {
            	s="-"+s;
            }
            System.out.println(s);
            try {
    			writer.write(s);
    		} catch (IOException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}
            try {
    			writer.newLine();
    		} catch (IOException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}
            }
            try {
    			writer.flush();
    		} catch (IOException e1) {
    			// TODO Auto-generated catch block
    			e1.printStackTrace();
    		}
            try {
    			writer.close();
    		} catch (IOException e1) {
    			// TODO Auto-generated catch block
    			e1.printStackTrace();
    		}
                  
     
            
            
    			BufferedReader br = null;
    			try {
    				br = new BufferedReader(new FileReader(file));
    			} catch (FileNotFoundException e) {
    				// TODO Auto-generated catch block
    				e.printStackTrace();
    			}	
    				
    				String tmp;
    				try {int i=0;
    					while((tmp = br.readLine()) != null){
    						Array[i][0]=Integer.parseInt(tmp);
    						i++;
    						length++;
    					}
    				} catch (NumberFormatException e) {
    					// TODO Auto-generated catch block
    					e.printStackTrace();
    				} catch (IOException e) {
    					// TODO Auto-generated catch block
    					e.printStackTrace();
    				}
    				try {
    					br.close();
    				} catch (IOException e) {
    					// TODO Auto-generated catch block
    					e.printStackTrace();
    				}
    				Array[0][1]=Array[0][0];
    		        for(int i=1;i<length;i++)
    		        {
    		            if(Array[i-1][1]<=0)
    		            {
    		                Array[i][1]=Array[i][0];
    		            }
    		            if(Array[i-1][1]>0)
    		            {
    		                Array[i][1]=Array[i-1][1]+Array[i][0];
    		            }
    		        }
    		        long Max=Array[0][1];
    		        for(int i=1;i<length;i++)
    		        {
    		            if(Array[i][1]>Max)
    		            {
    		                Max=Array[i][1];
    		            }
    		        }
    		        System.out.println("数组最大值为:"+Max);
    		    }
    
    }
    

      通过使用Scanner类随机产生数字,使用bufferedWriter写入文件shuzu.txt,使用bufferedReader读出文件内容

     

    在本文件中对数据的大小只能到达正负九位数左右,对输入内容的兼容性上有问题

  • 相关阅读:
    Duang!异地多活!_InfoQ_传送门
    异地多活设计辣么难?其实是你想多了!-博客-云栖社区-阿里云
    途牛谭俊青:多数据中心状态同步&两地三中心的理论
    魅族多机房部署方案
    荔枝FM架构师刘耀华:异地多活IDC机房架构
    zz
    “异地多活”多机房部署经验谈_运维管理_数据中心_中国IDC圈
    天猫双11晚会和狂欢城的互动技术方案
    案例 | 魅族云端同步的架构实践和协议细节
    如何应对大促?看京东核心中间件团队的高可用实践指南
  • 原文地址:https://www.cnblogs.com/NCLONG/p/10549181.html
Copyright © 2011-2022 走看看