
5个回答
展开全部
import java.util.*;
public class Test {
public static void main(String[]args){
int[] arry = new int[]{1,2,3,4,5,6,7,8,9,0,2,4,3,6,5,9,6,5};
//这个数组是您自己定义的,有多少元素自己写就好
Scanner input =new Scanner(System.in);
System.out.println("请输入你想要输出,数组前几个元素:");
int a=input.nextInt();
if(a > arry.length){
System.out.println("个数大于数组长度");
}else{
for(int i = 0; i < a; i++){
System.out.print(arry[i]);
System.out.print(" ");
}
}
}
}
public class Test {
public static void main(String[]args){
int[] arry = new int[]{1,2,3,4,5,6,7,8,9,0,2,4,3,6,5,9,6,5};
//这个数组是您自己定义的,有多少元素自己写就好
Scanner input =new Scanner(System.in);
System.out.println("请输入你想要输出,数组前几个元素:");
int a=input.nextInt();
if(a > arry.length){
System.out.println("个数大于数组长度");
}else{
for(int i = 0; i < a; i++){
System.out.print(arry[i]);
System.out.print(" ");
}
}
}
}
展开全部
public class Gamma {
public static void main(String[] args){
int[] arr = new int[]{1,2,3,4,5,6,7,8,9,0};
new Gamma().out(10, arr);
}
public void out(int n, int[] a){
if(n > a.length){
System.out.println("个数大于数组长度");
}else{
for(int i = 0; i < n; i++){
for(int j = 0; j <= i; j++){
System.out.print(a[j]);
System.out.print(" ");
}
System.out.println();
}
}
}
}
public static void main(String[] args){
int[] arr = new int[]{1,2,3,4,5,6,7,8,9,0};
new Gamma().out(10, arr);
}
public void out(int n, int[] a){
if(n > a.length){
System.out.println("个数大于数组长度");
}else{
for(int i = 0; i < n; i++){
for(int j = 0; j <= i; j++){
System.out.print(a[j]);
System.out.print(" ");
}
System.out.println();
}
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
两个for循环啊!
for(int 0;i<n.i++){
int j=i+1;
for(int x=0;x<j;x++)
System.out.println(a[x]);
}
for(int 0;i<n.i++){
int j=i+1;
for(int x=0;x<j;x++)
System.out.println(a[x]);
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
try{
for (int i = 0; i < n; i++){
System.out.println(a[i]);
}
}catch(Exception e ){}
for (int i = 0; i < n; i++){
System.out.println(a[i]);
}
}catch(Exception e ){}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询