Provide a deep explanation of the program showing the explination line by line, and show the purpose
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, 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 !"); } } }
International Marketing And Export Management
ISBN: 9781292016924
8th Edition
Authors: Gerald Albaum , Alexander Josiassen , Edwin Duerr