JAVA中的货币显示 [英] Money Display in JAVA

查看:94
本文介绍了JAVA中的货币显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题

创建JAVA代码以根据用户数字输入显示美元和美分的数量.例如,如果用户输入540,则程序将在消息对话框中显示5美元和40美分.对于此程序,您将使用整数算术,并且需要避免浮点算术.如果用户输入了浮点数,程序将提示警告消息.

如何创建JAVA代码?如何编写公式?谢谢

QUESTION

create JAVA code to display the number of dollars and cents based on user numeric input. For instance, if the user inputs 540, the program will display 5 dollar and 40 cent in a message dialog. For this program you will use integer arithmetic and will need to avoid floating point arithmetic. If user entered floating numbers, program will prompt a warning message.

How to create a JAVA code?What the formula?Thanz

推荐答案

请至少花点功夫做自己的功课.
Please, at least make an effort to do your own homework.


创建JAVA代码以根据用户数字输入显示美元和美分的数量.例如,如果用户输入540,则程序将在消息对话框中显示5美元和40美分.对于此程序,您将使用整数算术,并且需要避免浮点算术.如果用户输入了浮点数,程序将提示警告消息.
create JAVA code to display the number of dollars and cents based on user numeric input. For instance, if the user inputs 540, the program will display 5 dollar and 40 cent in a message dialog. For this program you will use integer arithmetic and will need to avoid floating point arithmetic. If user entered floating numbers, program will prompt a warning message.


/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Keja
 */
import javax.swing.*;
import javax.swing.JOptionPane;
public class RinggitSen
{

    public static void main(String args [])
    {
        // Declaration of variables.
       int ringgit;
       int sen;
       String inputNumberString;
       int inputNumber;
       JFrame frame;
       frame = new JFrame("Message Dialog");
       // Get interactive user input
       inputNumberString = JOptionPane.showInputDialog("Enter Number: ");

       // Convert String to int
       inputNumber = Integer.parseInt(inputNumberString);

       // Calculate the number
       ringgit = inputNumber / 100;
       sen = inputNumber % 100;

       // Output the result
        JOptionPane.showMessageDialog(frame, ringgit + " Ringgit " + sen + "Sen" );
    }
}


这篇关于JAVA中的货币显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