题库来源

计算字符个数

写出一个程序,接受一个由字母和数字组成的字符串,和一个字符,然后输出输入字符串中含有该字符的个数。不区分大小写。

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

while (sc.hasNextLine()) {

char[] text = sc.nextLine().toLowerCase().toCharArray();

char targetChar = sc.nextLine().toLowerCase().toCharArray()[0];

int count=0;

for (Character t : text) {

if (t==targetChar) {

count=count+1;

}

}

System.out.println(count);

}

}

明明的随机数

他先用计算机生成了N个1到1000之间的随机整数(N≤1000),对于其中重复的数字,只保留一个,把其余相同的数去掉,不同的数对应着不同的学生的学号。

再把这些数从小到大排序,按照排好的顺序去找同学做调查。

TreeSet与HashSet

HashSet不能保证元素的排列列顺序,TreeSet是SortedSet接⼝口的唯一实现类,可以确保集合

元素处于排序状态

HashSet底层⽤用的是哈希表,TreeSet采⽤用的数据结构是红黑树(红黑树是一种特定类型的二叉树)

HashSet中元素可以是null,但只能有一个,TreeSet不不允许放入null

一般使用HashSet,如果需要排序的功能时,才使⽤用TreeSet(性能原因)

import java.util.*;

public class Main

{

public static void main(String[] args) {

Scanner sc=new Scanner(System.in);

while(sc.hasNext()){

TreeSet set=new TreeSet(new Comparator() {

@Override

public int compare(Integer o1, Integer o2) {

return o1.compareTo(o2);

}

});

int n=sc.nextInt();

if(n>0){

for(int i=0;i

set.add(sc.nextInt());

}

}

for(Integer i:set){

System.out.println(i);

}

}

}

}

字符串数组

•连续输入字符串,请按长度为8拆分每个字符串后输出到新的字符串数组;

•长度不是8整数倍的字符串请在后面补数字0,空字符串不处理。

这题的重点在于要将长度不是8的整数倍字符串补齐后循环输出,而不是输出同时补齐(太麻烦并且)。

public class Main {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

while (sc.hasNext()) {

String line = sc.nextLine();

int lineLen = line.length();

if (lineLen % 8 == 0) {

for (int i = 0; i < lineLen; i = i + 8) {

System.out.println(line.substring(i, i + 8));

}

} else {

int lenMod = 8 - lineLen % 8;

for (int i = 0; i < lenMod; i++) {

line = line + 0;

}

if (lineLen < 8) {

System.out.println(line);

} else {

for (int j = 0; j < lineLen; j = j + 8) {

System.out.println(line.substring(j, j + 8));

}

}

}

}

}

}

进制转换

写出一个程序,接受一个十六进制的数,输出该数值的十进制表示。(多组同时输入 )

public class Main {

public static void main(String[] args) throws IOException {

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

String line = null;

while ((line = br.readLine()) != null) {

System.out.println(Long.parseLong(line.substring(2), 16));

}

}

}

输出质因子

功能:输入一个正整数,按照从小到大的顺序输出它的所有质因子(重复的也要列举)(如180的质因子为2 2 3 3 5 )

最后一个数后面也要有空格

import java.util.Scanner;

public class Main

{

public static void main(String[] args)

{

Scanner scanner = new Scanner(System.in);

long number = 0;

while(scanner.hasNextLong())

{

number = scanner.nextLong();

isPrimerFactors(number);

}

}

private static void isPrimerFactors(long num)

{

long number = num;

while(number != 1)

{

for(int i = 2; i <= number ;i++)

{

if(number % i == 0)

{

number /= i;

System.out.print(i + " ");

break;

}

}

}

}

}

取近似值

java中的三种取整函数:floor,ceil,round

写出一个程序,接受一个正浮点数值,输出该数值的近似整数值。如果小数点后数值大于等于5,向上取整;小于5,则向下取整。

import java.util.*;

public class Main

{

public static void main(String[] args) {

Scanner sc=new Scanner(System.in);

float num=sc.nextFloat();

System.out.println(Math.round(num));

}

}

合并表记录(TreeMap)

数据表记录包含表索引和数值(int范围的整数),请对表索引相同的记录进行合并,

