当前位置:网站首页>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 !
边栏推荐
- The difference between abstract classes and interfaces
- Write a program to simulate the traffic lights in real life.
- Nuxtjs快速上手(Nuxt2)
- Relationship between hashcode() and equals()
- Using spacedesk to realize any device in the LAN as a computer expansion screen
- 实验七 常用类的使用(修正帖)
- 【黑马早报】上海市监局回应钟薛高烧不化;麦趣尔承认两批次纯牛奶不合格;微信内测一个手机可注册俩号;度小满回应存款变理财产品...
- 实验五 类和对象
- 【头歌educoder数据表中数据的插入、修改和删除】
- [the Nine Yang Manual] 2019 Fudan University Applied Statistics real problem + analysis
猜你喜欢
Read only error handling
Custom RPC project - frequently asked questions and explanations (Registration Center)
MySQL lock summary (comprehensive and concise + graphic explanation)
(original) make an electronic clock with LCD1602 display to display the current time on the LCD. The display format is "hour: minute: Second: second". There are four function keys K1 ~ K4, and the fun
Relationship between hashcode() and equals()
Using spacedesk to realize any device in the LAN as a computer expansion screen
Strengthen basic learning records
1. Preliminary exercises of C language (1)
Intensive literature reading series (I): Courier routing and assignment for food delivery service using reinforcement learning
记一次猫舍由外到内的渗透撞库操作提取-flag
随机推荐
hashCode()与equals()之间的关系
Yugu p1012 spelling +p1019 word Solitaire (string)
使用Spacedesk实现局域网内任意设备作为电脑拓展屏
实验五 类和对象
稻 城 亚 丁
Strengthen basic learning records
Thoroughly understand LRU algorithm - explain 146 questions in detail and eliminate LRU cache in redis
Nuxtjs quick start (nuxt2)
MySQL锁总结(全面简洁 + 图文详解)
关于双亲委派机制和类加载的过程
Caching mechanism of leveldb
【educoder数据库实验 索引】
canvas基础1 - 画直线(通俗易懂)
Differences among fianl, finally, and finalize
Leetcode.3 无重复字符的最长子串——超过100%的解法
Relationship between hashcode() and equals()
Intensive literature reading series (I): Courier routing and assignment for food delivery service using reinforcement learning
简单理解ES6的Promise
强化学习基础记录
MATLAB打开.m文件乱码解决办法