新网创想网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
public class myTest
创新互联建站提供网站设计制作、成都做网站、网页设计,品牌网站制作,一元广告等致力于企业网站建设与公司网站制作,10多年的网站开发和建站经验,助力企业信息化建设,成功案例突破上1000家,是您实现网站建设的好选择.
{
public static void main(String[] args)
{
String[] strArr = { "010", "3223", "666", "灶斗7890987", "123123" };
System.out.println(getSymmetricString(strArr));
}
public static String getSymmetricString(String[] strArr)
{
String allInfo = "";
int sum = 0;
for (String str : strArr)
{
boolean flag = true;
for (int i = 0; 判返i str.length() / 2; i++)
{
String bgnStr = str.substring(i, i + 1);
String endStr = str.substring(str.length() - (i + 1), str.length() - i);
if (!bgnStr.equals(endStr))
{
flag = false;
break;
}
}
if (flag)
{
allInfo = allInfo + str + "是对称的,对称的数量为:" + str.length() / 2 + "\n";
sum++;
}
else
{
allInfo = allInfo + str + "不是对称的隐冲磨" + "\n";
}
}
return allInfo + "\n对称字符的个数为:" + sum;
}
}
运行代码
具体的代码如下:
import java.util.HashMap;
public class SearchDemo {
public HashMapInteger,Integer countMap(char[] arr){
HashMap countMap = new HashMapInteger, Integer();
for (int i = 0; i arr.length; i++) {
if(!countMap.containsKey(arr[i])){
countMap.put(arr[i],1);
}else{
int value = (int)countMap.get(arr[i]) + 1;
countMap.put(arr[i],value);
}
}
return countMap;
}
public static void main(String[] args) {
char[] arr={'A','1','R','告空!','e','','A','5','A','g','#'含丛,'D'};
int count = new SearchDemo().countMap(arr).get('A');
System.out.println("其中'A'字符的个数袜老瞎是:" + count);
}
}
运行结果
按照题目要求编写的用javaBean规范设计的学生类Student的Java程序如下
需要创建user.java.test包,把Student.java文件和Test.java文件放入包中,编译Student.java文件并且编译运行Test.java文件得到运行结果
Student.java文件扮租代码如下
package user.java.test;
import java.io.Serializable;
public class Student implements Serializable{
private static final long serialVersionUID = 1L;
private String no;
private String name;
private double score;
public Student(){}
public Student(String no,String name,double score){
this.no=no;
this.name=name;
this.score=score;
}
public String getNo(){ return no;}
public void setNo(String no){ this.no=no;}
public String getName(){ return name;}
public void setName(String name){ this.name=name;}
public double getScore(){ return score;}
public void setScore(double score){ this.score=score;}
public String toString(){
return "学号:"+no+",姓名:"+name+",成绩:"+score;
}
public static double getAvg(Student[] sArray){
double sum=0,avg;
for(int i=0;isArray.length;i++){
sum=sum+sArray[i].getScore();
}
avg=sum/sArray.length;
return avg;
}
}
Test.java文件代码如下
package user.java.test;
public class Test{
public static void main(String[] args){
Student[] sArray=new Student[5];
sArray[0]=new Student("001","张三",89.5);
sArray[1]=new Student("002","李四",82.5);
sArray[2]=new Student("003","王五",93);
sArray[3]=new Student("004"皮缺和,"赵六",73.5);
sArray[4]=new Student("005","燃盯孙七",66);
System.out.println("这些学生的平均分:"+Student.getAvg(sArray));
for(int i=0;isArray.length;i++){
System.out.println(sArray[i].toString());
}
}
}