df['cum_sum'] = df.val1.cumsum()
df['CumSumWithGrowth'] = .10*df[‘cum_sum’] + df[‘cum_sum’]
输出正确无误,但下面有新行。我将如何做到这一点,以便最后没有新行?
public class Prac
{
public static void main (String[] args)
{
for (int line = 7; line >= 1; line = line - 2)
{
for(int stars = 1; stars < line; stars++)
{
System.out.print("*");
}
System.out.println();
}
}
}
答案 0 :(得分:0)
循环的最后一次迭代是在line = 1时。那时,没有星星打印出来,但是您的System.out.println();
打印换行符。解决此问题的一种方法是删除System.out.println();
并将其放在System.out.print("*");
if(stars == line-1)
System.out.println();
答案 1 :(得分:0)
要在末尾删除新行,您可以像这样在代码中添加if语句;
public class Prac
{
public static void main (String[] args)
{
for (int line = 7; line >= 1; line = line - 2)
{
for(int stars = 1; stars < line; stars++)
{
System.out.print("*");
}
if((line-2) > 0)System.out.println();
}
}
}
这将确保只有在打印另一行时,才会有新行
答案 2 :(得分:0)
您当前的代码不起作用。 要在最后删除新行,您需要在代码中添加if语句。最好在顶部添加if,如下所示:
for (int line = 7; line >= 1; line -= 2){
if (line < 7) System.out.println(); // Don't print first time
for(int stars = 0; stars < line; stars++) {
System.out.print("*");
}
}