我当前的类SeriesCircuit
class包含两个构造函数:
public SeriesCircuit(Circuit input1, Circuit input2)
{
this.circuit1 = input1;
this.circuit2 = input2;
}
public SeriesCircuit(ParallelCircuit parallelCircuit, Circuit circuit1)
{
this.parallelCircuit = parallelCircuit;
this.circuit1 = circuit1;
}
Run Code Online (Sandbox Code Playgroud)
使用该.toString()
方法,我可以打印出第一个构造函数的值:
public String toString()
{
return circuit1.getResistance() + " + " + circuit2.getResistance();
}
Run Code Online (Sandbox Code Playgroud)
注意:.getResistance()
get 返回的值只是双倍,所以示例输出就像这个字符串:2.0 + 3.0
.
我的问题是,由于我有两个提供两种不同输入类型的构造函数,我如何只覆盖一个.toString()
以输出两种不同类型的构造函数输入?
例如,在我的主要内容中,我这样做:
SeriesCircuit s1 = new SeriesCircuit(new Circuit(2.0), new Circuit(3.0));
SeriesCircuit s2 = new SeriesCircuit(new ParallelCircuit(s1, new Circuit(4.0)), new Circuit(1.0));
我可以s1
使用System.out.println(s1)
很好的打印出来,但是由于我从未 …
我正在做一些自我学习的C练习,并遇到了以下问题:
第一部分:
int main(int argc, char **argv) {
int a = 5, b = 8;
int v;
v = fork();
if(v == 0) {
// 10
a = a + 5;
// 10
b = b + 2;
exit(0);
}
// Parent code
wait(NULL);
printf("Value of v is %d.\n", v); // line a
printf("Sum is %d.\n", a + b); // line b
exit(0);
}
Run Code Online (Sandbox Code Playgroud)
b部分:
int main(int argc, char **argv) {
int a = 5, b = 8;
int v; …
Run Code Online (Sandbox Code Playgroud) 我得到了一些类似于Bootstrap复选框的HTML.默认情况下,该复选框已打开.
<div id="full" class="checkbox">
<label>
<input type="checkbox" checked=""> Include Full Classes
</label>
</div>
Run Code Online (Sandbox Code Playgroud)
我有这个jQuery,它检测项目是否被选中或未被检查
var full;
$('#full').change(function(){
if(this.checked)
{
full = true;
console.log(full);
} else {
full = false;
console.log(full);
}
});
Run Code Online (Sandbox Code Playgroud)
我想要实现的是,当选中该复选框时,它将设置full
为1,如果未选中,则设置full
为0.
我执行console.log()
了full
变量,在我的输出中,我得到的只是false
.
我想知道我做错了什么?
这是线程我引用
我有一个全局变量叫myDataset
:
var myDataset = {
"classes":[
[
{
"name":"ECEC 301 Advanced Programming for Engineers Lecture",
"days":"MWF",
"times":"02:00 pm - 03:20 pm",
"crn":"11215"
},
{
"name":"ECEC 301 Advanced Programming for Engineers Lab",
"days":"W",
"times":"09:00 am - 10:50 am",
"crn":"11216"
}
],
[
{
"name":"ECEC 301 Advanced Programming for Engineers Lecture",
"days":"MWF",
"times":"02:00 pm - 03:20 pm",
"crn":"11215"
},
{
"name":"ECEC 301 Advanced Programming for Engineers Lab",
"days":"F",
"times":"02:00 pm - 03:50 pm",
"crn":"11217"
}
]
]
};
Run Code Online (Sandbox Code Playgroud)
在这之下,我初始化我的fullCalendar …
我目前有以下方法
public void printTitle(string title){
// settings for stringformat
g.DrawString(title, drawFontTitle, Brushes.White, x, y, stringFormatTitle);
}
Run Code Online (Sandbox Code Playgroud)
但是,我试图让输入定义标题的颜色,如下所示:
public void printTitle(string title, Brushes titleColor){
// settings for stringformat
g.DrawString(title, drawFontTitle, titleColor, x, y, stringFormatTitle);
}
Run Code Online (Sandbox Code Playgroud)
它会像这样使用:
printTitle("Title Text", Brushes.White);
Brushes titleColor
但是,我认为在声明导致错误时存在问题。
我试图找到一个子O(n)
方法来计算整数数组的总和~~~(而不是迭代0 - n
,我正在做n/2
)~~~ 我仍然在O(n)中做它.
public static int sum(int[] s) {
int length = s.length - 1;
int half = length/2;
int sum = 0;
for(int i = 0; i <= half; i++) {
System.out.println(i + " " + s[i] + " + " + s[length - i]);
sum += s[i] + s[length - i];
}
return sum;
}
Run Code Online (Sandbox Code Playgroud)
我的算法适用于偶数个整数,但是,当有奇数个整数时,它会将中间索引加两次:
测试:
int[] arr = {1, 2, 3, 4, 5};
System.out.println(sum(arr));
Run Code Online (Sandbox Code Playgroud)
输出:
0 1 + …
Run Code Online (Sandbox Code Playgroud) 我正在尝试编写一个返回计算机MAC地址字符串的静态方法(函数本身在这里找到:http://www.mkyong.com/java/how-to-get-mac-address-in-java /).我遇到return
了静态功能方面的问题.我得到的错误是missing return statement
.我该如何解决这个问题?
static String returnMacAddress(){
InetAddress ip;
try{
ip = InetAddress.getLocalHost();
NetworkInterface network = NetworkInterface.getByInetAddress(ip);
byte[] mac = network.getHardwareAddress();
System.out.print("Current MAC address: ");
StringBuilder stringBuilder = new StringBuilder();
for(int i = 0; i < mac.length; i++){
stringBuilder.append(String.format("%02X%s", mac[i], (i < mac.length - 1) ? "-" : ""));
}
return stringBuilder.toString();
}catch(UnknownHostException e){
e.printStackTrace();
} catch(SocketException e){
e.printStackTrace();
}
}
Run Code Online (Sandbox Code Playgroud) 我有一个没有分成<>格式的xml架构,只是文本框中的架构,<>和<>之间没有分离.
例:
<Cmp><Id>"Value"</Id><fecha_cbte>"Value"</fecha_cbte><Tipo_cbte>"Value"</Tipo_cbte><Punto_vta>"Value"</Punto_vta><Cbte_nro>"Value"</Cbte_nro><Tipo_expo>"Value"</Tipo_expo><Permiso_existente>"Value"</Permiso_existe>
等等.所以你可以看到一切都"加入",没有分离.
我的想法是将所有内容作为单个和长字符加入,之后我的dea将使用a
for (int i=0; i < myVariable.Count; i++)
{
if (myVariable == ">" && myVariable == "<")
{
//Here I can split the string with /n everytime it finds a > and <
}
}
Run Code Online (Sandbox Code Playgroud)
所以最后它应该是这样的:
<Cmp>
<Id>
"Value"
</Id>
<fecha_cbte>
"Value"
</fecha_cbte>
<Tipo_cbte>
"Value"
等等...
所以我可以将'<'''与数值分开.
任何想法或建议?
最好的祝福!