当前位置:网站首页>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 !
边栏推荐
- 为什么要使用Redis
- [au cours de l'entrevue] - Comment expliquer le mécanisme de transmission fiable de TCP
- 深度强化文献阅读系列(一):Courier routing and assignment for food delivery service using reinforcement learning
- 附加简化版示例数据库到SqlServer数据库实例中
- 1143_ SiCp learning notes_ Tree recursion
- [面試時]——我如何講清楚TCP實現可靠傳輸的機制
- 【黑马早报】上海市监局回应钟薛高烧不化;麦趣尔承认两批次纯牛奶不合格;微信内测一个手机可注册俩号;度小满回应存款变理财产品...
- [insert, modify and delete data in the headsong educator data table]
- 【VMware异常问题】问题分析&解决办法
- 透彻理解LRU算法——详解力扣146题及Redis中LRU缓存淘汰
猜你喜欢

Strengthen basic learning records

Leetcode.3 无重复字符的最长子串——超过100%的解法

【手撕代码】单例模式及生产者/消费者模式

4. Branch statements and loop statements

强化学习基础记录

Cookie和Session的区别

透彻理解LRU算法——详解力扣146题及Redis中LRU缓存淘汰

Reinforcement learning series (I): basic principles and concepts

强化学习基础记录

Service ability of Hongmeng harmonyos learning notes to realize cross end communication
随机推荐
[three paradigms of database] you can understand it at a glance
[data processing of numpy and pytoch]
7-11 机工士姆斯塔迪奥(PTA程序设计)
C language Getting Started Guide
[面试时]——我如何讲清楚TCP实现可靠传输的机制
Zatan 0516
[the Nine Yang Manual] 2021 Fudan University Applied Statistics real problem + analysis
FAQs and answers to the imitation Niuke technology blog project (I)
记一次猫舍由外到内的渗透撞库操作提取-flag
重载和重写的区别
Principles, advantages and disadvantages of two persistence mechanisms RDB and AOF of redis
Detailed explanation of redis' distributed lock principle
7-9 制作门牌号3.0(PTA程序设计)
强化學習基礎記錄
Mortal immortal cultivation pointer-1
Mortal immortal cultivation pointer-2
关于双亲委派机制和类加载的过程
Canvas foundation 1 - draw a straight line (easy to understand)
抽象类和接口的区别
Yugu p1012 spelling +p1019 word Solitaire (string)