java - I need help making a java constructor that akes a string and initilizes the value var with appropriate in
问题描述
so sorry if my question is dumb but i haven't done java in 2 years. I'm working in my hw right now and i'm one method away from being done. but one of my constructor is wrong and idk where. thanks in advance! the value variable is a private integer. so far i have:
public FancyInt(String a) {
value = "";
a = this.value;
}
basically this constructor takes a string and initalizes the value to the appropriate int
解决方案
首先,如果你想将“值”等于“a”,你必须写:
this.value = a;
在 Java(和许多编程语言)中,您必须编写在等号之前更改的变量。
其次,如果您将“值”设为整数。您必须先将其更改为 int:
try {
this.value = Integer.parseInt(a);
} catch (NumberFormatException e) {
e.printStackTrace();
}
第三,如果“值”是一个整数。您必须用数字定义:
value = ""; //if value is an Integer, delete this line.
推荐阅读
- javascript - jsReports 资产 nodejs
- python - Azure databricks - count() 方法的空数据框抛出错误
- node.js - 仅限一位用户使用 API 端点
- r - 如何绘制具有 x 轴非数字的三个变量的条形图?
- reactjs - 如何在 React 上复制它?
- javascript - Next.js 从根目录导入:使用斜线开始导入是否有效?
- angular - HTTP PUT 正在创建而不是在 Angular 应用程序中更新
- javascript - 提交后无法清除输入 - 反应
- python - 如何使用python修复flask-restfull中的typeError
- azure - 通过使用 Azure AD 的代表流来限制用户范围