本文介绍了长< name>代表什么?=(long)< expression&gt ;;用Java做?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下表达式中的(long)(int)表示什么意思?

What do (long) and (int) in the following statements before the expression mean?

long years = (long) (minutes / minutesInYear);
int remainingDays = (int) (minutes / 60 / 24) % 365;

推荐答案

(minutes/minutesInYear)尚不清楚它将返回什么变量类型.如果要在int变量中使用它,则必须在其前面编写(int).这称为类型转换",它基本上将一种格式转换为另一种格式.您会注意到 int a = 10.5; 不起作用,但是 int a =(int)10.5; 起作用.

(minutes / minutesInYear) is unclear as to what variable type it will return. If you want it in an int variable, you must write (int) before it. This is called "typecasting", and it basically converts one format to another. You'll notice that int a = 10.5; doesn't work but int a = (int) 10.5; does.

在您的示例中,您希望这样做:(minutes/minutesInYear)存储在一个float中.因此,要确保它变为浮点型,请使用(float)

In your example, you want this: (minutes / minutesInYear) to be stored in a float. So, to make sure it becomes a float, you typecast it using (float)

这篇关于长< name>代表什么?=(long)< expression&gt ;;用Java做?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-22 07:20