文章目录

  • String转为int
  • int转为String
  • 一行输入数字
  • 多行数字
  • 多行数字,无结果不输出
  • 循环多个int输入
  • 循环 String输入
  • 多行输入 数字 + 字符串数组
  • 多行字符串输入
  • 多行字符串输入,逗号隔开

String转为int

Integer.parseInt转为int

int i = Integer.parseInt(str);

Integer.valueOf转为Integer,intValue再转为int

int i = Integer.valueOf(s).intValue();

int转为String

String.valueOf

String s = String.valueOf(i);

Integer.toString

String s = Integer.toString(i);

加空串,效率低

String s = “” + i;

一行输入数字

输入

1 5
10 20

输出

6
30
public class Main{public static void main(String[] args){Scanner sc = new Scanner(System.in);while(sc.hasNext()){int a = sc.nextInt();int b = sc.nextInt();System.out.println(a+b);}}
}

多行数字

输入

2
1 5
10 20

输出

6
30
public class Main {public static void main(String[] args) {Scanner sc = new Scanner(System.in);int t = sc.nextInt();for(int i = 0; i < t; i++) {int a = sc.nextInt();int b = sc.nextInt();System.out.println(a + b);}}
}

多行数字,无结果不输出

输入

1 5
10 20
0 0

输出

6
30
public class Main {public static void main(String[] args) {Scanner sc = new Scanner(System.in);while (sc.hasNext()) {int a = sc.nextInt();int b = sc.nextInt();if (a == 0 && b == 0) break;System.out.println(a + b);}}
}

循环多个int输入

输入

2
4(个数) 1 2 3 4
5(个数) 1 2 3 4 5

输出

10
15
public class Main{public static void main(String[] args) {Scanner sc = new Scanner(System.in);int n = sc.nextInt();for (int i = 0; i < n; i++) {int number = sc.nextInt();int sum = 0;for (int j = 0; j < number; j++) {sum += sc.nextInt();}System.out.println(sum);}}
}

循环 String输入

输入

2
4(个数) 1 2 3 4
5(个数) 1 2 3 4 5

输出

10
15
public class Main {static public void main(String[] args) {Scanner sc = new Scanner(System.in);while (sc.hasNext()) {String input = sc.nextLine();String[] num = input.split(" ");System.out.println(Arrays.toString(num));int result = 0;for (int i = 1; i < Integer.parseInt(num[0]) + 1; i++) {result = result + Integer.parseInt(num[i]);}System.out.println(result);}}
}

多行输入 数字 + 字符串数组

输入

5
c d a bb e

输出

a bb c d e
public class Main {public static void main(String[] args) {Scanner in = new Scanner(System.in);while (in.hasNext()) {int n = in.nextInt();String[] ss = new String[n];for (int i = 0; i < n; i++)ss[i] = in.next();Arrays.sort(ss);for (int i = 0; i < n - 1; i++) {System.out.print(ss[i] + " ");}System.out.print(ss[n - 1]);}}
}

多行字符串输入

输入

a c bb
f dddd
nowcoder

输出

a bb c
dddd f
nowcoder
public class Main {public static void main(String[] args) {Scanner scanner = new Scanner(System.in);List<String> list;while (scanner.hasNextLine()) {String line = scanner.nextLine();String [] strArray = line.split(" ");list = Arrays.asList(strArray);Collections.sort(list);for (int i = 0; i < list.size()-1; i++) {System.out.print(list.get(i) + " ");}System.out.print(list.get(list.size()-1));System.out.println();}}
}

多行字符串输入,逗号隔开

输入

a,c,bb
f,dddd
nowcoder

输出

