使用不同数据类型的计算 [英] Calculations using different data types

查看:73
本文介绍了使用不同数据类型的计算的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一项任务要求我编写一个从用户那里获取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 ;-)


这篇关于使用不同数据类型的计算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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