java初级学习总结.ppt
文本预览下载声明
基础知识 流程控制 数组与字符串 面向对象程序设计 类库 异常处理 标识符的命名规则: 必须以字母、下划线(_)或美元符号开头,后面可以是字母、下划线、美元符号、数字(0~9)。 整数类型说明 实数类型 数据输入 import java.io.*; public class UseArithmetic { public static void main(String[] args) throws IOException { int a; String s; BufferedReader r=new BufferedReader (new InputStreamReader(System.in)); s=r.readLine(); a=Integer.parseInt(s); //将该字符串转换为整型 。。。。。。。。。 } } 关系运算符 错误分析: if(w=0) system.out.println(no cost!); if(0w5) cost=10 逻辑运算符 二、流程控制 if(条件表达式) { 语句块1 } else { 语句块2 } 练习:分析程序运行结果。 public class s1 { public static void main(String[] args) { int x=1; switch(x) { case 0: System.out.println(first);break; case 1: System.out.println(second); case 2: System.out.println(third); break; } } } 练习:分析程序运行结果。 public class s1 { public static void main(String[] args) { int x=5; switch(x) { default: System.out.println(default);break; case 1: System.out.println(second); break; case 2: System.out.println(third); break; } } } 纠错分析题 public class MonthSwitch { public static void main(String args[ ]) throws IOException { String s; BufferedReader r=new BufferedReader (new InputStreamReader(System.in)); system.out.println(enter an integer:); s=r.readline(); x=Integer.parseInteger(s); if(1x12); { System.out.println(请重新输入(1~12):) } 纠错分析题 switch(x) { case’2’: System.out.println(28天); case’1,3,5,7,8,10,12’: System.out.println(“31天); case’4’: case’6’: case’9’: case’11’: System.out.println(“31天); } } 纠错分析题 import java.io.*; public class Month
显示全部