该方法不返回局部变量的值.
我可以使用以下方法中的局部变量索引的值
public boolean contains(Object input) {
int index = 0;
while(myAsetIterator.hasNext()) {
index++;
if(input.equals(myAsetIterator.next())) {
return true;
}
}
return false;
}
Run Code Online (Sandbox Code Playgroud)
在此方法中作为我要删除的对象的数组的索引.
public boolean remove(Object o) {
int count = 0;
if(o == null) {
return false;
}
if(contains(o)) {
genArray[index] == null;
}
if (count > 0) {
System.out.println(count+" same elements were present in Aset. "
+ "Removed all those "+count+" elements from Aset.");
return true;
}
return false;
}
Run Code Online (Sandbox Code Playgroud)
我知道局部变量的范围仅限于它声明的方法.但是,如果不使用字段/实例变量,我可能还有一种方法可能无法实现.我不是那么擅长编程,但我绝对不知道大师们提供的所有小技巧和技巧.值得一试.谢谢你的时间.
对不起,如果这是一个非常明显的事情,但这是我在javascript处理导出模块的第一个任务node.js.
我有两个文件:1)ADT.js和2)main.js.我想一些职能出口ADT.js到main.js
这是代码ADT.js:
module.exports = {};
var exports = module.exports;
var wordCount = function(text) {
var data = readFile(text);
if(checkEmptyFile(data)){
return null;
} else {
// do something
}
};
//==================== Helper Functions ==================================
function readFile (file){
var fs = require('fs');
var data = fs.readFileSync(file, "utf8");
return data;
}
function checkEmptyFile(data){
if(data.replace(/\s+/, '') === ''){
return true;
}
}
/** adding the functions to the exports module …Run Code Online (Sandbox Code Playgroud)