我必须使用Scanner
,所以是有一个nextChar()
,而不是nextLine()
,我可以使用的方法?
谢谢!
我想知道如何将值输入到带有html的表单中.因此,当用户访问该站点时,文本框中已有数字,并且他们使用这些数字进行播放和"添加游戏".这是我到目前为止:
<script type="text/javascript">
function addSubmit() {
//trying to have num1 and num2 write into the html form
var num1= Math.floor(89+Math.random()*11);
var num2 = Math.floor(89+Math.random()*11);
/*num1 = value1
num2 = value2*/
document.getElementById("value1").value = num1;
document.getElementById("value2").value = num2;
var guess = document.getElementById("submit").value;
var answer = num1 + num2;
//have to write this to main window
if (guess == answer)
document.writeln("Congratulations you answered correctly! The answer to: "+num1+"+"+num2+"= "+answer);
else
document.writeln("Nice try, but the correct answer to: "+num1+"+"+num2+"= "+answer);
}
function addGiveUp() { …
Run Code Online (Sandbox Code Playgroud) 我看了一遍,似乎无法找到任何帮助..对于一个学校项目,我有一个BST树,我必须将所有从树中的整数放入一个名为BSTarray的int数组.
这是我到目前为止:
public int [] toBSTArray() {
int size = 20;
int [] BSTarray = new int [size];
for(int i = 0; i <size; i++) {
makeArray(root);
BSTarray[i] = root.getValue();
}
return BSTarray;
}
//helper method called by toBSTArray
public void makeArray(BinarySearchTreeNode node) {
if (node != null) {
makeArray(node.getLeft());
makeArray(node.getRight());
// System.out.print(node.getValue() + " ");
}
}
Run Code Online (Sandbox Code Playgroud)
我认为这个方法应该通过树并将它找到的值添加到BSTarray中的不同索引中,但它所做的只是将相同的数字添加到数组中的所有索引中.我在递归时做错了吗?
因此,对于我的 cit 课程,我必须编写一个猪拉丁语转换器程序,并且我对如何一起使用数组和字符串感到非常困惑。转换的规则很简单,只需将单词的第一个字母移到后面,然后添加 ay 即可。例如:英语中的地狱将是猪拉丁语中的 ellhay 到目前为止我有这个:
<form name="form">
<p>English word/sentence:</p> <input type="text" id="english" required="required" size="80" /> <br />
<input type="button" value="Translate!" onClick="translation()" />
<p>Pig Latin translation:</p> <textarea name="piglat" rows="10" cols="60"></textarea>
</form>
<script type="text/javascript">
<!--
fucntion translation() {
var delimiter = " ";
input = document.form.english.value;
tokens = input.split(delimiter);
output = [];
len = tokens.length;
i;
for (i = 1; i<len; i++){
output.push(input[i]);
}
output.push(tokens[0]);
output = output.join(delimiter);
}
//-->
</script>
Run Code Online (Sandbox Code Playgroud)
我真的很感激我能得到的任何帮助!
对于一个项目,我有一个类似银行的程序."银行"读入一个文件,其中的帐户如下所示:
Miller
William
00001
891692 06 <----需要转换为double
的字符串最后一个字符串必须转换为double,以便程序可以像加法和减法等一样对它进行计算.
而且我还要以货币格式打印出来,即$ 891692.06
到目前为止我有这个:
public class Account {
private String firstName, lastName;
private int accountID;
private String currentBalance;
private static int maxAccountID;
public Account(String fN, String lN, int acct, String bal) {
firstName = fN; lastName = lN;
accountID = acct;
currentBalance = bal;
if(accountID > Account.maxAccountID)
Account.maxAccountID = accountID;
}
public double getBalance(){
String [] s = currentBalance.split(" ");
String balStr = "$"+s[0]+"."+s[1];
double currentBalance = Double.parseDouble(balStr);
return currentBalance;
}
}
Run Code Online (Sandbox Code Playgroud)
提前致谢!
我环顾四周,似乎我有正确的语法:
QueueOfChars queue = new QueueOfChars();
QueueOfChars.QueueOfCharsNode charNode = queue.new QueueOfCharsNode();
Run Code Online (Sandbox Code Playgroud)
但是,我尝试创建的charNode对象出现编译错误
Driver3.java:22:错误:类
QueueOfChars.QueueOfCharsNode中的构造函数QueueOfCharsNode 不能应用于给定的类型;
QueueOfChars.QueueOfCharsNode charNode = queue.new QueueOfCharsNode();
required:char
found:无参数
原因:实际和形式参数列表长度
1错误不同
它收到此错误,因为我有一个QueueOfCharsNode(char ch)
public class QueueOfChars{
public class QueueOfCharsNode{
QueueOfCharsNode next;
QueueOfCharsNode prev;
char c;
public QueueOfCharsNode(char ch){ //line causing the error
c = ch;
next = prev = null;
}
Run Code Online (Sandbox Code Playgroud)
当我为它制作对象时,如何才能读取"公共类QueueOfCharsNode"行?