我需要使用泛型实现自定义链表.
这就是我所做的
public class Node {
Node next;
Object data;
public Node(Object data) {
next = null;
this.data = data;
}
public Object getData() {
return data;
}
public void setData(Object dataValue) {
data = dataValue;
}
public Node getNext() {
return next;
}
public void setNext(Node nextValue) {
next = nextValue;
}
}
public class LinkedList {
private Node head;
private int size;
public LinkedList() {
head = new Node(null);
size = 0;
}
public void add(Object data) { …Run Code Online (Sandbox Code Playgroud) public void onClick(View v){
switch(v.getId()){
case R.id.bereken:
EditText basis = (EditText)findViewById(R.id.Basis);
String tussenBasis = basis.getText().toString();
Double.valueOf(tussenBasis);
//
EditText hoogte = (EditText)findViewById(R.id.Hoogte);
String tussenHoogte = hoogte.getText().toString();
Double.valueOf(tussenHoogte);
double half = 1 / 2;
//half = 0,5
double einde = half * basis * hoogte;
//eind antwoord formule
((TextView)findViewById(R.id.antwoord)).setText("Het antwoord is: " + einde);
break;
}
}
}
Run Code Online (Sandbox Code Playgroud)
我正在尝试为三角形区域制作一个简单的计算器,但我似乎被困在这里.
我的Arraylist只存储一个对象.每次输入新对象时,它都会覆盖当前的对象.
通话方式:
public void saveBookingInfo(View view) {
EditText applicantNameText = (EditText) findViewById(R.id.applicantNameTextField);
EditText itemToBurnText = (EditText) findViewById(R.id.itemToBurnTextField);
String appName = applicantNameText.getText().toString();
String appItemToBurn = itemToBurnText.getText().toString();
if (appItemToBurn.isEmpty() || appName.isEmpty()) {
Toast.makeText(BookingScreen.this, "Please fill in all fields.", Toast.LENGTH_SHORT).show();
}
else {
sendApplication.storeApplication(appName, appItemToBurn);
this.finish();
}
}
Run Code Online (Sandbox Code Playgroud)
ArrayList方法:
public void storeApplication(String name, String item){
ArrayList<Application> peopleAttending = new ArrayList<>(10);
peopleAttending.add(new Application(name, item));
}
Run Code Online (Sandbox Code Playgroud) 我正在从 sql 数据库中获取数据,然后以图表的形式显示这些数据。我正在制作的图表基于时间的数据。我想摆脱秒,因为它对我的应用程序无用并且占用空间。
我尝试使用日历对象从其中删除秒数,如下所示:
ArrayList<Time> ints3 = new ArrayList<Time>();
while ( rs.next() ){
ints3.add(rs.getTime(ints.get(0)));
}
Calendar instance = Calendar.getInstance();
instance.setTime(ints3.get(1));
instance.clear(Calendar.SECOND);
ints3.set(1, (Time) instance.getTime());
Run Code Online (Sandbox Code Playgroud)
但是这不起作用,因为您不能将 java.util 日期转换为 sql 时间。我该如何去除部分时间的秒数。
我在互联网的某个地方得到了这个脚本,它应该做的是将文本加密到md5并显示结果(我认为)我是Java的新手,只能做一些php和python.我设置了JDK,所以我可以在cmd中运行它.我输入的是> javac MD5.java然后它运行代码并且C:\ file>再次显示,好像什么也没发生.它没有打印出我的哈希有没有人知道为什么?
import java.io.FileInputStream;
import java.io.UnsupportedEncodingException;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public class MD5 {
public static String getMD5(String input) {
byte[] source;
try {
//Get byte according by specified coding.
source = input.getBytes("UTF-8");
} catch (UnsupportedEncodingException e) {
source = input.getBytes();
}
String result = null;
char hexDigits[] = {'0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
try {
MessageDigest md = MessageDigest.getInstance("MD5");
md.update(source);
//The result should be …Run Code Online (Sandbox Code Playgroud) 我的任务是制作一个程序,允许用户输入他们的出生日期,它将输出他们的中国十二生肖动物和他们的星座.该程序认为月份是未声明的变量,但我试图使它们成为变量"月"的值.
这是代码,
int day, year;
String month;
System.out.println("Enter the month you were born.");
month=in.nextLine();
System.out.println("Enter day you were born.");
day=in.nextInt();
System.out.println("Enter the year you were born.");
year=in.nextInt();
if (month==January && day <=20)
System.out.println("You are a Capricorn.");
if (month==January && day > 20)
System.out.println ("You are an Aquarius.");
if (month==February && day <= 19)
System.out.println ("You are an Aquarius.");
if (month==February && day >19)
System.out.println ("You are a Pisces.");
if (month==March && day <= 20)
System.out.println ("You are a Pisces.");
if …Run Code Online (Sandbox Code Playgroud) 这是一个读取整数的程序:
public static void main(String argv[]) {
Scanner input = new Scanner(System.in);
int x = input.nextInt();
System.out.println(x);
}
Run Code Online (Sandbox Code Playgroud)
但是,如果我输入这样的输入:000114它将被读取为114.How to read integer 从零开始?
我有一个名为Person with properties的模型
name
image
age
amount
Run Code Online (Sandbox Code Playgroud)
我有一个Hashmap<String,Person> globalPersonList包含人物对象列表的单例哈希映射.
我试图从我的hashmap中检索一个单个对象
Person existingPerson = globalPersonList.get("key");
Run Code Online (Sandbox Code Playgroud)
我想Person用existingPerson类似的属性创建一个新实例并初始化
Person person = new Person();
person = globalPersonList.get("key");
Run Code Online (Sandbox Code Playgroud)
现在我想将amount字段设置为此person对象.我尝试过
newPerson.setAmount(100);
Run Code Online (Sandbox Code Playgroud)
但它不应该影响globalPersonList.我只想在我的newPerson对象中使用金额值.但是现在globalPersonList也是如此.设定金额后,如果我尝试
globalPersonList.get("key").getAmount()
Run Code Online (Sandbox Code Playgroud)
它给出了我设定的金额.它是否使用对新对象的引用?我想要一个Person对象的单独副本,这样它就不会影响主hashmap.
在我的家庭作业活动中,它要求我根据以下说明编写代码:
一组数字的标准差是衡量其价值差异的指标.它被定义为每个数字和平均值之间的平方差的平均值的平方根.要计算存储在数据中的数字的标准差:
计算数字的平均值.
对于每个数字,从平均值中减去它并将结果平方.
找到步骤2中计算的数字的平均值.
找到步骤3结果的平方根.这是标准偏差.
编写代码来计算数据中数字的标准差,并将结果存储在double sd中.
示例:double [] data = {1.0,2.0,3.0,4.0,5.0};
//预期标准偏差(输出):1.4142136
//My code:
double mean1=0;
double mean2=0;
double sum1=0;
double sum2=0;
double sd=0;
//calculate sum from arrays of doubles
for(double a:data)
{
sum1+=a;
}
//calculate mean
mean1=sum1/data.length;
//creates new array for step2
double newData[]=new double[data.length];
for(int k= 0; k>newData.length; k++)
{
double s=0;
newData[k]=data[k];
s=Math.pow((mean1-data[k]),2);
newData[k]=s;
}
//calculate sum of the new array
for(double b:newData)
{
sum2+=b;
}
//calculate mean
mean2=sum2/newData.length;
//calculate standard deviation by sqrt
sd+=Math.sqrt(mean2); …Run Code Online (Sandbox Code Playgroud) 我正在使用JDBC ResultSet从数据库中获取记录.但
ResultSet.getFloat() //returns 0 for NULL value.
Run Code Online (Sandbox Code Playgroud)
有没有办法获得null价值使用getFloat()或替代解决方案?