即将相同索引的数值进行求和运算,输出按照key值升序进行输出。

public class Main{

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

int num=sc.nextInt();

TreeMap map=new TreeMap<>();

while(num>0){

int key=sc.nextInt();

int value=sc.nextInt();

if(!map.containsKey(key)){

map.put(key,value);

}else{

map.put(key,map.get(key)+value);

}

num--;

}

Iterator iterator=map.entrySet().iterator();

while(iterator.hasNext()){

Map.Entry en = (Map.Entry)iterator.next();

Integer key=en.getKey();

Integer value=en.getValue();

System.out.println(key+" "+value);

}

}

}

提取不重复的整数

输入一个int型整数,按照从右向左的阅读顺序,返回一个不含重复数字的新的整数。

① HashSet的输出顺序是不确定的,但是它的速度最快;

② TreeSet输出顺序是升序排列的,相当于C++中的set,个人比较喜欢这种;

③ LinkedHashSet输出顺序是确定的,就是插入时的顺序。

import java.util.*;

/**

* @Author hwj

* @Date 2020/8/15 8:37

* @Desc:

**/

public class Main{

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

String[] number=sc.nextLine().split("");

int numLen=number.length;

LinkedHashSet set=new LinkedHashSet<>();

for(int i=numLen-1;i>=0;i--){

if(!set.contains(Integer.parseInt(number[i]))) {

set.add(Integer.parseInt(number[i]));

}

}

Iterator iterator= set.iterator();

while(iterator.hasNext()){

System.out.print(iterator.next());

}

}

}

句子逆序

将一个英文语句以单词为单位逆序排放。

例如“I am a boy”,逆序排放后为“boy a am I”

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

String sentence = sc.nextLine();

String strReverse=reverse(sentence);

System.out.println(strReverse);

}

public static String reverse(String sentence){

String[] str=sentence.split(" ");

int strLen=str.length;

String str2=str[strLen-1];

for(int i=strLen-2;i>=0;i--){

str2=str2+" "+str[i];

}

return str2;

}

字串的连接最长路径查找

给定n个字符串,请对n个字符串按照字典序排列。

public class Main {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

int n=sc.nextInt();

int num=n;

TreeSet set=new TreeSet<>();

while(num>=0){

set.add(sc.nextLine());

num--;

}

Iterator iterator = set.iterator();

while(iterator.hasNext()){

System.out.println(iterator.next());

}

}

}

字串的连接最长路径查找

在线编程适用: BufferedReader

集合排序 Collections.sort()

import java.io.BufferedReader;

import java.io.IOException;

import java.io.InputStreamReader;

import java.util.*;

/**

* @Author hwj

* @Date 2020/8/15 8:37

* @Desc:

**/

public class Main {

public static void main(String[] args) throws IOException {

BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

int num=Integer.parseInt(br.readLine());

ArrayList arr=new ArrayList<>();

while(num>0){

num--;

arr.add(br.readLine());

}

Collections.sort(arr);

for(String s:arr){

System.out.println(s);

}

}

}

