日期:2019.4.25

博客期:061

星期四

今天是把很久之前的那个相关程序——一维数组的最大和的子数组的求取信息,我们今天的任务就是把每一步的信息都要进行输出查看!

如下图:

  

 package pvp;

 import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.Random;
import java.util.Scanner; public class TestPlay6 {
public static void run(){
File f = new File("data/data.txt");
if(!f.exists())
{
System.out.println("文件不存在!");
System.exit(0);
}
//存储导入内容
String str;
//内容
Scanner sc = null;
try {
sc = new Scanner(f);
} catch (FileNotFoundException e1) {
System.out.println("文件不存在!");
System.exit(0);
}
//最大值
BigInteger rmax = new BigInteger("0");
//正数总值
BigInteger Tnum = new BigInteger("0");
//负数总值
BigInteger Fnum = new BigInteger("0");
//记录是否发生转变
int sis = 0;
//标记是第几程度
int attitude = 0; BigInteger start = BigInteger.ZERO,end = BigInteger.ZERO;
BigInteger true_start = BigInteger.ZERO,true_end = BigInteger.ZERO;
//循环
try
{
BigInteger sis_s = rmax;
BigInteger seat = new BigInteger("0");
if(!sc.hasNext())
{
System.out.println("文件内容为空!");
System.exit(0);
}
while(sc.hasNext())
{
str = sc.next();
BigInteger p = new BigInteger(str);
seat = seat.add(BigInteger.ONE);
end = seat;
if(attitude==0) //---------------------------------------[寻找第一个正数]
{
if(p.compareTo(new BigInteger("0"))<=0)
;
else
{
start = seat;
Tnum = p;
attitude = 1;
}
}
else if(attitude==1) //---------------------------------------[上一个数为正数]
{
if(p.compareTo(new BigInteger("0"))<0)
{
if(sis==0)
{
sis = 1;
Fnum.add(p);
}
else
{
Fnum = p;
}
attitude = -1;
}
else
{
Tnum = Tnum.add(p);
} if(Tnum.compareTo(rmax)>0)
{
rmax = Tnum;
true_start = start;
true_end = end;
}
}
else //---------------------------------------[上一个数为负数]
{
if(p.compareTo(new BigInteger("0"))>0)
{
attitude = 1;
if(Tnum.compareTo(new BigInteger("0").subtract(Fnum))>0)
{
Tnum = Tnum.add(Fnum).add(p);
}
else
{
Tnum = p;
start = seat;
}
}
else
{
Fnum = Fnum.add(p);
}
}
if(p.compareTo(rmax)>0)
{
rmax = p;
true_start = start;
true_end = end;
}
if(p.compareTo(Tnum)>0)
{
rmax = Tnum;
true_start = start;
true_end = end;
}
if(rmax.equals(sis_s))
System.out.println("数据编号:"+seat.toString()+"\t,新数大小:"+p.toString()+"\t,正数总值:"+Tnum.toString()+"\t,负数总值:"+Fnum.toString()+"\t,数组从第"+true_start.toString()+"\t位开始到第"+true_end.toString()+"\t位结束,最大值:"+rmax.toString()+"\t");
else
{
System.err.println("数据编号:"+seat.toString()+"\t,新数大小:"+p.toString()+"\t,正数总值:"+Tnum.toString()+"\t,负数总值:"+Fnum.toString()+"\t,数组从第"+true_start.toString()+"\t位开始到第"+true_end.toString()+"\t位结束,最大值:"+rmax.toString()+"\t");
sis_s = rmax;
}
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
} }
catch( NumberFormatException e){
System.out.println("输入内容不是数字!");
System.exit(0);
}
sc.close();
}
public static void run2(int ls){
File f = new File("data/data.txt");
if(!f.exists())
{
System.out.println("文件不存在!");
System.exit(0);
}
//存储导入内容
String str;
//内容
Scanner sc = null;
try {
sc = new Scanner(f);
} catch (FileNotFoundException e1) {
System.out.println("文件不存在!");
System.exit(0);
}
//最大值
BigInteger rmax = new BigInteger("0");
//正数总值
BigInteger Tnum = new BigInteger("0");
//负数总值
BigInteger Fnum = new BigInteger("0");
//记录是否发生转变
int sis = 0;
//标记是第几程度
int attitude = 0; BigInteger start = BigInteger.ZERO,end = BigInteger.ZERO;
BigInteger true_start = BigInteger.ZERO,true_end = BigInteger.ZERO;
//循环
try
{
BigInteger sis_s = rmax;
BigInteger seat = new BigInteger("0");
if(!sc.hasNext())
{
System.out.println("文件内容为空!");
System.exit(0);
}
BigInteger sss = new BigInteger(Integer.toString(ls));
while(sc.hasNext())
{
str = sc.next();
BigInteger p = new BigInteger(str);
seat = seat.add(BigInteger.ONE);
end = seat;
if(attitude==0) //---------------------------------------[寻找第一个正数]
{
if(p.compareTo(new BigInteger("0"))<=0)
;
else
{
start = seat;
Tnum = p;
attitude = 1;
}
}
else if(attitude==1) //---------------------------------------[上一个数为正数]
{
if(p.compareTo(new BigInteger("0"))<0)
{
if(sis==0)
{
sis = 1;
Fnum.add(p);
}
else
{
Fnum = p;
}
attitude = -1;
}
else
{
Tnum = Tnum.add(p);
} if(Tnum.compareTo(rmax)>0)
{
rmax = Tnum;
true_start = start;
true_end = end;
}
}
else //---------------------------------------[上一个数为负数]
{
if(p.compareTo(new BigInteger("0"))>0)
{
attitude = 1;
if(Tnum.compareTo(new BigInteger("0").subtract(Fnum))>0)
{
Tnum = Tnum.add(Fnum).add(p);
}
else
{
Tnum = p;
start = seat;
}
}
else
{
Fnum = Fnum.add(p);
}
}
if(p.compareTo(rmax)>0)
{
rmax = p;
true_start = start;
true_end = end;
}
if(p.compareTo(Tnum)>0)
{
rmax = Tnum;
true_start = start;
true_end = end;
}
if(sss.compareTo(seat)<=0)
{
if(rmax.equals(sis_s))
System.out.println("数据编号:"+seat.toString()+"\t,新数大小:"+p.toString()+"\t,正数总值:"+Tnum.toString()+"\t,负数总值:"+Fnum.toString()+"\t,数组从第"+true_start.toString()+"\t位开始到第"+true_end.toString()+"\t位结束,最大值:"+rmax.toString()+"\t");
else
{
System.err.println("数据编号:"+seat.toString()+"\t,新数大小:"+p.toString()+"\t,正数总值:"+Tnum.toString()+"\t,负数总值:"+Fnum.toString()+"\t,数组从第"+true_start.toString()+"\t位开始到第"+true_end.toString()+"\t位结束,最大值:"+rmax.toString()+"\t");
sis_s = rmax;
}
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
}
} }
catch( NumberFormatException e){
System.out.println("输入内容不是数字!");
System.exit(0);
}
sc.close();
}
public static void FileMaker(BigInteger leng,BigInteger min,BigInteger max){
File f = new File("data/data.txt");
if(!f.exists())
{
try {
f.createNewFile();
} catch (IOException e) {
//Do Nothing...
}
}
PrintWriter pw = null;
try {
pw = new PrintWriter(f);
} catch (FileNotFoundException e) {
System.out.println("文件不存在!");
System.exit(0);
}
Random ra = new Random(System.currentTimeMillis());
BigInteger bi = new BigInteger("1"); BigInteger sumL = max.subtract(min).add(BigInteger.ONE); while(bi.compareTo(leng)<=0)
{
long x = ra.nextLong();
BigInteger bnum = new BigInteger(Long.toString(x));
bnum = bnum.mod(sumL).add(min);
pw.println(bnum.toString());
bi = bi.add(BigInteger.ONE);
}
pw.close();
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入数据量:");
String str = sc.next();
System.out.println("请输入数据范围:");
String str1 = sc.next();
String str2 = sc.next();
System.out.println("确定是否查看关键步骤");
boolean isKey = false;
try{
isKey = sc.nextBoolean();
BigInteger leng = new BigInteger(str);
BigInteger num1 = new BigInteger(str1);
BigInteger num2 = new BigInteger(str2);
if(num1.compareTo(num2)==0)
throw new Exception();
else if(leng.compareTo(BigInteger.ZERO)<0)
throw new Exception();
else
{
if(num1.compareTo(num2)<0)
FileMaker(leng,num1,num2);
else
FileMaker(leng,num2,num1);
}
}catch(Exception e){
System.out.println("爷爷!出现问题了!");
System.exit(0);
} if(!isKey)
run();
else
{
run();
try{
int l = sc.nextInt();
run2(l);
}catch (Exception e){
//Do Nothing...
}
}
sc.close();
}
}

