Java基础教程学习(一)基础结构

来源:互联网 发布:linux mysql 开启日志 编辑:程序博客网 时间:2024/06/10 00:11
基础结构 - 变量,输入,输出
1.变量(Variables in Java)



The scalar types of Java

Java type

Allows for

Range of values

byte

very small integers

-128 to 127

short

small integers

-32768 to 32767

int

big integers

-2147483648 to 2147483647

long

very big integers

-9223372036854775808 to

 9223372036854775807

float

real numbers

 +/- 1.4 * 10-45 to 3.4 * 1038

double

very big real numbers

 +/- 4.9 * 10-324 to 1.8 * 10308

char

characters

Unicode character set

boolean

true or false

not applicable


变量声明(declare) 
dataType variableName;
变量命名规则
  • 不能是java中的关键字(void class)
  • 名称中间不能有空格
  • 不含有运算符和数字符合
创建常量(constant)
final int hours = 24;

2. 输出
    
System.out.println("hello");

3. 输入:Scanner类
 

Scanner专用类,获取来自键盘的信息
import java.util.Scanner;public class Hello {    public static void main(String[] args){        Scanner sca = new Scanner(System.in);        double width, heiht,area;      System.out.println("***计算面积***");        System.out.print("输入宽的长度:");        width = sca.nextDouble();        System.out.print("输入高的大小:");        heiht = sca.nextDouble();        area = width*heiht;        System.out.print("面积为:"+area);    }}




0 0
原创粉丝点击