对数据类型感到困惑 [英] Puzzled about data types

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

问题描述

尝试更好地了解作业项目的数据类型.我知道变量的变化和常量保持不变,但是它们与数据类型char,int,double,string和date有何关系?

谢谢,所以这些数据类型char,int,double,string和date是根据程序中定义的类型数据使用的?

Attempting to get a better understanding of types of data for homework project. I understand that a variable changes and constant remains the same but how do they relate to data types char, int, double, string, and date?

Thanks, So these data types char, int, double, string, and date are utilized based on the type data defined in the program?

推荐答案

变量和常量具有类型char,int,double,string和date的形式.常量只是只能分配一次值的变量.该常数或变量的可接受值范围取决于数据类型.因此,数据类型为"double"的变量可以具有一个数字值,例如1.4.然后可以将同一变量重新分配一个新值,例如20.9.可以为数据类型字符串"的常量分配"hello world"的值.这就是程序在整个运行期间的值(即,您无法将值更改为"hello Earth").如果它是数据类型字符串的变量(而不是常量),则可以根据需要多次更改该值.
Variables and constants have types of char, int, double, string, and date. Constants are just variables that can only be assigned a value once. That range of acceptable values for that constant or variable depends on the data type. So, a variable of data type "double" can have a numeric value, such as 1.4. That same variable could then be reassigned a new value of, say, 20.9. A constant of data type "string" could be assigned a value of "hello world". That would be it''s value during the entire time the program is running (i.e., you couldn''t change the value to "hello Earth"). If it were a variable (instead of constant) of data type string, you could change the value as often as you want.


Tahir讲述了一个故事,它可能有助于您了解什么数据类型

我们所有的家庭成员都可以使用您所有的资源,但是您的朋友不能直接来使用资源,因此他必须征得您的许可,这与编程中类似,我们已经将数据类型用于安全类型数据类型,例如int,float,double,char,string

现在,如果我初始化一个整数变量,则说int x = 10;
那么在这种情况下,变量x将仅保留一个整数值,这是对x的限制,如果u尝试将字符串值存储在x中,这是一个整数类型变量,则u最终会导致类型不兼容的错误.

变量用于存储存储在计算机内存中的值,记住计算机内存非常繁琐,因此在这种情况下,我们声明一个人类可以理解的字符或单词
int x [其中x是将保存整数值的变量]

变量可以根据称为覆盖的代码更改其值,请尝试使用此代码以更好地理解

Tahir heres a story that might help u whats a datatype

All ur family members can make use of all the resources of ur house but ur friend cant DIRECTLY come and start making use of resources he has to take ur permission for that similarly in programming we have datatypes that are used for type saftey we have set of datatypes such as int,float,double,char,string

now if i initialize an integer variable say int x=10;
then in this case variable x will hold only an integer value this is the restriction imposed on x if u try to store string value in x which is an integer type variable u will end up in an error of incompatible type.

Variables are used to store values which are stored in the computers memory, computer memory are very tedious to remember so we declare a human understandable character or word say in this case
int x[where x is an variable which will hold an integer value]

variables can change their values depending upon the code thats called overriding try this code for better understanding

class Example1
{
public static void main(String[ ] args)
{
int x = 10;

System.out.println("value of x before overriding: "+x);
int y =20;
x=x+y;
System.out.println("value of x after overriding: "+x);
}
}



现在,常量是那些从程序开始到结束都不会更改其值的变量,任何试图更改常量值的尝试都会引发错误.
在上面的故事中,我说过,您的朋友必须很好地使用资源才能获得您的许可.Tahir有时必须进行类型转换,以获得所需的结果,您将在编程的其他章节中学习有关类型转换的信息...... .......

谢谢&问候
基:rose:

一旦发现有用,就对我的答案进行评分



now constants are those variables which do not change their values from start of the program till the end and any attempt to change the value of a constant will throw an error.
In the above story i said ur friend has to take ur permission for using the resources well Tahir sometimes variables have to be typecasted in order to get the desired result u will learn about type casting in the further chapters of ur programming............

Thanks & Regards
Radix :rose:

Do rate my answer once u find it usefull


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

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