Java 0723 第十次课作业

1。从键盘输入一个字符串
   编写一个程序,判断输出一个字符串中大写英文字母数,和小写英文字母数,和其他非英文字母数

import java.util.Scanner;

public class Work1 {
    public static void main(String[] args){
        System.out.println("请输入:");
        Scanner scan = new Scanner(System.in);//键盘输入
        String ss = scan.next();
        int a1 = 0;
        int a2 = 0;
        int b = 0;
        for(int i=0; i<ss.length(); i++){
            char c = ss.charAt(i);              //获取索引处字符
            if('a'<=c && c<='z'){             //判断小写字母
                a1++;
            }else if('A'<=c && c<='Z'){          //判断大写字母
                a2++;
            }else{                              //其他字符
                b++;
            }

        }
        System.out.println("大写字母:"+a1);   //输出
        System.out.println("小写字母: "+a2);
        System.out.println("非英文字母:"+b);
    }

}

2.
编写一个方法,返回一个double类型的二维数组,数组中的元素通过解析字符串参数获得,如字符串参数为“1,2;3,4,5;6,7,8;9”的参数


public class TestString
{
    public static void main(String[] args)
    {
        double[][] d;                         //定义double类型二位数组
        String s = "1,2;3,4,5;6,7,8;9";
        String[] s1 = s.split(";");           //以;进行分割
        d = new double[s1.length][];
        for(int i=0; i<s1.length; i++)
        {
            String[] s2 = s1[i].split(",");   //以,进行分割
            d[i] = new double[s2.length];
            for(int j=0; j<s2.length; j++)
            {
                d[i][j] = Double.parseDouble(s2[j]);  //转为double类型
            }
        }
         
        for(int i=0; i<d.length; i++)            //循环输出
        {
            for(int j=0; j<d[i].length; j++)
            {
                System.out.print(d[i][j] + " ");
            }
            System.out.println();
        }
    }      
}

 

转载于:https://my.oschina.net/u/3858331/blog/1861960

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值