Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help with the flowchart, pseudocode, and UML diagram for both programs. InputMismatch.java import java.util.InputMismatchException; import java.util.Scanner; public class InputMismatch { public static void

I need help with the flowchart, pseudocode, and UML diagram for both programs.

InputMismatch.java

import java.util.InputMismatchException; import java.util.Scanner;

public class InputMismatch {

public static void main(String[] args) { Scanner scan = new Scanner(System.in); int firstNum, secondNum=0; while(true){ try{ System.out.println("Enteraninteger: "); firstNum = scan.nextInt(); break; } catch(InputMismatchException e){ System.out.println("Pleaseenteraninteger"); scan.next(); } } while(true){ try{ System.out.println("Enteraninteger: "); secondNum = scan.nextInt(); break; } catch(InputMismatchException e){ System.out.println("Pleaseenteraninteger"); scan.next(); } } int sum = firstNum + secondNum; System.out.println("The sum of two numbers is : "+sum); }

}

NumberFormat.java

import java.util.Scanner;

public class NumberFormat {

public static void main(String[] args) {

Scanner scan = new Scanner(System.in);

try{

System.out.println("Enter a binary string:");

String s = scan.next();

int integerValue = bin2Dec(Integer.parseInt(s));

System.out.println("The decimal value of "+s+" is "+integerValue);

}

catch(NumberFormatException e){

System.out.println(e);

}

}

public static int bin2Dec(int binaryNumber) throws NumberFormatException{

int decimal = 0;

int p = 0;

try{

while(true){

if(binaryNumber == 0){

break;

} else {

int temp = binaryNumber%10;

decimal += temp*Math.pow(2, p);

binaryNumber = binaryNumber/10;

p++;

}

}

}

catch(NumberFormatException e){

throw new NumberFormatException("Invalid binary number");

}

return decimal;

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Networking is a two-way street. Discuss this statement.

Answered: 1 week ago