I finally got it in order for smooth compilation, but nothing gets converted

import java.util.Scanner;

    public class nizadi_Lab8
   {
   
   
       public static void main(String[] args)
      {
         if(args.length > 0)
         {
         
            try
            {
               Integer.parseInt(args[0]);
            }
                catch(NumberFormatException f)
               {
                  System.out.println("wrong format");
               }
         }
         
         else
         {
            System.out.println("no arg");
         }
      }
   
       public int  printBin(int n)
      {
      args[0] = n;
      
         if(n < 1)
         {

         }
         else
         {
            System.out.println(printBin(n/2));
         
      
         
      
      System.out.println(printBin(n%2));
      }
      return n%2;
      }  
      
   
   }

This code won't compile at all, firstly try to make it compile, then think of how you define recursion:

  1. base case
  2. recursive case, which decrements value, so recursion terminates at some point

Your primary problem here is that you do not call the 'printBin' method from the main class so this procedure is never called! You also use the call Integer.parseint() but do not allocate the result to any variable. These could be overcome using

printBin(Integer.parseInt();

but as this returns an integer it will still need assigning to something or passing to another method that uses the result. Alternatively, you could make your recursive method return void ancd just use to print the results.

Further, this procedure will not print the desired results, although if you can get any output you may be able to sort the rest out yourself.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.