所花时间 :10小时 代码量 :200行 博客量 :两篇 了解到的新知识:对上次数组课堂练习的一个升级:
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 Sz1 {
private final int STOP = -1; private final int SUSPEND = 0; private final int RUNNING = 1; private int status = 1; private long count = 0; @SuppressWarnings("deprecation") public static void main(String[] args) throws IOException, InterruptedException { // TODO Auto-generated method stub 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"); @SuppressWarnings("unused") 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 {
// TODO Auto-generated method stub 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; }
}