%s是一个字符串printf,%d是我认为的小数......但是在放入时
writer.printf("%d dollars is the balance of %s\r\n", bal, nm);
Run Code Online (Sandbox Code Playgroud)
..抛出一个异常告诉我%d!= lang.double.想法?
所以几个星期以来我一直在来回尝试将以下代码创建为递归方法......
public static int binarySearch(Comparable[] objArray,Comparable item)
{
int lower=0;
int upper=objArray.length -1;
int i=-1; // if -1 is returned the search failed;
int compareResult;
boolean found= false;
while ((lower<=upper)&& (!found))
{
i=(lower+upper)/2;
compareResult=item.compareTo( objArray[i]);
if (compareResult<0)
{
upper=i-1;
}
else
if (compareResult>0)
{
lower=i+1;
}
else
{
found=true; //item found in spot i
}
}// end of while
if (found==false) return -1; else return i;
}
Run Code Online (Sandbox Code Playgroud)
我知道我必须重新定义整数并使用几个ifs,但没有while循环我不明白如何获得我想要的最终递归代码.有什么建议?谢谢
-D
package pkgPeople;
import java.io.File;
import java.io.PrintWriter;
import java.util.Scanner;
public class CreateWithoutSerialization {
public static void main(String[] args) throws Exception
{
BankAccount bankAccount = new BankAccount(0, 0);
Person person = new Person();
String nm;
int ht;
int wt;
long ba;
double bal;
File inFile = new File("G:/CS9.27/inperson.txt");
File outFile = new File("G:/CS9.27/outperson.txt");
PrintWriter writer = new PrintWriter(outFile);
Scanner reader = new Scanner(inFile);
nm = reader.nextLine();
ht = reader.nextInt();
wt = reader.nextInt();
ba = reader.nextLong();
bal = reader.nextDouble();
person.setName(nm);
person.setHeight(ht);
person.setWeight(wt); …Run Code Online (Sandbox Code Playgroud) 我有以下代码
public static int unknown(String x)
{
if ((x.length()==1) && (x.equals("1")))
return 1;
else if ((x.length()==1) && (x.equals("0")))
return 0;
else if (x.charAt(x.length()-1)=='1')
return 1+ 2*unknown(x.substring(0,x.length()-1));
else
return 0+2*unknown(x.substring(0,x.length()-1));
}
Run Code Online (Sandbox Code Playgroud)
我的教授说我必须绘制递归调用的图表.他在谈论什么样的图表?我应该如何展示它?谢谢.
PS正在调用的字符串是"101011",或43.
-担
所以这看起来像是一个普遍的问题..但是为了快速有效地学习编程语言,C#还是Java的方法呢?(我更喜欢VS2010)
是否有某种网站可以帮助大三学生更有效地理解这些语言?
谢谢...只是寻找一些意见
-DS