如果此代码格式不正确,我会提前道歉,尝试粘贴而不是重新输入每一行.如果它不对,有人可以告诉我一次粘贴多行代码的简单方法吗?
我的主要问题是我不断收到一条错误消息: Cannot make a static reference to the non-static field balance.
我试过使方法静态,没有结果,并通过从标题中删除"静态"使主方法非静态,但后来我收到消息: java.lang.NoSuchMethodError: main Exception in thread "main"
有没有人有任何想法?任何帮助表示赞赏.
public class Account {
public static void main(String[] args) {
Account account = new Account(1122, 20000, 4.5);
account.withdraw(balance, 2500);
account.deposit(balance, 3000);
System.out.println("Balance is " + account.getBalance());
System.out.println("Monthly interest is " + (account.getAnnualInterestRate()/12));
System.out.println("The account was created " + account.getDateCreated());
}
private int id = 0;
private double balance = 0;
private double annualInterestRate = 0;
public java.util.Date dateCreated;
public Account() …Run Code Online (Sandbox Code Playgroud) 我查看了如何在线退出应用程序,我发现了许多相互矛盾的答案.不同的人提出以下建议,每个都有不同的原因:
exit(0);
[NSApp terminate:self];
[NSApp terminate:nil];
[[NSApplication sharedApplication] terminate:self];
Run Code Online (Sandbox Code Playgroud)
作为Objective-C的新手,所有这些对我来说都很合理.每种方法何时最适合使用?
我知道在TI-BASIC中,惯例是尽可能地优化并保存尽可能多的位(这是非常有趣的,我承认).
例如,
DelVar Z
Prompt X
If X=0
Then
Disp "X is zero"
End //28 bytes
Run Code Online (Sandbox Code Playgroud)
会被清理干净
DelVar ZPrompt X
If not(X
"X is zero //20 bytes
Run Code Online (Sandbox Code Playgroud)
但这种方式优化代码实际上有所作为吗?它明显运行得更快还是节省内存?
我认为trimToSize()Java的ArrayList中的方法是不必要的.我的理解是:
我们来看一个整数数组:
int[] a = new int[10]; //This allocates ten free slots proactively.
Run Code Online (Sandbox Code Playgroud)
ArrayList的主要优点是它可以在运行时动态创建数组,从而节省内存.现在代码
ArrayList<Integer> arl = new ArrayList<Integer>(10);不会主动分配十个空闲插槽; 相反,只有在存储数据时才添加插槽.
现在Java规范说trimToSize()将从ArrayList中删除未使用的空间,但根据我的理解,ArrayList中不会有任何未使用的空间,因为只有在数据可用时才创建空间,并且当数据可用时,未使用或可用空间将为零.
我是编程Objective-C和编程的新手,所以如果这是一个非常明显的问题,请原谅我:
我想知道Objective-C是否逐行运行代码.我的意思是,如果它在移动到另一条线之前处理一条线,或者它只是运行下一条线而不管前一条线是否完成.
例如,
int difference = number1 - number2;
if (difference < 0) {
difference = difference + 10;
}
result = difference;
Run Code Online (Sandbox Code Playgroud)
说number1 = 3和number2 = 7.当我运行这段代码时,它会逐行进行并在第5行之前运行if块给我result = 6,还是会同时开始运行if块和第5行并给我result = -4?
提前致谢!
编辑:由于Obj-C怪癖,将模数更改为加法.
我刚刚开始学习HTML和CSS,我在这里遇到了一个问题.
我正在使用Bootstrap作为我的页面,这是我迄今为止所做的,简化:
index.html的:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<link rel="stylesheet" href="main.css">
</head>
<body>
<div class="div">
<h3>Title</h3>
<p>Description</p>
</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
的main.css:
h, p {
font-family: "Times New Roman", serif;
}
Run Code Online (Sandbox Code Playgroud)
文本<p>显示就像Times New Roman一样好,但文本<h3>拒绝改变.
为什么会这样,我该如何解决?对不起,如果这是一个明显的问题.