当前位置: 首页 > news >正文

自己做的网站只能打开一个链接怎么做好企业网

自己做的网站只能打开一个链接,怎么做好企业网,网站变灰,小松建设官方网站六 字符串 6.1 String字符串 1、String类对象创建 定义String类对象格式#xff1a;** 1#xff09;String 字符串变量名“字符串常量”#xff1b; 2#xff09;String 字符串变量名new String(字符串常量); 3#xff09;String 字符串变量名; 字符串变量名“字符串常…六 字符串 6.1 String字符串 1、String类对象创建 定义String类对象格式** 1String 字符串变量名“字符串常量” 2String 字符串变量名new String(字符串常量); 3String 字符串变量名; 字符串变量名“字符串常量”; public class StringDemo {public static void main(String[] args) {String s1java is beautiful;//字符串变量String s2new String(hello java!);String s3;s3JAVA;System.out.println(s1);System.out.println(s2);System.out.println(s3);}} 2、String类对象的常用基本方法 字符串变量通过点“.”方式调用即字符串变量.方法名 1、获取字符串长度方法 length() 2、字符串拼接 concat() 3、字符串比较 equals() 4、字符串代替 replace() 5、去掉字符串首尾空格返回字符串 trim() 6、返回字符串对象 toString() 7、返回字符串中所有字符转变为大写的新字符串 toUpperCase() 8、获取给定的index处字符串 charAt()public class StringDemo {public static void main(String[] args) {String s1java is beautiful;//字符串变量String s2new String(hello java!);String s3;s3JAVA;String s4 java and python ;System.out.println(s1);System.out.println(s2);System.out.println(s3);System.out.println();//获取字符串的长度System.out.println(s1的长度为s1.length());//字符串拼接System.out.println(s1.concat(s2));//s2拼接到s1中//字符串比较System.out.println(JAVA.equals(s3));//两个字符串比较忽略大小写System.out.println(java.equalsIgnoreCase(s3));//字符串代替 replaceSystem.out.println(s1.replace(java, JAVA));//去掉字符串首尾空格返回字符串System.out.println(s4.trim());//返回字符串对象System.out.println(s4.toString());//返回字符串中所有字符转变为大写的新字符串System.out.println(s4.toUpperCase());//获取给定的index处字符串System.out.println(s4.charAt(1));}}运行结果 java is beautiful hello java! JAVAs1的长度为17 java is beautifulhello java! true true JAVA is beautiful java and pythonjava and python JAVA AND PYTHON j 3、遍历字符串中的所有字符并打印 public class BianliDemo {public static void main(String[] args) {String s1java is beautiful;for(int i0;is1.length();i) {System.out.print(s1.charAt(i));}}}运行结果 java is beautiful4、单词计数案例 方法一import java.util.Scanner;// 统计单词的个数。 class CountWords {public static void main(String[] args) {// 输入Scanner sc new Scanner(System.in);// 输入一行可以接收一行的数据String str sc.nextLine();// 默认有0个单词int wordcount0;// 从第一个到最后一个字符for(int i0;istr.length();i){// 如果遇到了空格表示一个单词的结束。if(str.charAt(i) ){// 累加wordcount;}}// 输出字符串System.out.println(str);// 输出单词的个数。System.out.println(wordcount1);} }方法二 import java.util.Scanner;public class WordCount {public static void main(String[] args) {//计数器int count 0 ;System.out.println(输入一系列以空格隔开的字符串);Scanner sc new Scanner(System.in);//忽略字符串头尾的空白String str sc.nextLine().trim();String[] words str.split( );for(int i 0 ; i words.length; i) {if(!words[i].equals()) {//不为空格时才计数(即只计算单词数)count;}}System.out.println(一共有count个单词);sc.close();}}6.2 StringBuffer类 ​ 当String类字符串进行拼接操作每次拼接都会构建一个新的String对象既耗时又浪费空间。而StringBuffer就可以解决这个问题线程安全的可变字符序列。 1、StringBuffer类对象创建 定义StringBuffer类对象格式 1StringBuffer 字符串变量名 new StringBuffer();//默认长度16字符 2StringBuffer 字符串变量名 new StringBuffer(缓冲区长度); 3StringBuffer 字符串变量名 new StringBuffer(“字符串常量”); public class StringBufferDemo {public static void main(String[] args) {StringBuffer s2 new StringBuffer();//默认长度16字符StringBuffer s3 new StringBuffer(50);//长度为50StringBuffer s4 new StringBuffer(i like java);System.out.println(s2s2);System.out.println(s3s3);System.out.println(s4s4);}}public class StringBufferDemo {public static void main(String[] args) {StringBuffer s1 new StringBuffer();//默认长度16字符System.out.println(s1的缓冲区长度s1.capacity());//查看对象缓冲区长度System.out.println(s1的长度s1.length());StringBuffer s2 new StringBuffer(50);//缓冲区长度为50System.out.println(s2的缓冲区长度s2.capacity());//查看对象缓冲区长度System.out.println(s2的长度s2.length());StringBuffer s3 new StringBuffer(i like java python);System.out.println(s3的缓冲区长度s3.capacity());//查看对象缓冲区长度 161127System.out.println(s3的长度s3.length());}}运行结果 s1的缓冲区长度16 s1的长度0 s2的缓冲区长度50 s2的长度0 s3的缓冲区长度34//1618 s3的长度182、StringBuffer类成员方法 1append()添加、增加public class ChengYuanWay {public static void main(String[] args) {//append:添加StringBuffer S1 new StringBuffer(i like java);System.out.println(原来的S1:S1);//append() :S1.appendS1.append(,html,web);System.out.println(添加后的S1S1);}}注意该方法多次重写public class ChengYuanWay {public static void main(String[] args) {//append:添加StringBuffer S1 new StringBuffer(i like java);System.out.println(原来的S1:S1);//append() :S1.appendS1.append(,html,web).append(,python).append(,php);System.out.println(添加后的S1S1);}} public class ChengYuanWay {public static void main(String[] args) {//append:添加StringBuffer S1 new StringBuffer(i like java);System.out.println(原来的S1:S1);//append() :S1.appendS1.append(,html,web).append(,python).append(,php语言).append(12.67);System.out.println(添加后的S1S1);}}2insert()在指定的索引上插入字符串public class InsertDemo {public static void main(String[] args) {StringBuffer Snew StringBuffer(abcd 祖国 );System.out.println(原来的SS);//insert添加元素 1找到位置 找到位置之后在这个位置添加我们要添加的元素S.insert(0, F).insert(3, G);//a索引0:0就是它的位置System.out.println(添加元素后的SS);} }append()和insert()区别a、append()只能在字符串的结尾添加而insert在指定的索引上插入字符串b、insert()两个参数第一个参数索引位置第二参数你要添加什么值 通过索引值找到位置才能添加3deleteCharAt(int index)删除指定索引的值4delete(int start,int end)删除此序列的子字符串中的字符,子串开始于指定start并延伸到字符索引end - 15replace:替换 6reverse反转7substring截取 public class StringBufferDemo {public static void main(String[] args) {// replace:替换StringBuffer s new StringBuffer();s.append(hello java);System.out.println(s);System.out.println(s.length());s.replace(6, 10, html);System.out.println(替换之后的ss);//反转:reverse()StringBuffer s1new StringBuffer();s1.append(我爱你);System.out.println(s1);s1.reverse();System.out.println(反转之后的s1s1);//截取substringStringBuffer s2new StringBuffer();s2.append(java).append( html).append( php).append( web).append(python);System.out.println(s2);String s3 s2.substring(4, 10);System.out.println(s3);}}3、统计大、小写以及数字出现次数案例 案例键盘输入字符串absDGHS345;;;统计该字符串中的大写字母、小写字母、数字字符出现的次数import java.util.Scanner;public class CountStringDemo {public static void main(String[] args) {// TODO Auto-generated method stubScanner sc new Scanner(System.in);System.out.println(请输入一串字符串);String strsc.next();int bigc0;int smallc0;int numc0;for(int i0;istr.length();i) {char cstr.charAt(i);if(ca cz) {smallc;}else if (cA cZ) {bigc;}else if (c0 c9) {numc;}}System.out.println(大写字母有bigc个);System.out.println(小写字母有smallc个);System.out.println(数字有numc个);}}
http://www.hkea.cn/news/14540584/

