摘要: `for key in 字典 for value in 字典.values() for key, value in 字典.items()` 阅读全文
posted @ 2021-12-30 12:03 漂流海上的草帽 阅读(38) 评论(0) 推荐(0) 编辑
摘要: 带遍历 public class Test4 { public static void main(String[] args) { HashMap<Phone,String> map = new HashMap<>(); map.put(new Phone("Apple",7000),"美国"); 阅读全文
posted @ 2021-09-13 21:17 漂流海上的草帽 阅读(37) 评论(0) 推荐(0) 编辑
摘要: dict1={'name':'Lara','age':18} #判断键在不在字典中 for one in dict1: if 'name' in dict1:#或dict1.keys() print('key在字典中!') break #判断值在不在字典中 for one in dict1: if 阅读全文
posted @ 2021-04-15 19:36 漂流海上的草帽 阅读(1026) 评论(0) 推荐(0) 编辑
摘要: 用法见代码: `#include #include std::set s; using namespace std; int main() { int n; while (cin>>n) { int a; for(int i=0;i<n;i++) { cin>>a; s.insert(a); } s 阅读全文
posted @ 2021-04-01 16:40 漂流海上的草帽 阅读(668) 评论(0) 推荐(0) 编辑
摘要: 类方法:加static 对象方法:不加static,但要实例化对象才可以使用 方法的重载:在同一个类里面,相同函数名称,不同的参数 可变参数:一个方法中只能指定一个可变参数,且它必须是方法的最后一个参数,定义方式为指定参数类型后加省略号(...) package com.kuang.method; 阅读全文
posted @ 2021-03-28 19:47 漂流海上的草帽 阅读(25) 评论(0) 推荐(0) 编辑
摘要: 变量篇 类变量:前面要加static关键字,可以在自身类方法里面直接用 实例变量:不需要加static关键字,从属于对象,不初始化有默认值,除了基本类型都是null。要使用必须要有实例化对象,通过对象.xxx(如student.age)来使用 常量:在前面加final关键字 package com. 阅读全文
posted @ 2021-03-28 15:37 漂流海上的草帽 阅读(118) 评论(0) 推荐(0) 编辑
摘要: 类变量:前面要加static关键字,可以在自身类方法里面直接用 实例变量:不需要加static关键字,从属于对象,不初始化有默认值,除了基本类型都是null。要使用必须要有实例化对象,通过对象.xxx(如student.age)来使用 常量:在前面加final关键字 package com.kuan 阅读全文
posted @ 2021-03-28 15:01 漂流海上的草帽 阅读(47) 评论(0) 推荐(0) 编辑
摘要: treeset为有序的集合,不含重复元素且有序 import java.util.*;//引用全部 public class Test { public static void main(String[] args) { Scanner sc = new Scanner(System.in); // 阅读全文
posted @ 2021-03-25 18:12 漂流海上的草帽 阅读(167) 评论(0) 推荐(0) 编辑
摘要: 直接上代码: #include <iostream> #include <set> using namespace std; int N; set<int> s; int main() { int a; while (cin >> N) { for (int i = 0; i < N; i++) { 阅读全文
posted @ 2021-03-25 18:01 漂流海上的草帽 阅读(187) 评论(0) 推荐(0) 编辑
摘要: Arrays即数组,长度不可变,但一般定义时直接使用如下方式定义就好: int[] num=new int[100];int[] num=new int[]{1,2,3,4};String[] aArray = new String[5];//每一元素都是字符串的数组//数组一定要初始化(使用new 阅读全文
posted @ 2021-03-25 17:04 漂流海上的草帽 阅读(74) 评论(0) 推荐(0) 编辑