JAVA的心动之旅

Day1 字符串String

1.0 字符串的特点以及创建一个字符串

public class Practice {//构建字符串的3+1种方法
public static void main(String[] args) {
//第一种
String one=new String();
System.out.println("输出的字符串为:"+one);
//第二种
char str[]={'A','B','C'};
String two=new String(str);
System.out.println("输出的字符串为:"+two);
//第三种
byte []bytes={97,98,99,100};
String three=new String(bytes);
System.out.println("输出的字符串为:"+three);
//+1种 直接构造 字符串常量不可改变
String four="HelloWorld";
System.out.println("输出的字符串为:"+four); }
}

打印结果:

输出的字符串为:
输出的字符串为:ABC
输出的字符串为:abcd
输出的字符串为:HelloWorld

2.0 字符串的常量池

3.0 字符串的获取方法

public class Practice {
public static void main(String[] args) {
String one="Hello";
System.out.println("字符串的长度为:"+one.length());
String two="say ".concat(one);
System.out.println("字符串为:"+two);
for(int i=0;i<two.length();i++)
{
char ch=two.charAt(i);
System.out.print(ch+" ");
}
String three="o";
System.out.println("\n"+one.indexOf(three));
String four="h";
System.out.println(one.indexOf(four));
}
}

打印结果

字符串的长度为:5
字符串为:say Hello
s a y H e l l o
4
-1

4.0 字符串的比较 ==为地址的比较

5.0 字符串的截取

public class Practice {
public static void main(String[] args) {
String one="hellobts";
String two=one.substring(5);
System.out.println(two);
String three=one.substring(0, 5);
System.out.println(three);
}
}

打印结果:

bts
hello

6.0 字符串的转化方法

public class Practice {
public static void main(String[] args) {
String one="hellobts";
char a[]=one.toCharArray();
for(int i=0;i<a.length;i++)
{
System.out.print(a[i]+" ");
}
System.out.println();
byte []bytes=one.getBytes();
for(int i=0;i<bytes.length;i++)
{
System.out.print(bytes[i]+" ");
}
System.out.println();
String two=one.replace("hello", "love");
System.out.println(two);
}
}

打印结果:

h e l l o b t s
104 101 108 108 111 98 116 115
lovebts

Day2 static 关键字

1.0 static 概述

一旦用了static 关键字,那么这样的内容不再属于对象自己,它是属于类的,所以凡是本类的对象,都共享一份。

2.0 static 修饰成员变量

public class Students {
private static int idcounter=0;//每当创建一个对象(new)计数器++
static String room;
private String name;
private int age;
private int id;
public Students() {
this.id=++idcounter;
}
public Students(String name, int age) {
this.name = name;
this.age = age;
this.id=++idcounter;
} public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
} }
public class Practice {
public static void main(String[] args) {
Students one=new Students("田小娟",22);
one.room="101教室";
Students two=new Students("徐穗珍",22);
System.out.println("姓名:"+one.getName()+" "+"年龄:"+one.getAge()+" 教室:"+one.room+
" 学号"+one.getId());
System.out.println("姓名:"+two.getName()+" "+"年龄:"+two.getAge()+" 教室:"+two.room+
" 学号"+two.getId());
}
}

3.0 static 修饰方法

4.0 静态代码块

Day3 与Arrays相识

1.0 简单的应用

import java.util.Arrays;

public class Practice {
public static void main(String[] args) {
int []num={3,89,45,235,43,79};
String str=Arrays.toString(num);
System.out.println(str);
Arrays.sort(num);
for(int i=0;i<num.length;i++)
{
System.out.print(num[i]+" ");
}
}
}

打印结果:

[3, 89, 45, 235, 43, 79]
3 43 45 79 89 235

2.0 字符串倒序

import java.util.Arrays;

public class Practice {
public static void main(String[] args) {
String str="aihfjsdfhuwefwnf";
//定义一个随机的字符串,并将字符串排序后倒序输出
//需将字符串先转化为字符数组,才能使用Arrays
char []chars=str.toCharArray();
Arrays.sort(chars);
for(int i=chars.length-1;i>=0;i--)
{
System.out.print(chars[i]+" ");//w w u s n j i h h f f f f e d a
} }
}

 Math类方法(百度)

