网络编程技术实验报告
一实验目的:
网络编程技术是计算机科学与技术专业、网络工程专业、软件工程专业的一 门专业基础课程。本课程以Java技术为主讲授,Java语言是当前最流行的网络 编程语言。本课程是一门实用性和综合运用性都很强的课程,实践教学环节是教 学过程中必不可少的重要内容。通过实验,让学生熟悉JDK中的主要内容,掌 握用JDK调试和运行程序的方法,掌握网络编程的基本思想和开发方法、面向 对象编程的思想,JAVA中的基本方法和技术,能够熟练使用JAVA设计、编写 程序,特别是基于TCP/IP的Socket编程,并能运用这些知识方法完成C/S和 B/S结构程序的设计工作。通过实验,提高学生使用Java语言程序设计开发的能 力,提高应用面向对象技术分析和解决实际问题的能力,并在此基础上强化学生 的实践意识、提高其分析问题、解决问题的能力以及动手能力和创新能力。
二实验要求
要求学生熟悉JDK中的主要内容,掌握用JDK调试和运行程序的方法,掌 握网络编程的基本思想和开发方法、面向对象编程的思想,JAVA中的基本方法 和技术,能够熟练使用JAVA设计、编写程序,特别是基于TCP/IP的Socket编 程,并能运用这些知识方法完成C/S和B/S结构程序的设计工作。要注意培养学 生良好的编程习惯,自始至终贯彻课程中所介绍的程序设计风格。为保证尽量在 统一安排的上机时间内完成程序设计任务,学生应事先做问题分析,并做静态检 查。学生应记录实验中所遇到的问题,并写出详细的实验报告。课前准备上机程 序,上机认真调试,课后撰写实验报告,实验报告包括实验目的、实验内容、源 程序、实验结果及分析。
实验一 java基本语法
实验目的:
了解Java的数据类型,掌握各种变量的声明方式,理解运算符 的优先级,掌握Java基本数据类型、运算符与表达式,掌握顺序结构、选择 结构和循环结构语法的程序设计方法。
实验要求:
1、编写一个声明Java不同数据类型变量的程序。 2、编写使用不同选择结构的程序。 3、编写使用不同循环结构结构的程序。
实验内容:
1、编写一个声明Java不同数据类型变量的程序。 public class DataTypes {
public static void main(String args[]) {
byte b=127; short s=32767; int i=2147483647;
long l=9223372036l;//为什么long表示的数比Int还小? char c='c'; float f=1.23F; double d=0.9E-3; boolean bool=true;
System.out.println(\ System.out.println(\ System.out.println(\ System.out.println(\ System.out.println(\ System.out.println(\ System.out.println(\
System.out.println(\ }
}
/////////////////////////////////////////////////////////////////////////////////////// public class Testif {
public static void main(String args[]) {
boolean leap; int year=2014;
if((year%4==0&&year0!=0)||(year@0==0))// System.out.println(year+\年是闰年\ else
System.out.println(year+\年不是闰年\ //方法二///////////////////////////////////////
year=2008; if(year%4!=0) leap=false; else if(year0!=0) leap=true; else if(year@0!=0) leap=false; else leap=true; if(leap==true) System.out.println(year+\年是闰年\
else System.out.println(year+\年不是闰年\ //方法三///////////////////////////////////// year=2050; if(year%4==0){
if(year0==0){ if(year@0==0) leap=true; else leap=false; } else leap=false; } else leap=false; if(leap==true) System.out.println(year+\年是闰年\ else System.out.println(year+\年不是闰年\
} }
2、编写使用不同选择结构的程序。
//使用switch语句/////////////////////////////////////
//1.编写程序用Switch语句实现从键盘上都1,2,3时,屏幕提示不同的信息 import java.io.*; class SwitchTest { public static void main(String args[]) throw IOException { char a; System.out.println(\ a=(char)System.in.read(); switch(a) { case '1': System.out.println(\ case '2': System.out.println(\ case '3':
System.out.println(\ default:System.out.println(\ } } }
3、编写使用不同循环结构结构的程序。
//for循环语句
import java.io.*; class ForTest { public static void main(String args[])throws IOException { int fahr,cels; System.out.println(\ for(cels=0;cels<=100;cels+=5) { fahr=cels*9/5+32; System.out.println(cels+\ }
} }
char a;
outer://this is the lable for the outer loop for(int i=0;i<10;i++) for(int j=0;j<10;j++){ a=(char)System.in.read(); if(a=='b') break outer; if(a=='c') continue outer; }
//while循环语句//////////////////////////////////////////// import java.io.*; class WhileTest { public static void main(String[] args)throws IOException { char ch; System.out.println(\按1/2/3数字可获大奖!\ System.out.println(\按空格键后回车可退出循环操作\ while((ch=(char)System.in.read())!=' ') { System.in.skip(2);//跳过回车键 switch(ch){ case'1':
System.out.println(\恭喜你获得大奖,一辆汽车\ case'2': System.out.println(\不错呀,你得到一台笔记本电脑\ case '3':
System.out.println(\没白来,你得到一台冰箱\ default:
System.out.println(\真不兴,你没有奖品!下次再来\
} } } }
//多重循环
public class Mul99 { public static void main(String[] args) { int i,j, n=9;