练习题
//程序员:王智霞
//1、输出一个长整型的变量
public class Long
{
public static void main(String[] args)
{
long l=123456789012345l;//java中默认类型为Int型,电脑想要识别长整型需加l(或L)
System.out.println(l);
}
}
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//2、输出一个单精度的小数常量
public class Float
{
public static void main(String[] args)
{
float f=2.4f;//java中小数默认为double型
System.out.println(f);
}
}
--------------------------------------------------------------------------------------------------------------------------------------------------------------
//3、输出一个布尔类型的变量
public class Boolean
{
public static void main(String[] args)
{
boolean b=true;
b=false;
System.out.println(b);
}
}
-----------------------------------------------------------------------------------------------------------------------------------
//4、强制类型转换
public class Byte
{
public static void main(String[] args)
{
byte b=5; //b为byte类型,并为b初始化值
b=(byte)(b+200); //200为Int类型,与b类型不一致,需要强制转换
System.out.println(b);
}
}
----------------------------------------------------------------------------------------------------------------------
//5、输出一个字符型的加法计算
public class Char
{
public static void main(String[] args)
{
System.out.println('c'+1);
System.out.println((char)('c'+1));//将数字Int类型转换为字符型
}
}
------------------------------------------------------------------------------------------------------------------------------------
//6、变量的溢出效果
public class Overflow
{
public static void main(String[] args)
{
int big=0x7fffffff;
System.out.println(big);
}
}
-------------------------------------------------------------------------------------------------------------------------------------------------------
//7、算数运算符
import java.util.Scanner;
public class Count
{
public static void main(String[] args)
{
Scanner input=new Scanner(System.in);//创一个对象
System.out.println("输入一个数");
int x=input.nextInt();//输入一个整型的数
x=x/1000*1000;
System.out.println("输出的x为:"+x);
}
}