JAVA自学笔记(3)的更多相关文章

  1. JAVA自学笔记09

    JAVA自学笔记09 1.子类的方法会把父类的同名方法覆盖(重写) 2.final: 1)可修饰类.方法.变量 2)修饰类时:此时该类变为最终类,它将无法成为父类而被继承 3)修饰方法时:该方法将无法 ...

  2. JAVA自学笔记05

    JAVA自学笔记05 1.方法 1)方法就是完成特定功能的代码块,类似C语言中的函数. 2)格式: 修饰符 返回值类型 方法名(参数类型 参数名1,参数类型 参数名2,-){ 函数体; return ...

  3. JAVA自学笔记06

    JAVA自学笔记06 1.二维数组 1)格式: ①数据类型[][]数组名 = new 数据类型[m][n]; 或 数据类型[]数组名[]=new 数据类型[m][n]; m表示这个二维数组有多少个一维 ...

  4. JAVA自学笔记04

    JAVA自学笔记04 1.switch语句 1)格式:switch(表达式){ case 值1: 语句体1; break; case 值2: 语句体2; break; - default: 语句体n+ ...

  5. JAVA自学笔记07

    JAVA自学笔记07 1.构造方法 1) 例如:Student s = new Student();//构造方法 System.out.println(s);// Student@e5bbd6 2)功 ...

  6. JAVA自学笔记10

    JAVA自学笔记10 1.形式参数与返回值 1)类名作为形式参数(基本类型.引用类型) 作形参必须是类的对象 2)抽象类名作形参 需要该抽象类的子类对象,通过多态实现 3)接口名为形参 需要的是该接口 ...

  7. JAVA自学笔记13

    JAVA自学笔记13 1.StringBuffer类 1)线程安全的可变字符序列 线程安全(即同步) 2)StringBuffer与String的区别:一个可变一个不可变 3)构造方法: ①publi ...

  8. JAVA自学笔记11

    JAVA自学笔记11 1:Eclipse的安装 2:用Eclipse写一个HelloWorld案例,最终在控制台输出你的名字 A:创建项目 B:在src目录下创建包.cn.itcast C:在cn.i ...

  9. JAVA自学笔记14

    JAVA自学笔记14 1.正则表达式 1)是指一个用来描述或者匹配一系列符合某个句法规则的字符串的单个字符串.其实就是一种规则.有自己的特殊应用 2)组成规则: 规则字符在java.util.rege ...

  10. JAVA自学笔记12

    JAVA自学笔记12 1.Scanner 1)JDK5后用于获取用户的键盘输入 2)构造方法:public Scanner(InputStream source) 3)System.in 标准的输入流 ...

随机推荐

  1. Android自定义顶部栏及侧滑菜单和fragment+viewpag滑动切换的实现

    嘿嘿嘿,关于android滑动的操作,是不是经常都会用到呢. 我肯定也要学习一下啦. https://blog.csdn.net/u013184970/article/details/82882107 ...

  2. RabbitMQ的轮询模式和公平分发

    一.常用的消息模式 我们在工作的使用中,经常会遇到多个消费者监听同一个队列的情况,模型如下图所示: 当有多个消费者时,我们的消息会被哪个消费者消费呢,我们又该如何均衡消费者消费信息的多少呢: 主要有两 ...

  3. 【Kafka】Kafka简单介绍

    目录 基本介绍 概述 优点 主要应用场景 Kafka的架构 四大核心API 架构内部细节 基本介绍 概述 Kafka官网网站:http://kafka.apache.org/ Kafka是由Apach ...

  4. 网页爬虫--python3.6+selenium+BeautifulSoup实现动态网页的数据抓取,适用于对抓取频率不高的情况

    说在前面: 本文主要介绍如何抓取 页面加载后需要通过JS加载的数据和图片 本文是通过python中的selenium(pyhton包) + chrome(谷歌浏览器) + chromedrive(谷歌 ...

  5. FF按钮点击后表单提交

    如果发现<button>提交</button>点击后,所在的表单在ff中自动提交了,则需要添加属性 type='button'! 我也是百度的,记在这里以后方便查看!

  6. mp4封装格式各box类型讲解及IBP帧计算

    mp4封装格式各box类型讲解及IBP帧计算 目录 mp4封装格式各box类型讲解及IBP帧计算 box ftyp box moov box mvhd box (Movie Header Box) t ...

  7. Codeforces1176B(B题)Merge it!

    B. Merge it! You are given an array aanna1,a2,…,ana1,a2,…,an In one operation you can choose two ele ...

  8. python迭代器,生成器

    1. 迭代器 迭代器是访问集合元素的一种方式.迭代器对象从集合的第一个元素开始访问,直到所有的元素被访问完结束.迭代器只能往前不会后退,不过这也没什么,因为人们很少在迭代途中往后退.另外,迭代器的一大 ...

  9. 《C程序设计语言》 练习3-5

    问题描述 练习 3-5 编写函数 itob(n, s, b),将整数n转换为以b为底的数,并将转换结果以字符的形式保存到字符串s中.例如,itob(n, s, 16)把整数n格式化成十六进制整数保存在 ...

  10. 教你避过安装TensorFlow的两个坑

    TensorFlow作为著名机器学习相关的框架,很多小伙伴们都可能要安装它.WIN+R,输入cmd运行后,通常可能就会pip install tensorflow直接安装了,但是由于这个库比较大,接近 ...