我正在编写一个java代码来编写一个文本文件,我正在打印输出以查看是否所有条件都正确,有些情况下输出是正确的,而某些情况对于相同的条件是不正确的。 案例是:
bpup >= 14 => out1 = 0 out 2 = 0
bpdown >= 9 => out1 = 0 out 2 = 1
bpup > 14 and bpdown > 9 => out1 = 1 out2 = 0
bpup > 14 and bpdown > 9 and pulse <60 => out1 = 1 out2 = 1
这是我的代码:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package pfetext;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Random;
/**
*
* @author user
*/
public class PFEtext {
/**
* @param args the command line arguments
*/
static int i = 10;
static int out1;
static int out2;
public static void main(String[] args) throws IOException {
// TODO code application logic here
int bpup;
int bpdown;
int pulse;
int O2;
FileWriter fw=new FileWriter("C:\\Users\\user\\Desktop\\pfe.txt");
BufferedWriter bw= new BufferedWriter(fw);
do {
Random p = new Random();
bpup = p.nextInt(23 - 3) + 3 ;
bpdown = p.nextInt(17 - 4) + 4 ;
pulse = p.nextInt(150 - 30) + 30 ;
O2 = p.nextInt(100 - 40) + 40;
//Epistaxis
if(bpup >= 14){
out1 = 0;
out2 = 0;
System.out.println("========== CASE EPISTACSIS ==========");
System.out.println("BPUP " + bpup + " " + "BPDOWN " + bpdown + " " + "PULSE " + pulse + " " + "OUT1 " + out1 + " " + "OUT2 " + out2);
// bw.write(bpup + "," + bpdown + "," + pulse + "," + O2 + "," + out1 + "," + out2);
// bw.newLine();
}
//Blackout
if(bpdown >= 9){
out1 = 0;
out2 = 1;
System.out.println("========== CASE BLACKOUT ==========");
System.out.println("BPUP " + bpup + " " + "BPDOWN " + bpdown + " " + "PULSE " + pulse + " " + "OUT1 " + out1 + " " + "OUT2 " + out2);
// bw.write(bpup + "," + bpdown + "," + pulse + "," + O2 + "," + out1 + "," + out2);
// bw.newLine();
}
//Epistaxis and Blackout
if(bpup >= 14 && bpdown > 9){
out1 = 1;
out2 = 0;
System.out.println("========== CASE EPISTACSIS & BLACKOUT ==========");
System.out.println("BPUP " + bpup + " " + "BPDOWN " + bpdown + " " + "PULSE " + pulse + " " + "OUT1 " + out1 + " " + "OUT2 " + out2);
// bw.write(bpup + "," + bpdown + "," + pulse + "," + O2 + "," + out1 + "," + out2);
// bw.newLine();
}
//Numbness
if(bpup >= 15 && bpdown >= 9 && pulse <= 60){
out1 = 1;
out2 = 1;
System.out.println("========== NUMBNESS ==========");
System.out.println("BPUP " + bpup + " " + "BPDOWN " + bpdown + " " + "PULSE " + pulse + " " + "OUT1 " + out1 + " " + "OUT2 " + out2);
// bw.write(bpup + "," + bpdown + "," + pulse + "," + O2 + "," + out1 + "," + out2);
// bw.newLine();
}
i--;
}while(i>0);
bw.write(bpup + "," + bpdown + "," + pulse + "," + O2 + "," + out1 + "," + out2);
bw.newLine();
bw.close();
}
}
这是输出:
========== CASE BLACKOUT ==========
// correct
BPUP 9 BPDOWN 12 PULSE 106 OUT1 0 OUT2 1
========== CASE BLACKOUT ==========
// correct
BPUP 8 BPDOWN 11 PULSE 145 OUT1 0 OUT2 1
========== CASE BLACKOUT ==========
//correct
BPUP 7 BPDOWN 15 PULSE 103 OUT1 0 OUT2 1
========== CASE BLACKOUT ==========
// incorrect should be epistaxis and blackout
BPUP 13 BPDOWN 12 PULSE 145 OUT1 0 OUT2 1
========== CASE EPISTACSIS ==========
//correct
BPUP 18 BPDOWN 7 PULSE 125 OUT1 0 OUT2 0
========== CASE EPISTACSIS ==========
// incorrect should be epistaxis and blackout
BPUP 18 BPDOWN 11 PULSE 109 OUT1 0 OUT2 0
========== CASE BLACKOUT ==========
// incorrect should be epistaxis and blackout
BPUP 18 BPDOWN 11 PULSE 109 OUT1 0 OUT2 1
========== CASE EPISTACSIS & BLACKOUT ==========
// correct
BPUP 18 BPDOWN 11 PULSE 109 OUT1 1 OUT2 0
========== CASE BLACKOUT ==========
// correct
BPUP 3 BPDOWN 9 PULSE 107 OUT1 0 OUT2 1
========== CASE BLACKOUT ==========
//correct
BPUP 10 BPDOWN 10 PULSE 114 OUT1 0 OUT2 1
答案 0 :(得分:0)
从我所看到的,不平等有问题:
//Epistaxis and Blackout
if (bpup >= 14 && bpdown > 9) {
对于bpup = 14也是如此,而你说它只对bpup&gt;是真的14。
此外:
//Numbness
if (bpup >= 15 && bpdown >= 9 && pulse <= 60) {
对于pulse = 60是正确的,而你说它必须对于脉冲&lt; 60和 对于bpdown = 9是正确的,而你说它只对bpdown&gt;是真的9