a,bb,c
dddd,f
nowcoder
import java.util.*;public class Main {public static void main(String[] args) {Scanner sc = new Scanner(System.in);while (sc.hasNext()) {String[] input2 = sc.nextLine().split(",");List<String> list = Arrays.asList(input2);Collections.sort(list);int i = 0;// 输出for (String s : list) {if (i < list.size() - 1) {System.out.print(s + ",");i++;} else {System.out.print(s);}}System.out.println("");}}
}

Java牛客网输入测试用例相关推荐

  1. Java牛客网社区项目——知识点面试题

    Java牛客网社区项目--知识点&面试题 持续更新中(ง •̀_•́)ง 文章目录 Java牛客网社区项目--知识点&面试题 请简要介绍一下你的项目? 什么是Spring框架? 对Sp ...

  2. java 牛客网之[动态规划 简单]NC4 【模板】前缀和

    题目的链接在这里:https://www.nowcoder.com/practice/acead2f4c28c401889915da98ecdc6bf 目录 题目大意 一.示意图 二.解题思路 超时代 ...

  3. 牛客网输入规范总结(c++部分)

    注意:输入的多组输入,不是一组,已经猜了很多次坑了哦! 输入 预先不输入数据的组数 while(cin>>a>>b){cout<<a+b<<endl; ...

  4. java 牛客网之[动态规划 简单]NC3 nico和niconiconi

    题目的链接在这里:https://www.nowcoder.com/practice/70a03345bae6499ea4338ebc3a0b60e9 目录 题目大意 一.示意图 二.解题思路 字符串 ...

  5. 【牛客网笔试整理】美团点评 笔试整理

    链接:https://www.nowcoder.com/questionTerminal/29d1622d47514670a85e98a1f47b8e2d 来源:牛客网 已知一种新的火星文的单词由英文 ...

  6. 【2020牛客网笔试整理】小红书笔试题

    薯队长写了一篇笔记草稿,请你帮忙输出最后内容. 1.输入字符包括,"(" , ")" 和 "<"和其他字符. 2.其他字符表示笔记内容 ...

  7. 洛谷、牛客网、AcWing 刷题(python版)

    牛客网python专项练习整理(一) https://blog.csdn.net/weixin_41913008/article/details/87203468 牛客网剑指offer--python ...

  8. 牛客网编程OJ的典型输入Java模板

    笔试的时候一般都需要自己写输入输出,为了尽可能减少因为格式问题而爆0这种委屈之事,我在此以牛客网OJ为例总结了常见的6种典型情况输入描述的模板.希望可以帮助到广大考友把更多的精力放在解题思路上. 1. ...

  9. 字节跳动java笔试题目_牛客网--字节跳动面试题--特征提取

    牛客网--字节跳动面试题--特征提取 博客说明 文章所涉及的资料来自互联网整理和个人总结,意在于个人学习和经验汇总,如有什么地方侵权,请联系本人删除,谢谢! 来源 链接:特征提取 来源:牛客网 题目 ...

  10. Day5.牛客网剑指offer 67题之43-54题(java代码)

    文章目录 Day5.牛客网剑指offer 67题之43-54题 43.左旋转字符串 44.翻转单词顺序列 45.扑克牌顺序 46.孩子们的游戏 47.求1+2+...+n 48.不用加减乘除做加法 4 ...

最新文章

  1. TensorRT-优化-原理
  2. mysql不同实例数据同步_两台Mysql数据库数据同步实现实例
  3. TCP 为什么是三次握手,而不是两次或四次?
  4. html常用标签详解4-列表标签
  5. Java学习之容器上(Collection接口常用方法,Iterator接口,使用foreach循环遍历Collection集合元素,Set集合通用知识(Hashset类,hashcode()与Lin
  6. Linux C :Linux 下第一个C程序
  7. SharePoint工作流解决方案QuickFlow系列(2)--Task
  8. Ribbon源码解析(二)
  9. python ax.imshow_python – Matplotlib imshow / matshow在情节上显...
  10. 【20161108】总结
  11. MySQL与Redis缓存问题-开课吧
  12. linux|文本编辑
  13. 使用shell脚本实现everthing的功能
  14. css使用clac()垂直居中
  15. 平面设计的概念是什么,如何理解平面设计的概念
  16. windows 下 tomcat 开机自启动
  17. 关于加油站GPS坐标所想到的解决办法
  18. python实现添加商品至购物车
  19. 一分钟学会写网页表格
  20. Android通信安全之HTTPS

热门文章

  1. IMEI IMSI和ICCID
  2. 国内公有云对比(1.5)- 功能篇之青云
  3. cadence如何导入gds_Tanner LEdit系列 | 导入GDSII文件
  4. figma对比sketch有什么优势和不足?
  5. appstore软件销售数据统计分析软件Prismo
  6. linux C之srand函数
  7. 程序员:耐得住寂寞,禁得住诱惑
  8. linux格式化只读u盘,linux下FAT32格式u盘只读的问题及解决方法
  9. sql server 找到刚刚插入的indentify的数字
  10. 计算机一黑屏就显示当前账户已锁定,电脑黑屏用户已锁定账户怎么办?