java课程课后作业190425之一维数组最大子数组—功能扩展(界面实现)

  题目要求:

1.在第一个问题过程中,我在以前的代码中好像已经写出了这个功能,想要实现这个功能,我们只需要在我们储存的数组和是负数的时候对中转值进行重新赋值就可以得到新的数值的起始位置,而他的终了位置就是程序运行到那个地方时候的数值,其余的输出也是十分简单的

2.题目要求每运行一次就需要稍作停留,由于当时没有仔细的看题目,所以导致理解错误,理解成了直接暂停,当触发按键的时候则继续开始,然后问老师这个功能其实也是可以实现的,这个问题我以后再考虑一下,过段时间再来思考这个问题,因为最近时间有点挤。那么按照题目的要求,我们可以很清楚的发现问题解决的方法就在于线程的挂起, Thread.sleep(1000);即将这个线程暂停一秒,此函数就可以解决这个问题。

  1 package LessonTest20190314;
  2 
  3 import java.io.BufferedReader;
  4 import java.io.File;
  5 import java.io.FileReader;
  6 import java.io.IOException;
  7 import java.math.BigInteger;
  8 import java.util.Scanner;
  9 import java.util.regex.Matcher;
 10 import java.util.regex.Pattern;
 11 
 12 public class Main {
 13        private final int STOP = -1;
 14        private final int SUSPEND = 0;
 15        private final int RUNNING = 1;
 16        private int status = 1;
 17        private long count = 0;
 18     @SuppressWarnings("deprecation")
 19     public static void main(String[] args) throws IOException, InterruptedException {
 20         // TODO Auto-generated method stub
 21         Scanner sc =new Scanner(System.in);
 22         Thread thread = new Thread();
 23         BigInteger TempNum=new BigInteger("0");
 24         BigInteger Big0=new BigInteger("0");
 25         BigInteger Max=new BigInteger("0");
 26         @SuppressWarnings("unused")
 27         String subway_1=subway_1("C:/D/shuzu.txt");
 28         //System.out.println(subway_1);
 29         long num=0;
 30         long num1=0;
 31         for(int i=0;i<number.length;i++) {
 32             boolean flag=Isnumber(number[i]);
 33             if(flag==true) {
 34                 System.out.println("输入为数值!");
 35                 BigInteger BigNum=new BigInteger(number[i]);
 36                 TempNum=TempNum.add(BigNum);
 37                 int is=TempNum.compareTo(Big0);
 38                 if(is==-1) {
 39                     TempNum=new BigInteger("0");
 40                     
 41                 }else {
 42                     num++;
 43                     if(num>(0.5*number.length)) {
 44                         System.out.println("数组只能到这了!");
 45                         break;
 46                     }
 47                     int is2=TempNum.compareTo(Max);
 48                     if(is2!=-1) {
 49                         Max=TempNum;
 50                         num1=i+1;
 51                     }
 52                 }
 53                 System.out.println("读取的"+(i+1)+"个数值:"+BigNum);
 54                 System.out.println("当前判断子数组开始的数是:"+num1);
 55                 System.out.println("当前判断子数组的数是:"+(i+1));
 56                 System.out.println("最大值:"+Max);
 57 
 58                 Thread.sleep(1000);
 59             }
 60             else
 61                 System.out.println("输入不为数值!");
 62         }
 63     }
 64     private static  String[]number;
 65     
 66 
 67     private static  String subway_1(String file) throws IOException {
 68         // TODO Auto-generated method stub
 69         
 70             File f=new File(file);
 71             @SuppressWarnings("resource")
 72             BufferedReader bf=new BufferedReader(new FileReader(f));
 73            /* 
 74             String content="";
 75             content=bf.readLine();
 76             int line=Integer.parseInt(content);
 77             content=bf.readLine();
 78             @SuppressWarnings("unused")
 79             int list=Integer.parseInt(content);
 80             content="";
 81             for(int aline=0;aline<line;aline++) {
 82                 content=content+bf.readLine();
 83             }
 84             String[] temp = content.split(",");
 85             number=temp;
 86             */
 87             String content="";
 88             content=bf.readLine();
 89             content=content+content;
 90             String[] temp = content.split(",");
 91             number=temp;
 92             
 93         return null;
 94     }
 95     private static boolean Isnumber(String num) {
 96         
 97         Pattern pattern = Pattern.compile("-?[0-9]+(.[0-9]+)?");
 98         Matcher isNum = pattern.matcher(num);
 99         if( !isNum.matches() ){
100             return false;
101         }
102         return true;
103     }
104 
105 
106 
107 }
原文地址:https://www.cnblogs.com/heiyang/p/10770138.html