我在网页上有一个给定的文本块,我想使用javascript和JQuery使它看起来像法国国旗(蓝/白/红).
现在我尝试了以下代码:JSFiddle
或者,如果您更喜欢Stackoverflow片段:
jQuery(function ($) {
// Calculates the text width in <p>
var html_cur = $('.loremipsum').html();
var html_calc = '<span>' + html_cur + '</span>';
$('.loremipsum').html(html_calc);
var width = $('.loremipsum').find('span:first').width();
var color_width = Math.floor(width / 3), // Width of each color
text = $( ".loremipsum" ).text(), // Text of <p>
array = [], // Array containing each sentences
sentence = '', // Current sentence
sentence_width = 0; // Current sentence width
for(var i = 0; i < text.length; i++) …Run Code Online (Sandbox Code Playgroud)现在我有这个Java代码
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;
public class Dummy {
private String value;
public Dummy(final String value) {
this.value = value;
}
public boolean equals(final Object that) {
return that instanceof Dummy && Objects.equals(value, ((Dummy) that).value);
}
public int hashcode() {
return Objects.hash(value);
}
public static void main(final String... args) {
final Set<Dummy> dummies = new HashSet<>();
dummies.add(new Dummy("toto"));
System.out.println(dummies.contains(new Dummy("toto")));
}
}
Run Code Online (Sandbox Code Playgroud)
输出是"假的",我应该通过只更改一个字符将其更改为"true",但我完全不知道如何做到这一点......任何想法?谢谢.:)