【问题标题】:C to Java (binary numbers programm) [closed]C 到 Java(二进制数程序)[关闭]
【发布时间】:2017-04-25 00:27:01
【问题描述】:

我用 C 编写了这个程序,但我对 Java 毫无概念(年轻开发者)。你能帮我在 Java 上“翻译”它吗?

#include<stdio.h>
#include<stdlib.h>
#include<graphics.h>
void printbin(int num)
{
   int binnum;
   binnum=num%2;
   num=num/2;
   if (num!=0) printbin(num);
   printf("%d",binnum);
   return;
   system("pause");
}

int main(void)
{
   int posnumber,binnum;
   printf("Give a number : ");
   scanf("%d",&posnumber);   
   printbin(posnumber);
   printf("\n");
   return 0;
}

【问题讨论】:

  • SO 没有代码翻译服务,抱歉。职业培训中心。
  • * #include #include #include
  • 我投票结束这个问题作为题外话,因为它显然是一个写我的代码请求,而不是一个问题。请先阅读How to Ask 页。 :)
  • 请展示您迄今为止的研究/调试工作。请先阅读How to Ask页面。
  • 好吧,伙计们..你很专业,但我不是...这不是我的项目,只是为了好玩...我只想让...如果你可以帮助我,评论......如果你只想和一个他不知道发展的白痴“取笑”,因为你是神,不要让 cmets @SouravGhosh

标签: java c translate


【解决方案1】:

你可以从这段代码中学习,希望对你有帮助:

//here is comments in java
package help;

import java.util.Scanner;
//this is the way how you can all the libraries in java so
/*
#include<stdio.h>
#include<stdlib.h>
#include<graphics.h>
*/    

//here name of your class
public class Help {

    //here name of your methode
    public static void printbin(int num) {
        int binnum;
        binnum = num % 2;
        num = num / 2;
        if (num != 0) {
            printbin(num);
        }
        System.out.println(binnum);
    }

    //here is the main methode in java
    public static void main(String args[]) {
        int posnumber, binnum;
        Scanner scan = new Scanner(System.in);
        System.out.println("Give a number : ");
        posnumber = scan.nextInt();
        System.out.println(posnumber);
    }
}

祝你好运,从 java 开始:)

【讨论】:

  • 谢谢@mrly
  • 不客气 :)
  • 我会在 6 分钟内再次接受它..thnx!
  • 你可以检查我的编辑@MarcJackob,我会解释更多我的代码祝你好运:)
猜你喜欢
  • 2012-12-22
  • 1970-01-01
  • 1970-01-01
  • 2013-01-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多