71) Write a program to input a number in Decimal and convert it Octal form?( 8 in decimal then 10 in
octal, divide by 8)
import java.util.*;public class Decimal_to_octal{public static void main(String args[ ]){Scanner sc = new Scanner (System.in);System.out.println("Enter a number");int b = sc.nextInt();int a = b;String c = "";while(a>=1){c=c+(a%8);a=a/8;}int k = c.length();System.out.print("Entered number in OCTAL = ");for(int i = k-1;i>=0;i--){System.out.print(c.charAt(i));}}}
No comments:
Post a Comment
if you have any doubts, Please let me know.
Your Truly
Shashank Porwal