我得到以下代码:
int nnames;
String names[];
System.out.print("How many names are you going to save: ");
Scanner in = new Scanner(System.in);
nnames = in.nextInt();
names = new String[nnames];
for (int i = 0; i < names.length; i++){
System.out.print("Type a name: ");
names[i] = in.nextLine();
}
Run Code Online (Sandbox Code Playgroud)
该代码的输出如下:
How many names are you going to save:3
Type a name: Type a name: John Doe
Type a name: John Lennon
Run Code Online (Sandbox Code Playgroud)
注意它是如何跳过第一个名字的?它跳过它并直接进入第二个名称输入.我试过看是什么导致了这个,但我似乎无法指出它.我希望有一个人可以帮助我.谢谢
学习Go几个月后,我发现通过实现该功能来os.File实现io.Reader接口Read(b []byte) (n int, err error).这允许我使用缓冲的阅读器来读取文件,例如:
f, err := os.Open("myfile.txt")
bufReader := bufio.NewReader(f)
Run Code Online (Sandbox Code Playgroud)
除非我错过它,看起来在接口上的Go文档中没有"所有已知的实现类",就像在Java接口文档中找到的那样.
有没有办法识别在Go中实现接口的类型?
我正在使用Rails 4跟踪敏捷Web开发.章节购物车9购物车创建.当我想更新购物车时,我收到以下错误通知:分配属性时,必须将散列作为参数传递.CartController#更新.
class CartsController < ApplicationController
include CurrentCart
before_action :set_cart, only: [:show, :edit, :update, :destroy]
rescue_from ActiveRecord::RecordNotFound, with: :invalid_cart
def index
@carts = Cart.all
end
def show
end
def new
@cart = Cart.new
end
def edit
end
def create
@cart = Cart.new(cart_params)
respond_to do |format|
if @cart.save
format.html { redirect_to @cart, notice: 'Cart was successfully created.' }
format.json { render :show, status: :created, location: @cart }
else
format.html { render :new }
format.json { render json: @cart.errors, status: :unprocessable_entity } …Run Code Online (Sandbox Code Playgroud) 我写了这个查询来在hive上创建一个表.我的数据最初是json格式,所以我已经下载并构建serde并添加了运行所需的所有jar.但我收到以下错误:
FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask. Cannot validate serde: org.openx.data.jsonserde.JsonSerDe
Run Code Online (Sandbox Code Playgroud)
查询:
create table tip(type string,
text string,
business_id string,
user_id string,
date date,
likes int)
ROW FORMAT SERDE 'org.openx.data.jsonserde.JsonSerDe'
WITH SERDEPROPERTIES("date.mapping"="date")
STORED AS TEXTFILE;
Run Code Online (Sandbox Code Playgroud) 我错误地将更改推送到远程主分支。所以为了保证它们的安全,我创建了一个backup分支。然后我恢复了我对远程主机所做的更改。
在我本地的 master 分支上,我跑了:
git revert <commit_sha>
Run Code Online (Sandbox Code Playgroud)
进而
推
我现在已经完成了新分支(备份)的工作,看起来一切都很好。但是我无法将更改从本地backup分支推送到远程主节点。当我git pull在我的备份分支上运行时,我所做的更改丢失了。代码替换为远程主站的内容。
有没有办法将我的更改推送到远程 master 分支而不会丢失我的工作?
我是通过命令行git的新手,遇到了一些麻烦我无法摆脱困境.
我在我的服务器上设置了一个存储库,并使用thelucid.com上的指示创建了一个本地目录.
在服务器上:
ssh git@example.com
mkdir my_project.git
cd my_project.git
git init --bare
git update-server-info # If planning to serve via HTTP
exit
Run Code Online (Sandbox Code Playgroud)
然后,在本地机器上:
cd my_project
git init
git add *
git commit -m "My initial commit message"
git remote add origin git@example.com:my_project.git
git push -u origin master
Run Code Online (Sandbox Code Playgroud)
当我在这里找到最后一个命令"git push -u origin master"时,命令会挂起并挂起,并且永远不会停止挂起.
本地的git状态给了我这个:
$ git status
On branch master
nothing to commit, working directory clean
Run Code Online (Sandbox Code Playgroud)
服务器上的git状态(在myproject.git /中)给了我:
$ git status
fatal: This operation must be run in a …Run Code Online (Sandbox Code Playgroud) 我有两个表叫op_group和options.这些两个表由数组值填补.例如,我想在我的表中插入披萨细节.
它看起来像这样:
op_group餐桌.options表中.应根据相关的外键op_groupid 插入这些选项.
这就是我尝试过的.插入所有细节但不是相关的op_group.
$opg_name=$_POST['opg_name'];
$price=$_POST['price'];
$itemCountz = count($opg_name);
$itemValues=0;
$queryValue1 = "";
for($i=0; $i<$itemCountz; $i++) {
$itemValues++;
if($queryValue1!="") {
$queryValue1 .= ",";
}
$queryValue1 = "INSERT INTO op_group
(opg_id,ml_id,cat_id,res_id,res_name,op_grp)
VALUES(NULL,'".$ml_id."','".$cat_id."','".$res_id."','".$res_name."','".$_POST["opg_name"][$i]."')";
$result1= mysql_query($queryValue1)or die(mysql_error());
$query6= "SELECT * FROM op_group ORDER BY opg_id DESC LIMIT 1" ;
$result6= mysql_query($query6);
while($row6 = mysql_fetch_assoc($result6)){
$opg_id=$row6['opg_id'];
}
$itemCount2 = count($price);
$itemValues1 = 0;
$queryValue2 = "";
for($j=0;$j<$itemCount2;$j++) {
if(!empty($_POST["op_name"][$j])||!empty($_POST["price"][$j])) { …Run Code Online (Sandbox Code Playgroud) 如何在一个位置(如类)定义所有命名查询,而不是在Entity类的顶部编写NamedQuery .
例如,我有一个基类.在这个类中,我可以定义所有命名查询.
Base.java
@Entity
@NamedQueries({
@NamedQuery(name="Student.findAll", query="SELECT s FROM Student s"),
@NamedQuery(name="Employee.findAll", query="SELECT e FROM Employee e")})
class Base {
}
Run Code Online (Sandbox Code Playgroud)
假设我现在有两个实体,如学生和员工.现在我想从Base类访问Named查询.可以访问.如果可能那么如何.
class Employee {
}
class Student {
}
Run Code Online (Sandbox Code Playgroud)
在employee类中,Student我想从Base类访问命名查询.有可能的.如果有可能我可以访问.
我有以下问题:当我启动我的应用程序时,设置从文件加载,所以反序列化,当发生这种情况时,我收到以下错误:
{"End of Stream encountered before parsing was completed."} System.Exception {System.Runtime.Serialization.SerializationException}
序列化代码:
using(FileStream write = new FileStream(SETTINGSPATH,FileMode.Create,FileAccess.Write)
{
BinaryFormatter formatter = new BinaryFormatter();
formatter.Serialize(write,settings);
}
Run Code Online (Sandbox Code Playgroud)
反序列化方法:
using (FileStream read = new FileStream(SETTINGSPATH,FileMode.Open,FileAccess.Read))
{
BinaryFormatter formatter = new BinaryFormatter();
read.Position = 0;
settings = (Settings)formatter.Deserialize(read); // settings is declared as Settings object
}
Run Code Online (Sandbox Code Playgroud)
设置类:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
namespace Serie_Counter.Overkoepelend
{
public delegate void SelectedMoveOptionChanged(AutoMoveOption selectedOption, int checkInterval = 30 );
public delegate void EnableAutoMoveChanged(bool …Run Code Online (Sandbox Code Playgroud)