Design a program that asks the user to enter a floating-point number (either positive or negative). The program repeats while the user enters ‘y’ to continue. The program allows a user to enter either a lowercase or uppercase character. Use the ceil use the ( ), floor ( ), and abs ( ) methods to determine the smallest whole number that is greater than or equal to the number entered, the largest whole number that is less than or equal to the number entered, and the absolute value of the number given, respectively. Use the toLowercase ( ) method to change a given character value to lowercase if the value is an uppercase value.
1
Expert's answer
2016-04-04T12:19:04-0400
import java.util.Scanner;
public class FloatData {
public static void main(String[] args) {
Scanner reader = new Scanner(System.in);
while (true) { System.out.println("Enter a floating-point number: "); float f = reader.nextFloat(); System.out.println(Math.ceil(f)); System.out.println(Math.floor(f)); System.out.println(Math.abs(f)); String s = ""; System.out.println("Would you like to repeat? Press 'y' "); while (!(s = reader.next()).toLowerCase().equals("y")); }
Comments
Leave a comment