数组

package jhl;
import java.io .BufferedReader;
import java.io .File;
import java.io .FileReader;
import java.io .IOException;
import java.math.BigInteger;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {
	   private final int STOP = -1;
	   private final int SUSPEND = 0;
	   private final int RUNNING = 1;
	   private int status = 1;
	   private long count = 0;
	
	public static void main(String[] args) throws IOException, InterruptedException {
		
		Scanner sc =new Scanner(System.in );
		Thread thread = new Thread();
		BigInteger TempNum=new BigInteger("0");
		BigInteger Big0=new BigInteger("0");
		BigInteger Max=new BigInteger("0");
		
		String subway_1=subway_1("C:/D/shuzu.txt");
        //System.out.println(subway_1);
		long num=0;
		long num1=0;
        for(int i=0;i<number.length;i++) {
        	boolean flag=Isnumber(number[i]);
        	if(flag==true) {
        		System.out.println("输入为数值!");
        		BigInteger BigNum=new BigInteger(number[i]);
        		TempNum=TempNum.add(BigNum);
        		int is=TempNum.compareTo(Big0);
        		if(is==-1) {
        			TempNum=new BigInteger("0");
        			
        		}else {
        			num++;
        			if(num>(0.5*number.length)) {
        				System.out.println("数组没了");
        				break;
        			}
        			int is2=TempNum.compareTo(Max);
        			if(is2!=-1) {
        				Max=TempNum;
        				num1=i+1;
        			}
        		}
        		System.out.println("读取的"+(i+1)+"个数值:"+BigNum);
        		System.out.println("判断子数组开始的数是:"+num1);
        		System.out.println("判断子数组的数是:"+(i+1));
        		System.out.println("最大值:"+Max);

                Thread.sleep(1000);
        	}
        	else
        		System.out.println("输入不为数值");
        }
	}
	private static  String[]number;
	

	private static  String subway_1(String file) throws IOException {
		
		
			File f=new File(file);
	        @SuppressWarnings("resource")
			BufferedReader bf=new BufferedReader(new FileReader(f));
	       /* 
	        String content="";
	        content=bf.readLine();
	        int line=Integer.parseInt(content);
	        content=bf.readLine();
	        @SuppressWarnings("unused")
			int list=Integer.parseInt(content);
	        content="";
	        for(int aline=0;aline<line;aline++) {
	        	content=content+bf.readLine();
	        }
	        String[] temp = content.split(",");
	        number=temp;
	        */
	        String content="";
	        content=bf.readLine();
	        content=content+content;
	        String[] temp = content.split(",");
	        number=temp;
	        
		return null;
	}
	private static boolean Isnumber(String num) {
		
	    Pattern pattern = Pattern.compile("-?[0-9]+(.[0-9]+)?");
	    Matcher isNum = pattern.matcher(num);
	    if( !isNum.matches() ){
	        return false;
	    }
	    return true;
	}



}

  在网上找了一下,自己也学到了很多

转载于:https://www.cnblogs.com/jhl1234/p/10779841.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值