C to Java (二进制数编程)
C to Java (binary numbers programm)
我在 C 上制作了这个程序,我不知道 Java(新手开发者)。你能帮我在 Java 上 "translate" 吗?
#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;
}
您可以借鉴这段代码,希望对您有所帮助:
//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 开局不错:)
我在 C 上制作了这个程序,我不知道 Java(新手开发者)。你能帮我在 Java 上 "translate" 吗?
#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;
}
您可以借鉴这段代码,希望对您有所帮助:
//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 开局不错:)