【Java】基本Java语法,初学Java
2018-04-03 19:57
267 查看
常量:public static final double PI = 3.14159265358979323846;函数:将ang角度转换成径度public static double toRadians(double ang) {return ang / 180.0 * PI;}
if语句int score = 70; //考试成绩 if ( score >= 90 ) { System.out.println("优秀"); } else if (score >= 80 ) { System.out.println("良好"); } else if (score >= 60 ) { System.out.println("中等"); } else { System.out.println("差"); }
基本语法示例:
文件名称:ClassFun.javapublic class ClassFun { public double hight; private double weight, age; String name; // init all class object { System.out.println("init ClassFun class!"); this.hight = 1.75; this.age = 18; this.weight = 50; this.name = "administor"; } ClassFun(String new_name, double new_age, double new_hight, double new_weight){ this.age = new_age; this.name = new_name; this.hight = new_hight; this.weight = new_weight; } public void spoke_name(int password) { System.out.println("My name is : " + name); if(password == 999) spoke_weight(); else if(password == 888) spoke_age(); } private void spoke_weight() { System.out.println("My weight is : " + weight); } private void spoke_age() { System.out.println("My age is : " + age); }
}
文件名称:PrintHello.javapublic class PrintHello { public static void print_name(String name) { // this function is used to print String type. System.out.println(name); }
public static void main(String[] args) { // TODO Auto-generated method stub System.out.println("Hello World!"); int []a = {1,2,3,4}; for(int i = 0;i < a.length;i++) { System.out.println("a===" + a[i]); }// for(int i = 0;i < a.length;i++) int b = 4; switch(b) { case 100: System.out.println("a = 100"); break; case 10: System.out.println("a = 10"); break; default: System.out.println("XIAO"); }// switch(b) String str = "aa"; while(b <= 100) { str = System.out.toString(); System.out.println("b = " + b + " -> " + str); b++; if(b == 88) break; else if(b == 77) { System.out.println("b == 77"); }// if(b == 88) }// while(b <= 100) print_name("xiaogongwei10"); ClassFun Xiao = new ClassFun("xiaogongwei", 28, 1.75, 100); Xiao.spoke_name(888); Xiao.hight = 2.0; Xiao.name = "David Xiao"; Xiao.spoke_name(999); print_name(Xiao.toString()); }//main
}
if语句int score = 70; //考试成绩 if ( score >= 90 ) { System.out.println("优秀"); } else if (score >= 80 ) { System.out.println("良好"); } else if (score >= 60 ) { System.out.println("中等"); } else { System.out.println("差"); }
基本语法示例:
文件名称:ClassFun.javapublic class ClassFun { public double hight; private double weight, age; String name; // init all class object { System.out.println("init ClassFun class!"); this.hight = 1.75; this.age = 18; this.weight = 50; this.name = "administor"; } ClassFun(String new_name, double new_age, double new_hight, double new_weight){ this.age = new_age; this.name = new_name; this.hight = new_hight; this.weight = new_weight; } public void spoke_name(int password) { System.out.println("My name is : " + name); if(password == 999) spoke_weight(); else if(password == 888) spoke_age(); } private void spoke_weight() { System.out.println("My weight is : " + weight); } private void spoke_age() { System.out.println("My age is : " + age); }
}
文件名称:PrintHello.javapublic class PrintHello { public static void print_name(String name) { // this function is used to print String type. System.out.println(name); }
public static void main(String[] args) { // TODO Auto-generated method stub System.out.println("Hello World!"); int []a = {1,2,3,4}; for(int i = 0;i < a.length;i++) { System.out.println("a===" + a[i]); }// for(int i = 0;i < a.length;i++) int b = 4; switch(b) { case 100: System.out.println("a = 100"); break; case 10: System.out.println("a = 10"); break; default: System.out.println("XIAO"); }// switch(b) String str = "aa"; while(b <= 100) { str = System.out.toString(); System.out.println("b = " + b + " -> " + str); b++; if(b == 88) break; else if(b == 77) { System.out.println("b == 77"); }// if(b == 88) }// while(b <= 100) print_name("xiaogongwei10"); ClassFun Xiao = new ClassFun("xiaogongwei", 28, 1.75, 100); Xiao.spoke_name(888); Xiao.hight = 2.0; Xiao.name = "David Xiao"; Xiao.spoke_name(999); print_name(Xiao.toString()); }//main
}
相关文章推荐
- java-接口的基本语法(第28集)
- java基本语法的总结(一)
- Java基本语法
- [Java]复习笔记(三)--基本语法
- 回顾JAVA---1.概述及基本语法
- Java基础--------基本语法
- Java篇--Java语言的基本语法2
- JAVA 基础语法(一)——变量以及基本数据类型
- 《partner4java 讲述MySQL》之第一步:基本语法
- Java千百问_03基本的语法(005)_二进制是如何做位运算的
- java基础--1.基本语法 - 3.运算符
- java基础--1.基本语法 - 5.方法
- Java 基本语法
- [java语法]基本语法(4) 数组
- 第二章、Java基本语法
- 天耀18期 – 03.Java基本语法【作业】.
- Java基本语法学习时需要注意的几点
- Java_语法基础_基本数值与包装对象的转换
- Java基础学习之Java基本语法(1)【Java命名规范+程序执行过程】
- java基本语法