1.有一篇三行文字的文章,每行最多80个字符,编写一个类,由实参传递字符串,分别统计文章中大写字母、小写字母、数字、空格及其他字符的个数。
分析:自定义方法需返回多个统计结果,可采用一个专门的数组存放统计结果,并将其作为方法参数,在被调方法中计数。
2. 在5×5魔方矩阵中,每一行、每一列、每一对角线上的元素之和都是相等的。试定义一个包含下列元素的一个二维整型数组,然后检验其是否是魔方矩阵,并将其按如下格式显示到屏幕上。
17 24 1 8 15
23 5 7 14 16
4 6 13 20 22
10 12 19 21 3
11 18 25 2 9
提示:通过这个实际例子熟悉数组类型的应用场合以及数组的编程与使用方法,进一步熟悉含有选择、循环结构的程序的设计方法。3. 分析并编写一个People类,再在新类中生成10个People类对象,并放在一个一维数组中,编写方法按身高进行排序。
分析:自定义方法需返回多个统计结果,可采用一个专门的数组存放统计结果,并将其作为方法参数,在被调方法中计数。
2. 在5×5魔方矩阵中,每一行、每一列、每一对角线上的元素之和都是相等的。试定义一个包含下列元素的一个二维整型数组,然后检验其是否是魔方矩阵,并将其按如下格式显示到屏幕上。
17 24 1 8 15
23 5 7 14 16
4 6 13 20 22
10 12 19 21 3
11 18 25 2 9
提示:通过这个实际例子熟悉数组类型的应用场合以及数组的编程与使用方法,进一步熟悉含有选择、循环结构的程序的设计方法。3. 分析并编写一个People类,再在新类中生成10个People类对象,并放在一个一维数组中,编写方法按身高进行排序。
解决方案 »
- 一个计算文件 上期读数9995 本期读数10 该怎么计算
- java如何实现客户端与服务端的心跳机制
- 高难度问题,谢谢!!
- 如何将int转为long及long转int??
- Communication link failure:Bad handshake这是什么错误?
- 如何将数据库当中的图片通过方法读出来,并显示在jsp当中?
- 请问一个有小数的数字,怎么将它变成一个整数,假如有尾位就+1
- Weblogic Workshop 8.1大家觉得怎样?
- 异常一题?????????????????
- 各位高手:我想学习JAVA,听说jbuilder不错,请介绍几本入门书,多给一点见意。谢谢。
- 请教高手解决java数组输入输出的问题
- 这个例子怎么编写
第二题用多维数组做
第三题有点面向对象的意思吧 无非就是一个实现Comparable接口 看看我的这个blog吧:Java中的排序(一)
package com.tarena.wangweiwei.day07;
import java.io.* ;public class Count
{
public static void main(String[] args)throws IOException
{
String str ;
System.out.println("请输入(以回车键结束):") ;
BufferedReader buf = new BufferedReader(new InputStreamReader(System.in)) ;
str = buf.readLine() ;
int lowCount , upCount , numCount , spaceCount , otherCount ;
lowCount = lowCaseCount(str) ;
upCount = upCaseCount(str) ;
numCount = numCaseCount(str) ;
spaceCount = spaceCaseCount(str) ;
System.out.println("小写字母" + lowCount + "个!") ;
System.out.println("大写字母" + upCount + "个!") ;
System.out.println("空格字符" + spaceCount + "个!") ;
System.out.println("数字字符" + numCount + "个!") ;
}
public static int lowCaseCount(String str)
{
int count = 0 ;
for(int i = 0 ; i < str.length() ; i ++)
if(str.charAt(i) >= 'a' && str.charAt(i) <= 'z')
count ++ ;
return count ;
}
public static int upCaseCount(String str)
{
int count = 0 ;
for(int i = 0 ; i < str.length() ; i ++)
if(str.charAt(i) >= 65 && str.charAt(i) < 97)
count ++ ;
return count ;
}
public static int numCaseCount(String str)
{
int count = 0 ;
for(int i = 0 ; i < str.length() ; i ++)
if(str.charAt(i) >= '0' && str.charAt(i) <= '9')
count ++ ;
return count ;
}
public static int spaceCaseCount(String str)
{
int count = 0 ;
for(int i = 0 ; i < str.length() ; i ++)
if(str.charAt(i) == ' ')
count ++ ;
return count ;
}
}
[/code]
package com.tarena.wangweiwei.day07;
import java.io.* ;public class Count
{
public static void main(String[] args)throws IOException
{
String str ;
System.out.println("请输入(以回车键结束):") ;
BufferedReader buf = new BufferedReader(new InputStreamReader(System.in)) ;
str = buf.readLine() ;
int lowCount , upCount , numCount , spaceCount , otherCount ;
lowCount = lowCaseCount(str) ;
upCount = upCaseCount(str) ;
numCount = numCaseCount(str) ;
spaceCount = spaceCaseCount(str) ;
System.out.println("小写字母" + lowCount + "个!") ;
System.out.println("大写字母" + upCount + "个!") ;
System.out.println("空格字符" + spaceCount + "个!") ;
System.out.println("数字字符" + numCount + "个!") ;
}
public static int lowCaseCount(String str)
{
int count = 0 ;
for(int i = 0 ; i < str.length() ; i ++)
if(str.charAt(i) >= 'a' && str.charAt(i) <= 'z')
count ++ ;
return count ;
}
public static int upCaseCount(String str)
{
int count = 0 ;
for(int i = 0 ; i < str.length() ; i ++)
if(str.charAt(i) >= 65 && str.charAt(i) < 97)
count ++ ;
return count ;
}
public static int numCaseCount(String str)
{
int count = 0 ;
for(int i = 0 ; i < str.length() ; i ++)
if(str.charAt(i) >= '0' && str.charAt(i) <= '9')
count ++ ;
return count ;
}
public static int spaceCaseCount(String str)
{
int count = 0 ;
for(int i = 0 ; i < str.length() ; i ++)
if(str.charAt(i) == ' ')
count ++ ;
return count ;
}
}
[/code]