java输入数组数据并保存到数组中(指定数组大小、不指定数组大小和直接输入数组)

java输入数组数据并保存到数组中(指定数组大小、不指定数组大小和直接输入数组)1 指定数组大小 用循环输入数据 importjava util Scanner publicclassM publicstatic String args Scannersc newScanner System in int arr newint 5 for inti 0 i

1、指定数组大小,用循环输入数据

import java.util.Scanner; public class Main2 { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int[] arr=new int[5]; for(int i=0;i 
  
输入: 1 2 3 4 5 输出: 1 2 3 4 5 

2、不指定数组大小,用字符串作为中介

import java.util.Scanner; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); String temp1=sc.nextLine(); String[] s=temp1.split(" "); int[] arr=new int[s.length]; for(int i=0;i 
  
输入: 1 2 3 4 5 输出: 1 2 3 4 5 

3、直接输入数组

 public static void main(String[] args){ Scanner sc=new Scanner(System.in); String temp1=sc.next(); String temp2=temp1.substring(1,temp1.length()-1);//去掉两边大括号 System.out.println(temp2); String[] s=temp2.split(","); int[] arr=new int[s.length]; for(int i=0;i 
  
输入: [1,2,3,4,5] 输出: 1,2,3,4,5 1 2 3 4 5 

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/227742.html原文链接:https://javaforall.net

(0)
上一篇 2026年3月16日 下午8:39
下一篇 2026年3月16日 下午8:39


相关推荐

  • 如何查看redis占用内存大小

    如何查看redis占用内存大小

    2021年11月3日
    45
  • linux ll命令时间,Linux ll命令显示年月日 时分秒

    linux ll命令时间,Linux ll命令显示年月日 时分秒[root@linuxboot]#ls-lh–time-style=+”%Y-%m-%d%H:%M:%S”total13M-rw-r–r–1rootroot69K2011-01-1406:40:04config-2.6.18-238.el5PAE-rw-r–r–1rootroot69K2016-09-0606:26:21config-2.6….

    2025年12月5日
    7
  • 自定义单选框样式方法

    自定义单选框样式方法元素的初始样式都不怎么好看,我们一般修改样式会想到直接在那元素上添加样式,比如background、border等,在大多数元素上是可以这么做,但当遇上了单选框会毫无反应。例:<!DOCTYPEhtml><htmllang="en"><head><metacharset="UTF

    2022年5月25日
    47
  • 虚拟IP原理

    原文链接: http://xiaobaoqiu.github.io/blog/2015/04/02/xu-ni-iphe-ippiao-yi/                    http://www.cnblogs.com/crazylqy/p/7741958.html文中有两处用红色标记的文字,是博主认为错误的地方,故做了修改,若理解有误,还望指正。            …

    2022年4月5日
    111
  • dpkg配置包出错_dpkg-reconfigure

    dpkg配置包出错_dpkg-reconfigure2021-10-18by崔斐然dpkg:处理软件包xxx(–configure)时出错解决方法来源:https://blog.csdn.net/jf_xu/article/details/82285008dpkg:处理软件包libicu-dev(–configure)时出错:依赖关系问题-仍未被配置dpkg:依赖关系问题使得libxml2-dev:amd64的配置工作不能继续:libxml2-d…

    2022年10月7日
    4
  • Springboot文件上传机制[通俗易懂]

    Springboot文件上传机制[通俗易懂]springboot文件上传机制:1.访问路径2. 上传完成后返回访问文件地址3. 我们只需要访问返回的地址就可以访问到图片4. yaml配置文件(localpath是实际存储的地址)5. 添加配置类,进行访问地址和存储地址映射 @Value(“${file.upload.suffixPath}”) private String uploadSuffixPath; @Value(“${file.upload.localPath}”) private Strin

    2022年8月9日
    7

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号