输入一个长度
,仅由图片中的可见字符构成的字符串
。
在一行上输出一个整数,代表给定字符串中 ASCII 码在
到
范围内的不同字符的个数。
[@A8aA].0
8
import java.util.Scanner; import java.util.*; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); // 注意 hasNext 和 hasNextLine 的区别 String str = in.nextLine(); Set<Integer> num = new HashSet<>(); for (int i = 0; i < str.length(); i++) { num.add((int)str.charAt(i)); } System.out.println(num.size()); } }
import java.util.Scanner;
import java.util.LinkedHashSet;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) { Scanner in = new Scanner(System.in); // 注意 hasNext 和 hasNextLine 的区别
// 注意 while 处理多个 case
String a = in.nextLine(); LinkedHashSetInteger> set = new LinkedHashSet(); for(int i=0;ia.length();i++){ int b = (int)a.charAt(i); if(b>=0&&b127){ set.add(b); } } System.out.print(set.size()); }
}
import java.util.HashSet; import java.util.Scanner; import java.util.Set; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); // 注意 hasNext 和 hasNextLine 的区别 String str = in.nextLine(); int count =0;zz Set s = new HashSet<Character>(); for(int i =0; i< str.length();i++){ Character c = str.charAt(i); try{ int a = c; if(a >=0 && a<=127){ s.add(a); } }catch(Exception e){ continue; } } System.out.println(s.size()); } }
import java.util.*; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); String str=in.nextLine(); //set容器不允许有重复的元素,所以用set容器存储字符 HashSet<Character> set= new HashSet<Character>(); for(int i=0;i<str.length();i++){ if(str.charAt(i)>=0 && str.charAt(i)<=127){ set.add(str.charAt(i)); } } System.out.println(set.size()); } }
import java.util.*; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); String str = in.nextLine(); //使用HashSet存储不同的字符 Set<Character> chars = new HashSet<>(); for (int i = 0; i < str.length(); i++) { // 将字符添加到HashSet中,自动去重 chars.add(str.charAt(i)); } System.out.println(chars.size()); } }
import java.util.ArrayList; import java.util.List; import java.util.Scanner; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); List<Character> list = new ArrayList<>(); String str = in.nextLine(); for (int i = 0; i < str.length(); i++) { char c = str.charAt(i); if (!list.contains(c)) { list.add(c); } } System.out.println(list.size()); } }
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); String str = in.nextLine(); System.out.println(str.chars().distinct().count()); } }
import java.util.Scanner; import java.util.List; import java.util.ArrayList; public class Main { public static void main(String[] args){ List<String> list = new ArrayList<>(); Scanner in = new Scanner(System.in); while(in.hasNext()) { String str = in.nextLine(); String strs[] = str.split(""); for(int i=0;i<strs.length;i++){ //如果List中不存在就添加,存在就不添加 if(!list.contains(strs[i])){ list.add(strs[i]); } } System.out.println(list.size()); //因为是循环输入,上次记录的结果要清空 list.clear(); } in.close(); } }
import java.util.*; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); // 注意 hasNext 和 hasNextLine 的区别 //while (in.hasNextInt()) { // 注意 while 处理多个 case String a = in.nextLine(); // int b = in.nextInt(); // System.out.println(a + b); // } HashSet<Character> set = new HashSet<>(); for(char ch: a.toCharArray()){ set.add(ch); } System.out.println(set.size()); } }
import java.util.*; import java.util.stream.Collectors; import java.util.HashSet; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); // System.out.println("请输入要统计的字符串:"); String next = sc.next(); HashSet<Character> uniqueChars = new HashSet<>(); for (char c : next.toCharArray()) { if(c>=0 && c<=127){ uniqueChars.add(c); } } System.out.println(uniqueChars.size()); } }
import java.util.HashSet; import java.util.Scanner; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); // 注意 hasNext 和 hasNextLine 的区别 String str = in.nextLine(); int length = str.length(); HashSet<Character> Hashset = new HashSet<>(length); for (int i =0;i<length;i++){ Hashset.add(str.charAt(i)); } System.out.println(Hashset.size()); } }