当前位置:网站首页>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 !
边栏推荐
- [insert, modify and delete data in the headsong educator data table]
- MySQL锁总结(全面简洁 + 图文详解)
- (原创)制作一个采用 LCD1602 显示的电子钟,在 LCD 上显示当前的时间。显示格式为“时时:分分:秒秒”。设有 4 个功能键k1~k4,功能如下:(1)k1——进入时间修改。
- String ABC = new string ("ABC"), how many objects are created
- 实验七 常用类的使用
- 稻 城 亚 丁
- [hand tearing code] single case mode and producer / consumer mode
- Relationship between hashcode() and equals()
- [three paradigms of database] you can understand it at a glance
- Programme de jeu de cartes - confrontation homme - machine
猜你喜欢
Mixlab unbounded community white paper officially released
3. Input and output functions (printf, scanf, getchar and putchar)
强化学习系列(一):基本原理和概念
记一次猫舍由外到内的渗透撞库操作提取-flag
Nuxtjs快速上手(Nuxt2)
【黑马早报】上海市监局回应钟薛高烧不化;麦趣尔承认两批次纯牛奶不合格;微信内测一个手机可注册俩号;度小满回应存款变理财产品...
SRC mining ideas and methods
Leetcode. 3. Longest substring without repeated characters - more than 100% solution
Leetcode.3 无重复字符的最长子串——超过100%的解法
[during the interview] - how can I explain the mechanism of TCP to achieve reliable transmission
随机推荐
[the Nine Yang Manual] 2022 Fudan University Applied Statistics real problem + analysis
[modern Chinese history] Chapter 6 test
7-15 h0161. 求最大公约数和最小公倍数(PTA程序设计)
[three paradigms of database] you can understand it at a glance
Custom RPC project - frequently asked questions and explanations (Registration Center)
实验六 继承和多态
强化学习基础记录
7-3 构造散列表(PTA程序设计)
受检异常和非受检异常的区别和理解
. How to upload XMIND files to Jinshan document sharing online editing?
【VMware异常问题】问题分析&解决办法
【Numpy和Pytorch的数据处理】
Miscellaneous talk on May 27
FAQs and answers to the imitation Niuke technology blog project (III)
canvas基础1 - 画直线(通俗易懂)
[insert, modify and delete data in the headsong educator data table]
Package bedding of components
Nuxtjs快速上手(Nuxt2)
Strengthen basic learning records
It's never too late to start. The tramp transformation programmer has an annual salary of more than 700000 yuan