相关文章:

  • 周口网站seo久久建筑网账号
  • 福永自适应网站建公众号做网站
  • 手机网站导航设计模板建企业网站怎么做
  • 北京网站优化 卓立海创wordpress缩略图延时加载
  • 怎么制作免费的企业网站银行网站建设公司
  • 做软装什么网站可以吗微信平台app网站建设
  • 校园网站建设的要素软件技术培训
  • 同学聚会怎么样做网站wordpress多张页面左右翻
  • 网站开发费应该入什么科目梅河口建设局网站
  • 网站搭建周期免费个人网站建站申请
  • 微信二维码网站建设开一个小程序要多少钱
  • 网站建设要如何选择福州市建设工程工料机信息网站
  • 广东企业网站seo哪里好企业网站托管价格
  • phpmysql网站设计工业设计产品效果图
  • 网站备案地区名米趋外贸网站建设
  • 网站建设员课程电子商务网站建设与管理 李建忠
  • 小程序登录入口网页版系统优化工具是什么软件
  • 网站建设需要会什么软件上海建设学院网站
  • 删除百度收录的网站wordpress文章部分展示
  • 保定电子商务网站建设上海十大设计公司有哪些
  • 产品介绍网站如何做seo河北康城建设集团网站
  • 中山祥云网站建设网站的百度百科怎么做
  • 怎么申请网站用wordpress修改现有网页
  • 网站关键词没有指数安康市建设银行网站
  • 广州平台网站建设浏览网站模板
  • 昆山高端网站建设咨询wordpress 图片本地化
  • 深圳高端网站开发东莞公司官网推广
  • 凡科建站代理太原做网站价格
  • 网站建设所需技术营销型网站主机
  • 建设网站需要考虑什么郑州网站建设哪家公司好