这个问题的标题实际上是以前的考试问题,我正在寻找澄清/答案.
请注意,我正在学习Java并且正在熟悉它的语法.
我知道以前可能会问过这个问题,如果有的话,有人可以告诉我,如果可能的话,我可以在哪里提出这个问题吗?如果是这种情况,也请接受我的道歉.为了表明我一直在研究这个领域,我自己的理解是实例变量属于某个类(模板)的对象/实例,并且可以在需要时在该实例/对象中进行更改(变异).
类变量是一个只有一个副本且可以访问但不能被修改(变异?)的变量,但是所有类都可以根据需要使用它?
我在这里走在正确的轨道上吗?
另外,'静态'到底是做什么的?如果一个类的实例位于类的主实例中,那么它是静态的吗?
非常感谢.
我想按出生年份的降序排序我的数组.我的数组有另外两个String类型的元素.因此,作为一个例子,出生在最早年的人,如1939年,将处于最顶层,然后如此.
这是我的代码:
import java.util.*;
public class StudentInformationTest
{
public static void main (String [] args){
StudentInformation[] studentInfo = new StudentInformation[10];
studentInfo[0] = new StudentInformation("Student A",1971, "BSc FDIT");
studentInfo[1] = new StudentInformation("Student B",1964, "BSc FDIT");
studentInfo[2] = new StudentInformation("Student C",1996, "BSc FDIT");
studentInfo[3] = new StudentInformation("Student D",1939, "BSc FDIT");
studentInfo[4] = new StudentInformation("Student E",1945, "BSc FDIT");
studentInfo[5] = new StudentInformation("Student F",1991, "BSc FDIT");
studentInfo[6] = new StudentInformation("Student G",1987, "BSc FDIT");
studentInfo[7] = new StudentInformation("Student H",1968, "BSc FDIT");
studentInfo[8] = new StudentInformation("Student …Run Code Online (Sandbox Code Playgroud) 我在使用以下语法时遇到了一些问题.
我目前正在学习Java,并且一直在阅读过去的考试文章,以帮助我建立自己的Java知识.
这是一个问题:
写一个类帐户,其中包含帐号的实例变量和帐户的当前余额.实现构造函数和方法getAccountNumber(),getBalance(),debit(double amount)和credit(double amount).在您的借记和贷记实施中,检查指定的金额是否为正,并且在借方法中不会引起透支.在这些情况下返回false.否则,请更新余额.
我曾试图这样做,但我还没有为借记和贷记方法实现布尔函数.我只是想先建立程序并尝试让它运行起来.我之后会看到这个,因为我不确定如何返回真或假,同时也试图从所述方法中返回一定数量.
请原谅我的代码中的任何错误,因为我还在学习Java.
我可以运行我的代码,但是当我输入存款时,它似乎无法正常工作,我将在此感谢任何指示.
这是我的代码:
import java.util.*;
public class Account {
private int accountNumber;
private static double currentBalance;
private static double debit;
// ***** CONSTRUCTOR *****//
public Account(double currentBalance, int accountNumber) {
accountNumber = 12345;
currentBalance = 10000.00;
}
public int getAccountNumber(int accountNumber) {
this.accountNumber = accountNumber;
return accountNumber;
}
public double getcurrentBalance(double currentBalance) {
this.currentBalance = currentBalance;
return currentBalance;
}
public static double debit(double currentBalance, double amount) {
currentBalance -= amount;
return currentBalance;
} …Run Code Online (Sandbox Code Playgroud) 我试图从我的int数组返回两个最大的整数.我能够返回最大和最小的罚款,但我不能让我的算法返回最大的两个.这里非常感谢任何帮助.
请原谅我的代码中的任何错误.这是一个练习课程,问题来自去年大学的考试材料.
这是我的代码:
public class TwoLargestIntsArray {
public static void main(String [] args){
int [] values = new int[5];
values[0] = 5;
values[1] = 10;
values[2] = 15;
values[3] = 20;
values[4] = 25;
System.out.println(twoLargest(values));
System.out.println();
}
public static int twoLargest(int values[]){
int largestA = values[0];
int largestB = values[0];
for(int i = 0; i < values.length; i++){
if(values[i] > largestA){
largestA = values[i];
}
if(values[i] < largestA){
largestB = values[i];
}
}
return largestA + largestB;
}
}
Run Code Online (Sandbox Code Playgroud) 我将在过去的试卷上查看一系列问题.其中一个问题是boolean类型.
如果名称不是Thomas,则应返回false,如果是,则返回true.
这是我的代码:
public class QuestionTwo
{
String name;
public static void main(String [] args){
System.out.println(nameTest("Thomas"));
}
public static boolean nameTest(String name){
if(!name.equals("Thomas"));
return false;
}
}
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,我的代码应该返回true,但它会一直返回false?有人可以告诉我,我的代码似乎出了问题吗?请原谅我仍在学习的任何愚蠢的错误.非常感谢.
我试图使用Math.pow找到一小组整数的几何平均值.这是我第一次使用这种语法,我不知道如何完成我的代码.
我目前正在阅读去年的考试试卷,这是其中一个问题.
请原谅我的代码中的任何错误.我还在学习Java.
public class AverageOfArray {
public static void main(String []args){
int [] data = new int[3];
data[0] = 2;
data[1] = 4;
data[2] = 8;
int y = 0;
int sum = 0;
for(int i = 0; i < data.length; i++){
sum = sum + data[i];
y++;
}
Math.pow(sum, 1.0/data.length);
System.out.println(sum);
}
}
Run Code Online (Sandbox Code Playgroud)
虽然代码运行正常没有错误,但它没有给我我需要的输出.平均值应为4.
以下是一些编辑后的代码:
public class AverageOfArray {
public static void main(String []args){
int [] data = new int[3];
data[0] = 2;
data[1] = 4;
data[2] = …Run Code Online (Sandbox Code Playgroud) 我正在参加之前的信息安全考试。
我正在研究与密码加密有关的加盐。我的问题是 - 如果 SHA 256 是一种单向加密,那么如何解密?
我只是想,当通过电子邮件发送消息时,它们会被加密和解密,以便可以访问消息或文件。
SHA 256 如何工作?如果加密无法解密,您如何查看您的消息或文件?或者它只是保护密码本身?
我目前正在研究这个(在大学),希望得到任何帮助。请原谅我的问题中的任何愚蠢错误,因为我仍在尝试了解这个主题。
谢谢。