当前位置:首页 > Java程序设计实验报告要点
HTML文档参考如下:
(3)输出下列数字形式。 ①n=4
0 0 0 0 0 1 1 1 0 1 2 2 0 1 2 3 ② n=4
1 1 2 1 1 2 3 2 1 1 2 3 4 3 2 1
(4)采用数组输出等腰三角形的杨辉三角。 (5)判断回文字符串
回文是一种“从前向后读”和“从后向前读”都相同的字符串。如“rotor”是一个回文字符串。
程序中使用了两种算法来判断回文字符串: 算法一:分别从前向后和从后向前依次获得原串str的一个字符ch1、ch2,比较ch1和ch2,如果不相等,则str肯定不是回文串,yes=false,立即退出循环:否则继续比较,直到字符全部比较完,yes的值仍为true,才能肯定str是回文串。
算法二:将原串str反转成temp串,再比较两串,如果相等则是因文字符串。
要求:
(1) 编译调试程序之前应配置好环境变量;
(2) 要分别掌握用JDK命令行和Eclipse集成开发环境调试Java程序; (3) 注意Java两大类程序:应用程序和小程序的区别。
程序清单:
(建议程序中适当添加注释信息,增强可读性;较长程序可分栏书写,保证报告排版整洁美观。)
(实验一程序清单续1) (3)①public class shuxing {
}
public static void main(String[] args) { }
int n=4;
for(int i=0;i for(int j=0;j System.out.println(); System.out.print(\+((i ②public class shuxingtower { } public static void main(String[] args) { } int n=4; for(int i=0;i<=n;i++) { } for(int j=1;j<=n-i;j++) System.out.print(\); System.out.print(\+j); System.out.print(\+j); for(int j=1;j<=i;j++) for(int j=i-1;j>0;j--) System.out.println(); (4)public class yanghui { public static void main(String[] args) { int[][] a=new int[5][5]; for(int i=0;i<5;i++) { } for(int i=2;i<5;i++) { for(int j=1;j } } } a[i][j]=a[i-1][j-1]+a[i-1][j]; for(int i=0;i<5;i++) { } for(int k=0;k<=5-i;k++) { } for(int j=0;j<=i;j++) { } System.out.println(); System.out.print(a[i][j]+\); System.out.print(\); (5)public class palindrome { } public static void main(String[] args) { } String str=\; int i=0; int n=str.length(); boolean yes=true; System.out.println(\+str); char ch1,ch2; while(yes&&(i System.out.println(\算法1: \+yes); String temp=\,sub=\; for(i=0;i System.out.println(\+temp); System.out.println(\算法2: \+str.equals(temp)); sub=str.substring(i,i+1); temp=sub+temp; ch1=str.charAt(i); ch2=str.charAt(n-i-1); if(ch1==ch2) i++; else yes=false; 四、实验结果与分析 (1) (2) (3)① ② (4) (5)
共分享92篇相关文档