Java基础

1.输出数组内所有内容

		System.out.println(Arrays.toString(temp)); //输出格式为“[100, 1000, 1001]”, 有时不会通过一些题目
		
		for(int i=0; i<M; i++) {
			System.out.println(temp[i]);
		}

输出:

[100, 1000, 1001]

100
1000
1001

2.由控制台输入的代码

		Scanner sc = new Scanner(System.in);  
		int m = sc.nextInt();
		System.out.println(m);

输出:

10
10

3.判断map中是否存在某key值

map.containsKey(key)

此方法返回为 boolean 类型,若存在返回 true, 不存在返回 false.

代码举例:

public static void main(String[] args) {
		Map<String, String> map = new HashMap<>();
		String key = "key";
		String value = "value";
		map.put("key", "value");
		if(map.containsKey("key")) System.out.println("map中存在key为 'key' 的值");
	}

输出:在这里插入图片描述

4.int型转化String字符型、反转字符串、n的次方

		int x = 123;
		String s = Integer.toString(x);
		String sb = new StringBuffer(s).reverse().toString();
		int y = (int) Math.pow(2, 5);
		System.out.println(s);
		System.out.println(sb);
		System.out.println(y);

输出:在这里插入图片描述

5.substring , charAt , indexOf 用法

		String str = "abcdefgaaa";
		System.out.println(str.substring(2));
		System.out.println(str.substring(2, 5));
		System.out.println(str.charAt(2));
		System.out.println(str.indexOf("abc"));
		System.out.println(str.indexOf("a", 2));

输出:
在这里插入图片描述

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值