标签: console-output

在递归中使用+ =的Java和C++中的不同结果

如下非常简单的Java代码具有奇怪的输出,但C和C++中的相同逻辑代码具有正确的输出.我尝试使用JDK 1.7和JDK 1.3(相对JRE),奇怪的输出始终存在.

public class Test {

    public static int sum=0;

    public static int fun(int n) {

        if (n == 1)
            return 1;
        else
            sum += fun(n - 1);  // this statement leads to weird output
        // { // the following block has right output
        //     int tmp = fun(n - 1);
        //     sum += tmp;
        // }

        return sum;
    }

    public static void main(String[] arg) {
        System.out.print(fun(5));
    }
}
Run Code Online (Sandbox Code Playgroud)

输出为1,应为8.相对C/C++代码如下:

#include<stdio.h>
int sum=0;
int fun(int n) {

        if (n …
Run Code Online (Sandbox Code Playgroud)

c++ java recursion operator-precedence console-output

6
推荐指数
2
解决办法
1063
查看次数

echo 一个 JavaScript 变量

回显变量 get_parestotal 的最佳方法是什么?

请一些帮助!谢谢

  <script type="text/javascript">
 $(document).ready(function(){
                    var get_parestotal = 0
                $(".parestotal").each(function(){
                    get_parestotal += parseFloat($(this).text());
                });
                alert(get_parestotal);

            });

</script>



<? echo json_encode($get_parestotal); ?>
Run Code Online (Sandbox Code Playgroud)

javascript echo console-output

5
推荐指数
1
解决办法
3万
查看次数

在重定向文件 (&gt;output.txt) 中显示带有重音符号的字符

例子

mode con: cp>%tmp%\output.tmp
notepad %tmp%\output.tmp
Run Code Online (Sandbox Code Playgroud)

展示:

Statut du p‚riph‚rique CON:
---------------------------
    Page de codesÿ:   850
Run Code Online (Sandbox Code Playgroud)

代替:

Statut du périphérique CON:
---------------------------
    Page de codes :   850
Run Code Online (Sandbox Code Playgroud)

我也试过chcp 650011252

你知道修复吗?

编辑:

我使用 truetype Lucida 字体,即使我这样做,type %tmp%\output.tmp它也会在控制台中显示正确的字符,但在任何文本编辑器中都没有。

我也试过:

cmd /U /C "chcp 65001>nul &mode con: cp>%tmp%\output.tmp"
Run Code Online (Sandbox Code Playgroud)

cmd /A /C "chcp 65001>nul &mode con: cp>%tmp%\output.tmp"
Run Code Online (Sandbox Code Playgroud)

没有成功

windows cmd batch-file console-output

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

高位和低位字节

getchar() 和 putchar() 的原型是:

int getchar(void);

int putchar(int c);

正如它的原型所示,getchar() 函数被声明为返回一个整数。但是,您可以将此值分配给一个 char 变量,就像通常所做的那样,因为该字符包含在低位字节中。(高位字节) -order 字节通常为零。)

与 putchar() 的情况类似,即使它被声明为采用整数参数,您通常也会使用字符参数调用它。只有其参数的低位字节实际输出到屏幕。

我正在研究控制台 I/O 并遇到了这个问题。高位字节和低位字节是什么意思?

在上述上下文中它是什么意思?

c bit console-output console-input

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

网状不会实时打印到控制台

print()在循环结构中使用 Python 的(或据我所知,任何其他控制台输出生成)函数并通过R 中的网状运行代码,输出仅在执行完成后打印。例如,采用以下循环,每次迭代后进入休眠状态 1.5 秒;循环结束后,运行号全部打印出来。将 Python 代码保存到单独的 .py 文件然后运行reticulate::py_run_file().

library(reticulate)

py_run_string("
import time

for i in range(5):
   print(str(i))
   time.sleep(1.5) # sleep for 1.5 sec
")
Run Code Online (Sandbox Code Playgroud)

有谁知道这种行为的来源,如果可能的话,如何规避它?

python r console-output reticulate

5
推荐指数
2
解决办法
619
查看次数

是否可以在Python中将print语句与中心对齐?

我想知道是否可以在Python(最新版本)中对齐print语句.例如:

print ("hello world")
Run Code Online (Sandbox Code Playgroud)

会显示在左侧的用户屏幕上,那么我可以将其设为居中对齐吗?

非常感谢你的帮助!

= 80(列)x 30(宽度)

python alignment console-output

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

How can i use printf("\b") to make my console output look like typewriter?

I am using a loop to delete characters from a string using printf(\b) 1 by 1 and sleep 0.1 seconds in between. But when I run the code it happens simultaneously.

I literally tried typing each printf because I thought the loop might be the cause but still, the output was the same

#include <stdio.h>
#include <unistd.h>

void coolIntro(){
int i;

printf("A Game by Hideo Kojima");

Sleep(800);

for(i=0;i<12;i++){

    printf("\b");

    Sleep(100);

        }

printf("my_name_here");
}
Run Code Online (Sandbox Code Playgroud)

I want the letters to disappear with …

c printf console-output backspace

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

如何在java中使用for循环打印带有"*"的三角形?

我想用for循环绘制一个像下面这样的星形的三角形,但我真的不知道怎么做这个?三角形将是这样的:

*
**
***
****
*****
******
*******
********
*********
**********
Run Code Online (Sandbox Code Playgroud)

等等.有人可以帮帮我吗?

public class Project1 {
    public static void main (String[] args){
        int c, d, e;
        for (c = 1 ; c <= 8 ; c++){
            for (d = 1 ; d <= c ; d++){
                System.out.print ("*");
            }
            System.out.println("");
        }

        for (e = 1 ; e <= 4 ; e++){
            System.out.println ("***");
        }
    } 
} 
Run Code Online (Sandbox Code Playgroud)

这是我从互联网上找到的,但我不明白为什么它使用两个循环.(我理解用于构建茎的那个.)

java for-loop console-output

-1
推荐指数
1
解决办法
2万
查看次数