使用不同数据类型的计算

编程入门 行业动态 更新时间:2024-10-25 10:27:35
本文介绍了使用不同数据类型的计算的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一项任务要求我编写一个从用户那里获取5个数字的应用程序。当用户输入数字时,我必须将它们变成double,float,long,int和byte。在此之后我需要的是输出以下计算的结果并将结果存储在一个int变量中。 计算要做 从intValue中减去floatValue,然后乘以doubleValue,然后除以longValue,然后乘以byteValue然后除以2.我将结果存储在int变量中。我可以获得用户输入,但是如何进行计算并将结果存储在int变量中则不知所措。有人可以在网络世界中帮忙吗?感谢响应的任何人。 代码 import java.util。*; 公共类TestNumbers { public static void main(String args []) { 扫描仪输入=新扫描仪(System.in); int结果; System.out.println("输入数字:"); double num1 = input.nextDouble(); System.out.println(); System.out.println("输入第二个数字:"); float num2 = input.nextFloat(); System.out.println(); System.out.println("输入第三个数字:"); long num3 = input.nextLong( ); System.out.println(); System.out.println("输入第四个数字:"); int num4 = input.nextInt(); System.out.println(); System.out.println("输入第五个数字:"); byte num5 = input.nextByte (); System.out.println(); } }

解决方案

从intValue中减去floatValue,然后乘以doubleValue,然后除以longValue ,然后乘以byteValue然后除以2.我将结果存储在一个int变量中。我可以获得用户输入,但是如何进行计算并将结果存储在int变量中则不知所措。

该赋值文本几乎读起来像COBOL;问题是什么?假设变量是fv,iv,dv,lv和bv。公式如下: (iv-fv)* dv / lv * bv / 2 结果需要再次为int所以你必须施展。在Java中读取:

展开 | 选择 | Wrap | 行号

你需要做的是详细拼写,不是吗? br /> 1.从intValue中减去floatValue, 2.然后乘以doubleValue, 3.然后除以longValue, 4.然后乘以byteValue和 5.然后除以2. 6.我将结果存储在一个int变量。 我的建议是尝试这样做,如果你还有问题就发布它。

你要做的就是详细说明,不是吗?

承认:你用COBOL编程也不是吗? 亲切的问候, Jos; - )

I have an assignment that wants me to write an application that takes 5 numbers from a user. As the user inputs the numbers I have to make them into a double, float, long, int and byte. All I need after this is to output the result of the following calculation and store the result in an int variable. Calculation to do Subtract the floatValue from the intValue, then multiply by the doubleValue, then divide by the longValue, then multiply by the byteValue and then divide by 2. I am to store the result in an int variable. I can get the user input but am at a loss as to how to do the calculation and store the result in an int variable. Can someone out in cyberworld help? Thanks to anyone who responds. CODE import java.util.*; public class TestNumbers { public static void main(String args[]) { Scanner input = new Scanner(System.in); int result; System.out.println("Enter a number:"); double num1 = input.nextDouble(); System.out.println(); System.out.println("Enter second number:"); float num2 = input.nextFloat(); System.out.println(); System.out.println("Enter third number:"); long num3 = input.nextLong(); System.out.println(); System.out.println("Enter fourth number:"); int num4 = input.nextInt(); System.out.println(); System.out.println("Enter fifth number:"); byte num5 = input.nextByte(); System.out.println(); } }

解决方案

Subtract the floatValue from the intValue, then multiply by the doubleValue, then divide by the longValue, then multiply by the byteValue and then divide by 2. I am to store the result in an int variable. I can get the user input but am at a loss as to how to do the calculation and store the result in an int variable.

That assignment text almost reads like COBOL; what is the problem? Assume the variables are fv, iv, dv, lv and bv. The formula reads as: (iv-fv)*dv/lv*bv/2 The result needs to be an int again so you have to cast. In Java that reads:

Expand|Select|Wrap|Line Numbers

What you have to do is spelled out in detail, no? 1. Subtract the floatValue from the intValue, 2. then multiply by the doubleValue, 3. then divide by the longValue, 4. then multiply by the byteValue and 5. then divide by 2. 6. I am to store the result in an int variable. My advice is to try to do this and post it if you still have questions.

What you have to do is spelled out in detail, no?

Admit it: you programmed in COBOL too didn''t you? kind regards, Jos ;-)

更多推荐

使用不同数据类型的计算

本文发布于:2023-10-25 14:19:04,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1527206.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据类型

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!