吉软-人文精英班-第十次作业

1。从键盘输入一个字符串
   编写一个程序,计算输出一个字符串中大写英文字母数,和小写英文字母数,和其他非英文字母数
2.
编写一个方法,返回一个double类型的二维数组,数组中的元素通过解析字符串参数获得,

如字符串参数为“1,2;3,4,5;6,7,8;9”的参数

/*
*第一题
*/
package org.jsoft.zuoye;

import java.util.Scanner;

public class CharactersMum {
	public static void main(String[] args) {
		//输出一个字符串中大写英文字母数,和小写英文字母数,和其他非英文字母数
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			String str = sc.nextLine();
			char []c = new char [str.length()];
			c = str.toCharArray();//转化成字符数组
			int n1=0,n2=0,n3=0;
			for(int i = 0; i < c.length; i++){
				if(c[i]>='A'&&c[i]<='Z'){
					n1++;//大写字母数
				}else if(c[i]>='a'&&c[i]<='z'){
					n2++;//小写字母数
				}else{
					n3++;//非英文字母数
				}
			}
			System.out.println("大写字母数:"+n1);
			System.out.println("小写字母数:"+n2);
			System.out.println("其他非字母数:"+n3);
		}
		sc.close();
	}

		
}

/*
* 第二题
*/
package org.jsoft.zuoye;

public class ParseString {
	//编写一个方法,返回一个double类型的二维数组,数组中的元素通过解析字符串参数获得
	//如字符串参数为“1,2;3,4,5;6,7,8;9”的参数
	public static double[][] parseString(String str){
		//用split()方法分解
		//1.先split(";")分解成一维(行)
		//2.在用split(",")分解成二维(列)
		//3.用一个二位数组装分解好的字符
		double [][]result;
		String []sFirst = str.split(";");//第一次分解
		int l = sFirst.length;
		result = new double [l][];//先设置多少行
		
		for(int i = 0 ; i < l ; i++){
			String sSecond[] = sFirst[i].split(",");//第二次分解
			int l2 = sSecond.length;
			result[i] = new double [l2];//再设置多少列
			for(int j = 0 ; j < l2 ; j++){
				result[i][j] = Double.valueOf(sSecond[j]);//将String转换成Double
			}
		}
		return result;
	}
	public static void main(String[] args) {
		String s = "1,2;3,4,5;6,7,8;9";
		double arraySecond [][];
		arraySecond = parseString(s);
		//输出二维数组
		for(int i = 0 ; i < arraySecond.length ; i++){
			for(int j = 0 ; j <arraySecond[i].length ; j++){
				System.out.print(arraySecond[i][j]+" ");
			}
			System.out.println();
		}
	}
}

转载于:https://my.oschina.net/u/3863623/blog/1861622

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值