zoukankan      html  css  js  c++  java
  • 2017.12.11 String 类中常用的方法

    1、编写程序将 “jdk” 全部变为大写,并输出到屏幕,截取子串”DK” 并输出到屏幕

    package demo;
    import java.util.Scanner;
    public class demo5 {
     public static void main(String[] args) {
    	String str="jdk";
    	
    	String str1 = str.toUpperCase();//转换成大写字母
    	System.out.println(str1);
    	
    	String str2 = str1.substring(1);//获取开始字符
    	System.out.println(str2);
     }
    }
    
    public class demo5{
    	public static void main(String[] args) {
    		String str= "test";
    		StringBuffer sbf = new StringBuffer(str);
    		sbf.reverse();
    		str = sbf.toString();
    		System.out.println(str);
    	}
    }
    
    public class demo5{
    	public static void main(String[] args) {
    		String str="张三:90|李四:80|王五:100";
    		String s[] =str.split("\|");
    		
    		for(int i=0;i<s.length;i++){  //先循环第一次拆分的结果
    			String temp[] = s[i].split(":");
    			System.out.println("姓名:"+temp[0]+",成绩是:"+temp[1]);//循环输出第二次拆分的结果
    		}
    	}
    }
    
    public class demo5{
    	public static void main(String[] args) {
    		//StringBuffer sbf = new StringBuffer();
    		Scanner sc = new Scanner(System.in);
    		System.out.println("请输入一个邮箱地址(a@a.c):");
    		
    		String email = sc.next();
    		int index1 =email.indexOf("@");//通过获取下标来匹配大小的问题
    		int index2 =email.indexOf(".");
    			if(index1<index2){
    				System.out.println("邮箱格式正确");
    			}else{
    				System.out.println("邮箱格式错误");
    			}
    		}
    }
    
  • 相关阅读:
    python_django_分页
    python_django_中间件
    python_django_静态文件
    Django项目基础配置和基本使用
    python_django__验证码
    python_django_The requested URL /sunck/login/sunck/showmain/ was not found on this server.错误
    python_django_template_url反向解析
    python_django_template模块
    Andrew Ng机器学习算法入门(一):简介
    Vue.js 条件语句
  • 原文地址:https://www.cnblogs.com/qichunlin/p/8030493.html
Copyright © 2011-2022 走看看