小编ngu*_*a02的帖子

新的Java程序员,基本的java组成

我是一名新的计算机编程学生.我观看了一个关于Java的视频,基本构图,视频中的人就此主题做了一个例子,如下所示:

public class PaperTray
{
  int pages = 0;
  ....
  public boolean isEmpty()
  {
    return pages > 0;
  }
}
Run Code Online (Sandbox Code Playgroud)
public class Printer extends Machine
{
  private PaperTray paperTray = new PaperTray();
  ....
  public void print(int copies)
  {
  ....
  while(copies > 0 && !paperTray.isEmpty() )
  {
    System.out.println("some text to print");
    copies--;
  }
  if(paperTray.isEmpty())
  {
    System.out.println("load paper");
  }
}
Run Code Online (Sandbox Code Playgroud)

我的问题是如果纸盘是空的,那么在PaperTray类中,方法isEmpty()将返回false.因此,将不会执行类Printer中的if语句.如果纸盘不为空,则PaperTray类中的方法isEmpty()将返回true,因此不会执行类Printer中的while语句.我错了,或者视频剪辑中的讲师犯了一些错误?

谢谢

java composition

5
推荐指数
2
解决办法
312
查看次数

AngularFire $ add操作导致浏览器冻结

我正在使用angularjs学习Firebase.从本教程https://thinkster.io/tutorials/angularfire-realtime-slack-clone/creating-the-channels-sidebar,用于添加新聊天室的代码是这样的

channels.$add(vm.newRoom).then(function (ref) {
Run Code Online (Sandbox Code Playgroud)

但是,当我运行应用程序时,这个$ add操作成功地在firebase表中添加了一条新记录,但它也导致整个浏览器冻结.

Angular版本:1.6.2 Firebase:3.7.1 AngularFire:2.1.0

angularjs firebase

5
推荐指数
1
解决办法
270
查看次数

fork()在C++学习os开发

我正在学习使用C/C++进行OS开发,我正在使用fork()方法来试验过程.我有以下代码:

#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv) {
    fork(); //create a child process, currently total is 1 parent, 1 child
    fork(); //create a child process,currently total is 2 parents, 2 child
    pid_t pid;
    if((pid=fork()) == 0) { //fork() and assign to pid, now has 4 parents, 4 childs
        printf("I am the child: %u\n", getpid());
    else {
        printf("I am the parent: %u and my child is: %u\n", getpid(), pid);
    }
}
Run Code Online (Sandbox Code Playgroud)

当我编译它并运行它时,它显示了4个父母和4个孩子,正如我所料,但是输出看起来很奇怪(请注意下面的粗体线,我得到用户@ slacker之后的输出:〜$).

user @ slacker:〜$ …

c++ operating-system

2
推荐指数
1
解决办法
236
查看次数

为什么Ansi_nulls不起作用?

假设我有两个名为aTable1,aTable2的表

aTable1将userID设置为identity并包含以下数据:

userID  email          FirstName    LastName
1       NULL               C            CC
2       NULL               D            DD
3       a@yahoo.com        A            AA
4       b@yahoo.com        B            BB
5       e@yahoo.com        E            EE
6       f@yahoo.com        NULL         NULL
7       g@yahoo.com        NULL         NULL
Run Code Online (Sandbox Code Playgroud)

aTable2包含以下数据:

userID  email          FirstName    LastName    Title
3       a@yahoo.com      A            AA       student
4       b@yahoo.com      B            BB       student
5       e@yahoo.com      E            EE       student
NULL    NULL             C            CC       dean
NULL    NULL             D            DD       advisor
NULL    f@yahoo.com NULL    NULL               student2
NULL    g@yahoo.com NULL    NULL               student3
Run Code Online (Sandbox Code Playgroud)

我想基于aTable1更新aTable2.userID,但知道2个表中有空值,所以我喜欢这样:

set ANSI_NULLS off
update …
Run Code Online (Sandbox Code Playgroud)

sql sql-server

0
推荐指数
1
解决办法
204
查看次数