-3

I made this program on C,and I have no idea of Java (new-yοung developer).Can you help me to "translate" it on 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;
}
Youcef LAIDANI
  • 55,661
  • 15
  • 90
  • 140
MarcJackob
  • 11
  • 2

1 Answers1

0

You can learn from this code, hope this can help you:

//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);
    }
}

Good luck, and good start with java :)

Youcef LAIDANI
  • 55,661
  • 15
  • 90
  • 140