TestPlay6

Java软件工程的弹幕调试原则的更多相关文章

  1. ndk-gdb 对java/native code联合调试(升级版)

    之前写过一篇 关于android native 开发,调试的文章(http://www.cnblogs.com/yaozhongxiao/archive/2012/03/13/2393959.html ...

  2. developerWorks 中国 技术主题 Java technology 文档库 Java 性能测试的四项原则

    转-https://www.ibm.com/developerworks/cn/java/j-lo-java-performance-testing/?cm_mmc=dwchina-_-homepa ...

  3. Java设计模式的6大原则

    Java设计模式的6大原则 1.开闭原则(Open Close Principle) 开闭原则就是说对扩展开放,对修改关闭.在程序需要进行拓展的时候,不能去修改原有的代码,实现一个热插拔的效果.简单来 ...

  4. 图解Java设计模式之设计模式七大原则

    图解Java设计模式之设计模式七大原则 2.1 设计模式的目的 2.2 设计模式七大原则 2.3 单一职责原则 2.3.1 基本介绍 2.3.2 应用实例 2.4 接口隔离原则(Interface S ...

  5. RASP | 远程Java应用的RASP调试教程

    远程Java应用的RASP调试教程 介绍 Java RASP是基于Java Agent技术实现的,而Java Agent代码无法独立启动,必须依赖于一个Java运行时程序才能运行. 如何调试一个Jav ...

  6. 有效处理java异常的三个原则

    Java中异常提供了一种识别及响应错误情况的一致性机制,有效地异常处理能使程序更加健壮.易于调试.异常之所以是一种强大的调试手段,在于其回答了以下三个问题: 什么出了错? 在哪出的错? 为什么出错? ...

  7. Java GC 专家系列5:Java应用性能优化的原则

    本文是GC专家系列中的第五篇.在第一篇理解Java垃圾回收中我们学习了几种不同的GC算法的处理过程,GC的工作方式,新生代与老年代的区别.所以,你应该已经了解了JDK 7中的5种GC类型,以及每种GC ...

  8. Java Eclipse进行断点调试

    如何调试Java程序? 大家最开始学习Java,都会觉得IDE调试好高端有木有,其实很简单了. 下文会尽量简单直观的教会你在Eclipse中调试,其他的IDE调试步骤也是类似的. 1.在你觉得有错的地 ...

  9. JAVA设计模式之依赖倒转原则

    3.1 依赖倒置原则的定义 依赖倒置原则(Dependence Inversion Principle,简称DIP)这个名字看着有点别扭,“依赖”还“倒置”,这到底是什么意思?依赖倒置原则的原始定义是 ...

随机推荐

  1. git忽略文件不起作用时

    开始我是直接进到仓库建立了.gitignore文件,再从仓库进入到项目add时总是会添加不需要添加的文件, 后来明白应该是在哪里提交在哪里创建.gitignore文件 git忽略文件操作步骤如下: 1 ...

  2. springdata 一对多 级联操作 在注解里面开启级联操作@OneToMany(mappedBy = "customer",cascade = CascadeType.ALL)

  3. 如何关闭WIN7自动配置 IPV4 地址 169.254

    如何关闭WIN7自动配置 IPV4 地址 169.254 以管理员身份运行cmd.exe 输入:netsh winsock reset catalog 回车 输入:netsh int ip reset ...

  4. Centos下MariaDB操作

    MariaDB简介 MariaDB是mysql数据库的一个分支,操作几乎和mysql一样 MariaDB安装.启动.停止 # 安装 yum -y install mariadb mariadb-ser ...

  5. mac下安装gradle

    安装 gradle brew install gradle 配置Path环境 vim .bash_profile // 写入 export PATH="${PATH}:/usr/local/ ...

  6. Asp.netMVC模型

    Model负责在View和控制器之间进行数据的传递:用户输入的内容封装为Model对象,发给Controller:要显示的数据有Controller放到Model中,然后扔给View去显示.Contr ...

  7. matplotlib的读书笔记

    matplotlib绘图总结   本文作为学习过程中对matplotlib一些常用知识点的整理,方便查找. 类MATLAB API 最简单的入门是从类 MATLAB API 开始,它被设计成兼容 MA ...

  8. 实验一 Java开发环境的熟悉(Linux + Eclipse)

    学号 20175206 实验一 <Java开发环境的熟悉>实验报告 实验内容 1.使用JDK编译.运行简单的Java程序: 2.使用Eclipse 编辑.编译.运行.调试Java程序. 实 ...

  9. 【优秀的iPhone/iPad数据恢复工具】Omni Recover for Mac 2.5

    [简介] 今天和大家分享最新的 Omni Recover for Mac 2.5 版本,这是一款Mac上优秀的iPhone/iPad设备数据恢复工具,支持恢复误删除的短信.照片.视频.文档.通话记录等 ...

  10. (六)循环和控制语句及列表迭代(enumerate)

    一.pythoh中while.for.if的循环 嗯.........这个好像没什么好说的,简单粗暴来几个游戏! 1.来玩儿个猜数字游戏,需求:只能猜3次,小了提示小,大了提示大,猜对了游戏结束 3次 ...