Answers for "Java program convert decimal to octal using while loop"

1

Java program convert decimal to octal using while loop

import java.util.Scanner;
public class DecimalToOctalUsingWhileLoop
{
   public static void main(String[] args)
   {
      int decimal;
      Scanner sc = new Scanner(System.in);
      System.out.println("Please enter decimal number: ");
      decimal = sc.nextInt();
      int octalNumber = 0, a = 1;
      while(decimal > 0)
      {
         octalNumber += a * (decimal % 8);
         decimal = decimal / 8;
         a = a * 10;
      }
      System.out.println("Octal number is: " + octalNumber);
      sc.close();
   }
}
Posted by: Guest on February-18-2021

Code answers related to "Java program convert decimal to octal using while loop"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language