Question: Provide a deep explanation of the program showing the explination line by line, and show the purpose of program by the input and output. Then,
Provide a deep explanation of the program showing the explination line by line, and show the purpose of program by the input and output. Then, explain the purpose of the conversion methods: subtraction, division, and multiplication in this program. After that, provide a sample run.
The program:
import java.util.*; public class main { //class main public static String conversion(String value, int sourceB, int destB) { return Integer.toString(Integer.parseInt(value, sourceB), destB); }
public static void main(String[] args) { Scanner input= new Scanner(System.in); System.out.print("***Welcome to conversion Base program*** "); System.out.print("Enter an alphanumeric or numeric value to be converted : "); String value= input.nextLine(); try { if ( value.matches("[A-Za-z0-9]+")) { System.out.print(" *** Choose the base Source *** Base 2 Base 8 Base 10 Base 16 Enter : "); int sourceB = input.nextInt(); System.out.print(" *** Choose the base destination *** Base 2 Base 8 Base 10 Base 16 Enter : "); int destB = input.nextInt(); if((sourceB==2 || sourceB==8 || sourceB==10 || sourceB==16) & (destB==2 || destB==8 || destB==10 || destB==16)) { System.out.println(" Converted Base value: "+ conversion(value, sourceB, destB)+" "); main(null); } else { System.out.println(" Error ! Destination Base {2, 8, 10, 16} !"); } } else if (Integer.parseInt(value)<0 ) { System.out.println(" Do NOT enter negative or floating-point numbers !"); }
} catch(Exception e) { System.out.println(" Error formating Number ! Check the inputs & retry !"); } } }
Step by Step Solution
3.33 Rating (147 Votes )
There are 3 Steps involved in it
A linebyline explanation of the provided Java program along with its purpose import javautil public class main class main This line imports the javautil package and declares a class named main its rec... View full answer
Get step-by-step solutions from verified subject matter experts
