// Program by Akash Tripathi (@proakash256)
import java.util.Scanner;
public class Octal {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
byte ch;
int n;
System.out.println("Enter 1 to convert
Octal Number to
Decimal Number.");
System.out.println("Enter 2 to convert
Decimal Number to
Octal Number.");
System.out.println("Enter your Choice :\n");
ch = sc.nextByte();
System.out.println();
if (ch == 1) {
System.out.print("Enter the Octal Number : ");
n = sc.nextInt();
System.out.println();
int temp = n, i = 0, s = 0, a;
while (temp > 0) {
a = temp % 10;
s = s + (a * (int) Math.pow(8, i));
temp = temp / 10;
i = i + 1;
}
System.out.println("\nThe Decimal
equivalent of
Octal Number "
+ n + " is : " + s);
} else if (ch == 2) {
System.out.print("Enter the Decimal Number : ");
n = sc.nextInt();
System.out.println();
int temp = n, i = 0, s = 0, a;
while (temp > 0) {
a = temp % 8;
s = s + (a * (int) Math.pow(10, i));
temp = temp / 8;
i = i + 1;
}
System.out.println("The Octal equivalent
of Decimal Number "
+ n + " is : " + s);
} else
System.out.println("Invalid Choice.\n");
sc.close();
}
}
Comments
Post a Comment