目前我可以运行我的程序,但我的代码包含很多重复,看起来像:
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)
缩短上述代码的最快方法是什么?
(除了使用附加功能有什么办法吗?)
我正在学习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) 我已经设法以递归方式编写我的算法:
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) 我的基本工作示例代码:
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给了我错误"未知属性名称",我需要将其更改为以前的版本,以使我的转换再次工作.我怎么能解决这个问题,因为我有很多第二种格式的代码.
algorithm ×2
c ×2
c++ ×2
conditional ×1
css ×1
css3 ×1
fibonacci ×1
inheritance ×1
java ×1
optimization ×1
polymorphism ×1
recursion ×1