2016.3.3 软件开发基础
来源:互联网 发布:单片机汇编比较数大小 编辑:程序博客网 时间:2024/06/09 23:18
注释
什么是注释?注释分为几种?注释有什么作用?
注释就是对一些编程思路或程序作用进行注释说明
3种注释 单行注释 ://
多行注释: /*
*
*/
文档注释: /**
*
*/
注释的作用:
- 生成文档
- 跟踪代码依赖性,实现替代配置文件功能
- 在编译时进行格式检查
-------------------------------------------------------------------------------------------------------------------------------------------------
JAVA标识符
标识符就是一个名称
标识符的命名规则:
1、要以字母、下划线(_)或是美元符号($)开头
2、由数字、字母、下划线、美元符号组成
3、不能与关键字一样
4、区分大小写
-------------------------------------------------------------------------------------------------------------------------------------------------
变量与常量
什么是变量?变量的分类?
变量表示在程序中可以修改的数据
变量分为 局部变量和成员变量
局部变量:方法或是语句块内部的变量
成员变量:在类的内部 ,方法的外部的变量
什么是常量?常量的分类?
常量表示在程序中不能被修改的程序
声明变量必须有关键字final
常量分为:整型、浮点型、布尔类型、字符型、字符串型 常量
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Java的数据类型分几类?基本数据类型有哪些?
分为 基本类型和引用类型
基本类型包括
字符型 (char 2个字节)
整型 (byte 1个字节、short 2个字节、int 4个字节、long 8个字节 )
布尔类型 ( boolean
浮点类型 (float 4个字节 double 8个字节)
引用类型 : 数组、字符串、接口、类
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
数据类型的转换
数据类型有小到大排列为 :byte、short、char----->int------>long------>float----double
同等级之间的数据类型不能转换
类型: 自动转换 (有低级向高级)强制转换(有高级到低级)
强制转换可能会造成精度降低或是溢出
整型与字符串之间的相互转换
如何将字串 String 转换成整数 int
int i = Integer.parseInt([String])
如何将整数 int 转换成字串 String
String s = "" + i;
截取字符串
.substring(int begin,int end);
———————————————————————————————————————————
整数变量值之间的互换
使用第三方变量:
部分代码: int a,b;
int temp=a;
a=b;
b=temp;
---------------------------------------------------------------------------------------
自加自减运算
自增(++) 前缀时先加1 再参加运算 后缀时先参加运算 在加1;
自减(- -) 前缀时先减1 再参加运算 后缀时先参加运算 在减1;
例
int i=0;
if(i++==0){
System.out.println(i);
}
输出的结果为 1 i++先参与运算 在加1
运用while continue来计算1-100中奇数的和
部分代码:
int sum=0;
int i=0;
while(++i<=100){
if(i%2==1){
sum=sum+i;
}
else
continue;
}
----------------------------------------------------------------------------------------
在字符串的比较中 == 与equa之间的区别
== 比 较的是地址 而equal 比较的是字符串内容
String s1="asd"+"asd";
String s2=new Stirng(s1);
if(s1==s2){
System.out.println("1成功");
}
if(s1.equal(s2)){
System.out.println("2成功");
}
输出结果为: 2成功
如果 String s2="asdasd";
输出结果为 1成功 2成功
------------------------------------------------------------------------------------------
精彩代码
例一: 简单的考试成绩分等级
部分代码:
Scanner sc=new Scanner(System.in);
int score=sc.nextInt(); //读取键盘值 s.next() //读取字符 s.nextdouble()//读取浮点型 s.Line();//读取一行文本
if(score>100||score<0){
System.out.int("输入分数错入!!");
}
else{
switch(score/10){
case 10: System.out.println(满分");break;
case 9: System.out.println("A");break;
case 8 :System.out.println("B");break;
case 7:System.out.println("C");break;
case 6:System.out.println("D");break;
default: System.out.println("不及格");
}
sc.close(); //关闭Scanner
}
输入一个人的5门成绩
部分代码:
运用数组:
int sum,avg;
sum=0;
int [ ]s=new int[5];
Scanner sc=new Scanner(System.in);
for(int i=0;i<s.lengthli++){
s[i]=sc.nextInt();
sum=s[i]+sum;
}
avg=sum/5;
System.out.println("总成绩为"+sum+"平均数为"+avg);
根据身份证号 来判断星座 (switch 语句)
package ll;
import java.util.Scanner;
public class L9 {
/* 作者:张长朋
* 时间:20163.4
* 题目:身份证号判断星座
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
System.out.println("请输入身份证号: ");
String st=sc.next();
if(st.length()!=18){
System.out.println("身份证号错误!");
}
else{
String s1=st.substring(10, 12);
String s2=st.substring(12, 14);
//System.out.println(s1);
//System.out.println(s2);
int mou=Integer.parseInt(s1);
int day=Integer.parseInt(s2);
switch (mou) {
case 1:
if(day>=1&&day<=19){
System.out.println("摩羯座");
}
else{
System.out.println("水瓶座");
}
break;
case 2:
if(day>=1&&day<=18){
System.out.println("水瓶座");
}
else {
System.out.println("双鱼座");
}
break;
case 3:
if(day>=1&&day<=20){
System.out.println("双鱼座");
}
else{
System.out.println("白羊座");
}
break ;
case 4:
if(day>=1&&day<=19){
System.out.println("白羊座");
}
else{
System.out.println("金牛座");
}
break;
case 5:
if(day>=1&&day<=20){
System.out.println("金牛座");
}
else{
System.out.println("双子座");
}
break;
case 6:
if(day>=1&&day<=21){
System.out.println("双子座");
}
else{
System.out.println("巨蟹座");
}
break;
case 7:
if(day>=1&&day<=22){
System.out.println("巨蟹座");
}
else{
System.out.println("狮子座");
}
break;
case 8:
if(day>=1&&day<=22){
System.out.println("狮子座");
}
else{
System.out.println("处女座");
}
break;
case 9:
if(day>=1&&day<=22){
System.out.println("处女座");
}
else{
System.out.println("天秤座");
}
break;
case 10:
if(day>=1&&day<=23){
System.out.println("天秤座");
}
else{
System.out.println("天蝎座");
}
break;
case 11:
if(day>=1&&day<=21){
System.out.println("天蝎座");
}
else{
System.out.println("射手座");
}
break;
case 12:
if(day>=1&&day<=21){
System.out.println("射手座");
}
else{
System.out.println("摩羯座");
}
break;
default:
System.out.println("日期错误!");
}
}
sc.close();
}
}
import java.util.Scanner;
public class L9 {
/* 作者:张长朋
* 时间:20163.4
* 题目:身份证号判断星座
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
System.out.println("请输入身份证号: ");
String st=sc.next();
if(st.length()!=18){
System.out.println("身份证号错误!");
}
else{
String s1=st.substring(10, 12);
String s2=st.substring(12, 14);
//System.out.println(s1);
//System.out.println(s2);
int mou=Integer.parseInt(s1);
int day=Integer.parseInt(s2);
switch (mou) {
case 1:
if(day>=1&&day<=19){
System.out.println("摩羯座");
}
else{
System.out.println("水瓶座");
}
break;
case 2:
if(day>=1&&day<=18){
System.out.println("水瓶座");
}
else {
System.out.println("双鱼座");
}
break;
case 3:
if(day>=1&&day<=20){
System.out.println("双鱼座");
}
else{
System.out.println("白羊座");
}
break ;
case 4:
if(day>=1&&day<=19){
System.out.println("白羊座");
}
else{
System.out.println("金牛座");
}
break;
case 5:
if(day>=1&&day<=20){
System.out.println("金牛座");
}
else{
System.out.println("双子座");
}
break;
case 6:
if(day>=1&&day<=21){
System.out.println("双子座");
}
else{
System.out.println("巨蟹座");
}
break;
case 7:
if(day>=1&&day<=22){
System.out.println("巨蟹座");
}
else{
System.out.println("狮子座");
}
break;
case 8:
if(day>=1&&day<=22){
System.out.println("狮子座");
}
else{
System.out.println("处女座");
}
break;
case 9:
if(day>=1&&day<=22){
System.out.println("处女座");
}
else{
System.out.println("天秤座");
}
break;
case 10:
if(day>=1&&day<=23){
System.out.println("天秤座");
}
else{
System.out.println("天蝎座");
}
break;
case 11:
if(day>=1&&day<=21){
System.out.println("天蝎座");
}
else{
System.out.println("射手座");
}
break;
case 12:
if(day>=1&&day<=21){
System.out.println("射手座");
}
else{
System.out.println("摩羯座");
}
break;
default:
System.out.println("日期错误!");
}
}
sc.close();
}
}
0 0
- 2016.3.3 软件开发基础
- 2016.3.2 软件开发基础
- 软件开发基础
- 基础软件开发管理
- 软件开发基础模型
- 软件开发方法基础
- 附:软件开发基础
- 基础软件开发的日子
- 业务基础软件开发平台
- 软件开发的四大基础
- 软件开发与数学基础
- 测试基础---软件开发生命周期
- 软件开发步骤(基础)
- 软件开发的基础内容
- 软件开发流程基础常识
- 测试基础---软件开发生命周期
- [零基础学软件开发3]第一行c代码
- C语言开发基础软件理解
- [JAVA · 初级]:5.以我微观看变量
- bzoj1091 切割多边形 枚举&计算几何
- 蓝桥杯历届-古堡算式
- Android Cordova 插件开发之创建项目
- pat 1009 - 1010
- 2016.3.3 软件开发基础
- MyBatis快速入门
- 设计模式之适配器模式
- mybatis调用orcale存储过程-传入多个参数返回结果集
- 历届试题 错误票据
- The first day of learning java
- Android Cordova 插件开发之编写自定义插件
- 统计学习方法概论
- onEnter和init