当前位置:网站首页>Experiment 7 use of common classes (correction post)
Experiment 7 use of common classes (correction post)
2022-07-06 13:55:00 【Wen Wen likes Guo Zia】
Thank you very much for discovering and pointing out the mistakes in my experimental report in time , The following amendments are made to the two existing problems :
2. Enter a string of characters from the keyboard , How many different characters are output 、 The number of occurrences of each character .
package code72;
import java.util.Scanner;
import java.util.HashMap;
public class code72 {
public static void main(String[] args) {
Scanner in=new Scanner(System.in);
System.out.println(" Please enter a string of characters :");
String str=in.nextLine();
StringBuffer b=new StringBuffer(str); // Insert string buffer StringBuffer
int length=b.length(); // The total number of characters
str=str.toLowerCase(); // Convert all uppercase letters of the input string to lowercase letters
int c=0;
HashMap hm=new HashMap();
for(int i=0;i<str.length();i++) {
char ch=str.charAt(i); // Returns the char value
if((ch>='a'&&ch<='z')) {
if(!hm.containsKey(ch)) { // Determine whether the specified key name is included
hm.put(ch,new Integer(1)); //put Method , You can send a single message to HashMap Add a key value pair to the
c++;
}
else {
Integer d=(Integer)hm.get(ch)+1;
hm.put(ch,d);
}
}
}
System.out.println(" The total number of different characters is :"+c);
String a; // Declare a single character
int index,sum;
for(int i=0;i<b.length();) {
sum=0;
a=b.substring(0,1); // Intercept a single character
index=b.indexOf(a); // Search for the position of a single character in the whole string
while(index!=-1) {
sum++;
b.deleteCharAt(index); // Delete character
index=b.indexOf(a,index); // Count the times
}
System.out.println(a+" The letters have "+sum+" individual !");
}
}
}
4. Enter an octal digit string ( Within the range of integer data ), Respectively by 2 Base number 、10 Base number 、16 Binary output .
Tips :Integer.parseInt("100",8); // take 8 Base number 100 Convert to decimal number
Integer.toBinaryString(100); // Decimal integer 100 Convert to binary
package code74;
import java.util.Scanner;
public class code74 {
public static void main(String[] args) {
Scanner in=new Scanner(System.in);
System.out.println(" Enter an octal digit string ( Within the range of integer data ):");
String a=in.nextLine(); // Enter the original string
int b=Integer.parseInt(a); // Convert the original string to a number
System.out.println("2 Into the system for :"+Integer.toBinaryString(b)); // take b Convert to 2 Hexadecimal number
System.out.println("10 Into the system for :"+Integer.parseInt(a,8)); // take b Convert to 10 Hexadecimal number
System.out.println("16 Into the system for :"+Integer.toHexString(b)); // take b Convert to 16 Hexadecimal number
}
}
My knowledge is still shallow , I sincerely hope that some friends can point out my mistakes and put forward valuable suggestions , I will correct and adopt it in time , Strive to present better content for your reference and learning , At the same time, I hope we can make progress together !
边栏推荐
- FAQs and answers to the imitation Niuke technology blog project (II)
- 实验五 类和对象
- 【VMware异常问题】问题分析&解决办法
- [the Nine Yang Manual] 2019 Fudan University Applied Statistics real problem + analysis
- Reinforcement learning series (I): basic principles and concepts
- 强化学习基础记录
- 这次,彻底搞清楚MySQL索引
- [the Nine Yang Manual] 2020 Fudan University Applied Statistics real problem + analysis
- String abc = new String(“abc“),到底创建了几个对象
- 实验七 常用类的使用
猜你喜欢
Leetcode. 3. Longest substring without repeated characters - more than 100% solution
强化学习系列(一):基本原理和概念
SRC挖掘思路及方法
强化学习基础记录
透彻理解LRU算法——详解力扣146题及Redis中LRU缓存淘汰
实验六 继承和多态
强化学习基础记录
2022 Teddy cup data mining challenge question C idea and post game summary
A piece of music composed by buzzer (Chengdu)
MySQL事务及实现原理全面总结,再也不用担心面试
随机推荐
Relationship between hashcode() and equals()
7-3 构造散列表(PTA程序设计)
[modern Chinese history] Chapter 6 test
附加简化版示例数据库到SqlServer数据库实例中
编写程序,模拟现实生活中的交通信号灯。
Renforcer les dossiers de base de l'apprentissage
MySQL中count(*)的实现方式
强化学习基础记录
The difference between abstract classes and interfaces
Zatan 0516
2022 Teddy cup data mining challenge question C idea and post game summary
Write a program to simulate the traffic lights in real life.
强化学习系列(一):基本原理和概念
Detailed explanation of redis' distributed lock principle
SRC mining ideas and methods
canvas基础2 - arc - 画弧线
Package bedding of components
Using qcommonstyle to draw custom form parts
Redis的两种持久化机制RDB和AOF的原理和优缺点
The difference between cookies and sessions