try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
Object[] test = Arrays.stream(br.readLine().split(" ")).map(string -> Integer.parseInt(string)).toArray();
System.out.println(Arrays.toString(test));
} catch (IOException E) {
}
Run Code Online (Sandbox Code Playgroud)
所以这段代码可以工作,但它返回一个类型的数组Object[]
但是,我想要的是让它返回一个类型的数组int[].
有没有人知道如何才能做到这一点?
所以这段代码完美无缺
var arr = [1, 2, 3, 4];
arr.forEach(function (el) {
console.log(el);
})
Run Code Online (Sandbox Code Playgroud)
但如果我尝试这样做:
function printArgsInfo() {
arguments.forEach(function (el) {
console.log(el);
});
}
printArgsInfo(2, 3, 2.5, -110.5564, false);
Run Code Online (Sandbox Code Playgroud)
参数.forEach不是函数即使tought参数是一个数组,如果尝试用forin循环执行它仍然有效.
var hello = 'hello';
Array.prototype.unshift.call(hello, '11') // gives error
Array.prototype.join.call(hello, ', ') // works, why??
Run Code Online (Sandbox Code Playgroud)
有人可以向我解释为什么.join有效,为什么.unshift无效
我是新的反应,我想知道这是否是从输入表单获取值的正确方法(有点质量代码).从'react'导入React;
class Form extends React.Component {
constructor() {
super();
this.state = {
nameValue: '',
ageValue: ''
}
}
onChangeName(event) {
this.setState({
nameValue:event.target.value
});
}
onChangeAge(event) {
this.setState({
ageValue: event.target.value
});
}
showValue(){
alert('name '+ this.state.nameValue + ' age: ' + this.state.ageValue)
}
render() {
return (
<form>
<label>Name:
<input type="text" onChange={this.onChangeName.bind(this)}/>
</label>
<label>Age:
<input type="text" onChange={this.onChangeAge.bind(this)}/>
</label>
<input type="submit" value="Submit" onClick={this.showValue.bind(this)}/>
</form>
);
}
}
export default Form;
Run Code Online (Sandbox Code Playgroud)
我的意思是我听说它做出反应的方式是这样的,每个组件都应该有点独立,并且有自己的行为.顺便说一句代码的工作原理只是要求我从中获得项目的质量.或者我应该只是向按钮添加一个事件并使其他组件无状态,即2个输入字段
HashMap<String, Double> missions = new HashMap<>();
missions.put("name", 1.0);
missions.put("name1", 2.0);
missions.keySet().stream().forEach(el-> System.out.println(el));
Run Code Online (Sandbox Code Playgroud)
仅打印键
select town_id,name from `soft_uni`.towns
where name like 'b%' or 'm%' or 'k%' or 'e%'
Run Code Online (Sandbox Code Playgroud)
我想找到所有以b或m或k或e开头的名字,但是它们只适用于以b开头的城镇