该程序应显示计算总数的一系列分数(由用户确定)。它不允许我在程序中输入分数,只是它们所说的数量通常是无效的。
import java.util.*;
public class Fractions
{
public static void main(String[] arg)
{
//------------------ declare ints and constants ----
Scanner stdIn = new Scanner(System.in);
int fractions = 0,
count = 1,
fractionAdd = 0;
double enteredFraction = 0;
boolean inValid = false;
//------------------- welcome msg -----------------------
System.out.println("\n * * * Welcome to Fractions * * *\n");
//--------------------- get input ----------------------
System.out.print("Enter the number of fractions: ");
fractions = stdIn.nextInt();
if (fractions < 2 && fractions > 10)
inValid = true;
else
inValid = true;
while (inValid)
{
System.out.print(
fractions + " is invalid, please re-enter ractions (2-10): "
);
fractions = stdIn.nextInt();
if (fractions < 2 && fractions > 10)
inValid = true;
else
inValid = false;
}
while (count < fractions)
{
System.out.println(fractions + "+");
fractions += count;
while (fractions < count)
{
System.out.print(enteredFraction + " +");
fractions ++;
}
if(enteredFraction <= fractions)
System.out.println("Error, please re-enter number of fractions (2-10)");
}
//--------------------- end msg ---------------------------
System.out.println("\nThanks for using the Fraction Adder program");
} //end main
}//end program
答案 0 :(得分:1)
if (fractions < 2 && fractions > 10)
inValid = true;
else
inValid = true;
我认为问题在这里。 你设置了'inValid&#39;在这两种情况下都有标志。
答案 1 :(得分:0)
您必须将$("#textarea").on('keydown',function(e){
if (e.ctrlKey && String.fromCharCode(e.which).toLocaleLowerCase() == 'b') {
e.preventDefault();
var cursorPosition = $(this).prop("selectionStart");
this.value = this.value.substr(0, cursorPosition) + '-b- -.b-' + this.value.substr(cursorPosition);
$(this).prop("selectionStart", cursorPosition + 3);
$(this).prop("selectionEnd", cursorPosition + 3);
}
});
更改为<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<textarea id="textarea"></textarea>
以及
fractions += count;
总是fractions += count;
您必须将其更改为if (fractions < 2 && fractions > 10)
inValid = true;
else
inValid = true;