软通动力华为java机考题库_华为机考笔试刷题-java-1相关推荐

  1. 华为硬件工程师社招机考题库_华为硬件工程师笔试、面试题

    模拟电路 1.基尔霍夫定理的内容是什么?(仕兰微电子) 2.平板电容公式(C=εS/4πkd).(未知) 3.最基本的如三极管曲线特性.(未知) 4.描述反馈电路的概念,列举他们的应用.(仕兰微电子) ...

  2. 华为硬件工程师社招机考题库_华为电子软硬件工程师招聘笔试题

    华为面题 (硬件) 全都是几本模电数电信号单片机题目 1.用与非门等设计全加法器 2.给出两个门电路让你分析异同 3.名词:sram,ssram,sdram 4.信号与系统:在时域与频域关系 5.信号 ...

  3. 华为硬件工程师社招机考题库_华为校招_硬件技术工程师机考试题及答案

    1. (判断题 ) DRAM 上电时存储单元的内容是全 0, 而 Flash 上电时存储单元的内容是全 1 .( 4 分 ) A. 正确 B. 错误 FLASH 可保存 2. (判断题 ) 眼图可以用 ...

  4. 软通动力华为java机考题库_软通动力Java考试题库.doc

    软通动力Java考试题库.doc 软通动力培训课程题库 Java 编号:ISS-TJ-TC 版本: 1.0 作者:JavaSE基础康佳琪日期作者:JavaEE高级张建军日期:审批人:张林福日期: 目录 ...

  5. 华为校招java笔试题库_华为校招Java笔试题库,看你会不会做

    1.在java中如果声明一个类为final,表示什么意思? 答:final是最终的意思,final可用于定义变量.方法和类但含义不同,声明为final的类不能被继承. 2.父类的构造方法是否可以被子类 ...

  6. 华为云NP考试题库_华为认证网络工程师怎么考

    如果现在打算学习华为认证的话,那么下一步该怎么开始呢?华为认证网络工程师的考试该怎么样考呢?有不少朋友长期关注网络工程师成长日记作者小编,看了大量小编关于华为认证的介绍之后,有些朋友时间充裕也打算进行 ...

  7. 华为云NP考试题库_华为云服务考试 华为云hcip认证试题

    怎样找到华为手机云服务? 在华为手机云服务的手机设置菜单中,以华为G9手机为例.搜索方法如下:1.打开手机的设置页面,在设置页面的顶部有一个搜索框. 2.在搜索框中,输入云服务以开始搜索.搜索结束后, ...

  8. 华为硬件工程师社招机考题库_干货:2016年华为中兴硬件工程师笔试题目与经验...

    1.一位工科男在拿到华为实习生offer后的面经干货 某211学校,机械学院研究生. 不得不说一下,华为的员工们真的是认真做事,因为怕我们担心下班轮不到面试.工作人员特意去休息区告诉我们,不面试完他们 ...

  9. 华为硬件工程师社招机考题库_中级会计机考你了解吗?机考操作常见八大问题速看...

    中级会计考试采用无纸化机考的形式,考生们在备考时要多熟悉机考操作,为了帮助考生提前了解无纸化机考,东奥小编整理了一些机考的常见问题,希望能够帮助到大家! 一.参加无纸化考试的考生允许带计算器入场吗? ...

最新文章

  1. Linux sendmail发送邮件失败诊断案例(一)
  2. 【数据结构与算法】之深入解析“最长有效括号”的求解思路与算法示例
  3. [渝粤教育] 西南科技大学 施工组织 在线考试复习资料
  4. SourceTree超前一个版本,落后N个版本
  5. 中学教师计算机技术培训资料,教师信息技术能力培养
  6. Pandas一些小技巧
  7. 从佛罗伦萨记账到区块链,应用才是区块链崛起的真正标志
  8. What we learn before born?
  9. firebug下载及安装
  10. mysql查询登录端口_mysql查看、修改端口、指定端口登录
  11. Drupal 在Views 中自定义筛选 Filter
  12. 虚拟机服务器渗透,对一台虚拟主机服务器的渗透 -电脑资料
  13. 如何在Photoshop里抠头发丝
  14. 2022-2028年中国眼镜制造行业市场竞争策略及未来发展潜力报告
  15. Java object转string
  16. XJTU-SY数据集轴承故障诊断
  17. Android 修改SIM卡默认VOLTE值
  18. 游戏策划学习:未知性与好奇心
  19. B2B,B2C,C2C,O2O,P2P的区别
  20. mysql 报错 lock wait timeout exceeded 解决方法

热门文章

  1. 在windows环境下ftp服务器的文件上传和下载
  2. nohup xxx 后台进程关闭,可以这样避免
  3. f5+big+client+android,F5负载均衡 MIBs bigip oid
  4. python asyncio 并发编程_asyncio并发编程
  5. android surfaceview camera,android – 如何在SurfaceView上显示相机预览?
  6. 黑群晖找不到设备_黑群晖洗白算号器SN、MAC地址
  7. 物联网协议比较 MQTT CoAP RESTful/HTTP XMPP
  8. xp/win 7 系统搭建 Java环境
  9. 浅谈Normalize.css
  10. 用自定义注解做点什么——自定义注解有什么用