在shell脚本方面,我仍然是一个ROOKIE.长话短说我试着每次迭代将数组的值递增一.这是我的代码
cmd=(1 2 3 4 5 6 7 8 ................) // How can I pass numbers 1 to 1000 with out having to type manually.
${cmd[@]}
for (( i = 0 ; i < ${#cmd[@]} ; i++ )) do
echo ${cmd[$i]}"
done
Run Code Online (Sandbox Code Playgroud)
一种方法是cmd =()然后在循环内部我们添加"let cmd [i] ++"这一行,但它对我没用.提前致谢
使用此代码:
public static void main(String[] args) {
String s = "Java";
StringBuilder buffer = new StringBuilder(s);
change(buffer);
System.out.println("What's strBuf.charAt(5)? " + strBuf.charAt(3));
System.out.println(buffer);
}
private static void change(StringBuilder buffer) {
buffer.append(" and HTML");
}
Run Code Online (Sandbox Code Playgroud)
当我使用 StringBuilder 运行代码时,我收到错误消息
The constructor StringBuilder(String) is undefined
The method charAt(int) is undefined for the type StringBuilder
Run Code Online (Sandbox Code Playgroud)
改为尝试 StringBuffer 并且它有效。StringBuffer 对象的内容被编译为“Java 和 Eclipse..”
public static void main(String[] args) {
String s = "Java";
StringBuffer strbuf = new StringBuffer(s);
change(strbuf);
System.out.println("The Stringbuffer.charAt(5) is ? " + strbuf.charAt(3)); …Run Code Online (Sandbox Code Playgroud) 对于这个问题,我编写了一个代码,在数组中找到重复项并将其打印出来.最初,我使用了时间复杂度为0(n ^ 2)的嵌套循环.为了更高效的0(n)解决方案,我编写了下面的代码,并希望得到一些帮助/见解如何找出是否有任何元素及其.Next()保持相同的值"Duplicates",如果是这样,打印它们出.
public class FindDuplicates {
public static void main(String arg[]){
int[] str={1 , 2 , 3 ,4 ,5 ,3 ,5 , 4,3,43,1,33,4,5};
List<Integer> list = new LinkedList<Integer>();
for(int x : str) {
list.add(x);
}
Collections.sort(list);
System.out.println(list);
Iterator<Integer> it = list.listIterator();
while(it.hasNext() && it.next() != null) {
/* Pseudocode => if(it.next().equals(it.next.next)); */
/* OR Pseudocode => if(it.next() == it.next().next) */
System.out.println(it) ;
}
}
}
Run Code Online (Sandbox Code Playgroud) 此脚本从下载的网页中删除网址.我在使用这个脚本时遇到了一些麻烦 - 当我使用它"my $csv_html_line = @_ ;"
然后打印出来时"@html_LineArray"- 它只是打印出来"1's".当我更换
"my $csv_html_line = @_ ;"使用"my $csv_html_line = shift ;"脚本工作正常.我不知道有什么不同之处"= @_" and shift- 因为我认为没有具体说明,在子程序中,转移从"@_".
#!/usr/bin/perl
use warnings;
use strict ;
sub find_url {
my $csv_html_line = @_ ;
#my $csv_html_line = shift ;
my @html_LineArray = split("," , $csv_html_line ) ;
print "@html_LineArray\n" ;
#foreach my $split_line(@html_LineArray) {
# if ($split_line =~ m/"adUrl":"(http:.*)"/) {
# my $url = $1;
# $url …Run Code Online (Sandbox Code Playgroud)