zoukankan      html  css  js  c++  java
  • 4Java字符串注意事项

    课后作业编码

    • 字符的使用
    public class Homework02{
    
    	public static void main(String[] args) {
    		
    		char c1 = '\n';
    		char c2 = '\t';
    		char c3 = '\\';
    		char c4 = '\r';
    		char c5 = '1';
    		char c6 = '2';
    		char c7 = '3';
    		System.out.println("开始");
    		System.out.println(c1);
    		System.out.println(c2);
    		System.out.println(c3);
    		System.out.println(c4);
    		System.out.println(c5);
    		System.out.println(c6);
    		System.out.println(c7);
    
    	}
    }
    
    1. 注意事项,""代表是字符串,所以字符需要''
    2. 字符串相加,代表的是两个数字相加,不是跟字符串一样
    public class Homework03{
    	public static void main(String[] args) {
    		
    		String bookName1 = "唐诗300";
    		String bookName2 = "小王子";
    
    		char sex1 = '男';
    		char sex2 = '女';
    
    		double price1 = 123.12;
    		double price2 = 34.2;
    
    		System.out.println(bookName1 + bookName2);
    		System.out.println(sex1 + sex2);
    		System.out.println(price1 + price2);
    
    	}
    }
    
    • 转义字符的使用
    public class Homework04{
    
    	public static void main(String[] args) {
    		
    		String name = "金先生";
    		int age = 12;
    		double grade = 99;
    		char sex = '男';
    		String hobby = "打羽毛球";
    
    		System.out.println("姓名\t年龄\t成绩\t性别\t爱好\n" + 
    			name + "\t" + age + "\t" + grade + "\t" + sex + "\t" + hobby);
    	}
    }
    
  • 相关阅读:
    Playwright安装及基本用法
    生成随机数、随机字符串
    xmind2testcase使用
    jmeter5.0二次开发环境搭建(IDEA)
    pytest配置文件pytest.ini
    pytest+allure2生成测试报告
    pytest生成html报告-使用pytest-html插件方式
    pytest一些简单参数
    pytest简单搭建和入门
    python3学习-元组
  • 原文地址:https://www.cnblogs.com/jly1/p/15621404.html
Copyright © 2011-2022 走看看