Import java.util.ArrayList;import

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

public class FindCorruptData
{
/**
Reads a set of floating-point values from a string. The first number is an integer that indicates how
many floating point numbers follow. Some of the floating point numbers may be corrupt. This program uses exceptions
to count the number of bad floating (i.e. double) numbers and prints them.
 */
public static void printCorruptDataValues()
{
String numbers = “6 3.14 7.25 8,23 6.99 9.2w 6.34”;
Scanner console = new Scanner(numbers);
int numDoubles = console.nextInt();

//———–Start below here. To do: approximate lines of code = 5
// Use a for loop to loop through numDoubles double number strings.
// Get the next double number string using the scanner then use Double.parseDouble() to determine
// if the current double number string is corrupt in some way. If it is, print “Corrupt Double Number: “
// followed by the number string.  
// Hint: use try{..} catch{..} such that you catch any NumberFormatException and print out the bad double number
// making use of the getMessage() method of the exception class to print the corrupt number string.

//—————–End here. Please do not remove this comment. Reminder: no changes outside the todo regions.
}

public static void main(String[] args)
{
printCorruptDataValues();
System.out.println(“Expected:”);
System.out.println(“Corrupt Double Number: For input string: “8,23””);
System.out.println(“Corrupt Double Number: For input string: “9.2w””);
}
}

P.S: Please include screenshots of the output so all is working as expected. Thank you!

 

Leave a Comment

Your email address will not be published. Required fields are marked *

GradeEssays.com
We are GradeEssays.com, the best college essay writing service. We offer educational and research assistance to assist our customers in managing their academic work. At GradeEssays.com, we promise quality and 100% original essays written from scratch.
Contact Us

Enjoy 24/7 customer support for any queries or concerns you have.

Phone: +1 213 3772458

Email: support@gradeessays.com

© 2024 - GradeEssays.com. All rights reserved.

WE HAVE A GIFT FOR YOU!

15% OFF 🎁

Get 15% OFF on your order with us

Scroll to Top