小编Vui*_*inh的帖子

如何缩短多重&&条件

目前我可以运行我的程序,但我的代码包含很多重复,看起来像:

while(option != 'E' && option != 'D' && option != 'P' && option != 'Q' &&
      option != 'e' && option != 'd' && option != 'p' && option != 'q') {
  // Some code here
}
Run Code Online (Sandbox Code Playgroud)

要么:

while(cType != 'S' && cType != 'L' && cType != 'O' && cType != 'Q' &&
      cType != 's' && cType != 'l' && cType != 'o' && cType != 'q') {
  // Some code here
}
Run Code Online (Sandbox Code Playgroud)

缩短上述代码的最快方法是什么?

(除了使用附加功能有什么办法吗?)

c c++ algorithm optimization conditional

11
推荐指数
1
解决办法
359
查看次数

如何创建属于接口的实例并实现它

我正在学习Java,所以请忍受我的无知.这是我目前的代码

Shape.java

public interface Shape {
    public abstract void draw();
}
Run Code Online (Sandbox Code Playgroud)

Rectangle.java

public abstract class Rectangle implements Shape {

    private final double width, length;

    public Rectangle() {
        this(1,1);
    }
    public Rectangle(double width, double length) {
        this.width = width;
        this.length = length;
    }

    public void draw() {
        System.out.println("A rectangle of sides " +  length + " by " + width + " will be drawn");
    }

}
Run Code Online (Sandbox Code Playgroud)

TestPolymorph.java

public class TestPolymorph implements Shape {

    public static void main(String[] args) {
        Shape[] …
Run Code Online (Sandbox Code Playgroud)

java polymorphism inheritance

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

如何将递归转换为迭代解决方案

我已经设法以递归方式编写我的算法:

int fib(int n) {
    if(n == 1)
        return 3
    elseif (n == 2)
        return 2
    else
        return fib(n – 2) + fib(n – 1)
}
Run Code Online (Sandbox Code Playgroud)

目前我正在尝试将其转换为迭代方法而没有成功:

int fib(int n) {
   int i = 0, j = 1, k, t;
   for (k = 1; k <= n; ++k)
   {
       if(n == 1) {
           j = 3;
       }
       else if(n == 2) {
           j = 2;
       }
       else {
           t = i + j;
           i = j;
           j = t;
       } …
Run Code Online (Sandbox Code Playgroud)

c c++ algorithm recursion fibonacci

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

为什么这个CSS过渡速记不再起作用?

我的基本工作示例代码:

div {
    width: 100px;
    height: 100px;
    background: red;
    -webkit-transition: all 0.25s ease 0s;
    -moz-transition: all 0.25s ease 0s;
    transition: all 0.25s ease 0s;
}
Run Code Online (Sandbox Code Playgroud)

演示

如果我删除0转换前的持续时间并且s在转换延迟之后,则它不起作用:

div {
    width: 100px;
    height: 100px;
    background: red;
    -webkit-transition: all .25s ease 0;
    -moz-transition: all .25s ease 0;
    transition: all .25s ease 0;
}
Run Code Online (Sandbox Code Playgroud)

我问这个问题,因为我的转换正在使用后一个代码,但突然Chrome给了我错误"未知属性名称",我需要将其更改为以前的版本,以使我的转换再次工作.我怎么能解决这个问题,因为我有很多第二种格式的代码.

css google-chrome css3 css-transitions

-3
推荐指数
1
解决办法
454
查看次数