输入的任意一组int型数组如{1,3,4,7,2,1,1,5,2},打印出.
解决方案 »
- could not find the main class,program will exit
- 100分求助,按完OneMoreTime钮按后,再用键盘改变方向就不好使了
- java基础问题????
- 求解一个java语法.关于双花括号的.
- 怎么将一个容器(Container)中的所有内容(控件及图形)转化成一个Image对象?
- 谁来帮我看看这段代码。拉兄弟一把吧(多线程问题-在线等)
- 请教TableMode的问题。
- question:关于tomcat和apache的整合
- 关于注册jbuilder6.0的问题
- 帮忙翻译一句话!
- 100分请教Java代码运行顺序问题
- Client字符访问Server数据库的困惑
数组不可变长,那先输入长度,然后再输入数字.
Scanner s=new Scanner(System.int);
s.nextInt(); 下一个整数.
s.nextLine(); 下一行(包括空格)
s.next() 没有包括空格.以空格为分隔符.
先得一个n=s.nextInt();
然后for(i=0;i<n....) 一个一个填充数组
public class Test1 {
public static void main(String[] args) {
int[] arr = {1,3,4,7,2,1,1,5,2};
for(int i:arr){
System.out.println(i);
}
}
}
public class NO3_B_1
{
public static void main(String[] args)throws Exception
{
int arrays[] = new int[9];
int pos = 0;
int num = 0;
System.out.print("输入E结束输入:");
Scanner s = new Scanner(System.in);
while(!String.valueOf(num).equals("e"))
{
num = s.nextInt();
arrays[pos++] = num ;
}
for(int i : arrays)
System.out.print(i+"\t");
}
public static void main(String[] args){
int arrays[] = new int[10];
int pos = 0;
String num = "";
int input=0;
System.out.print("输入E结束输入:");
Scanner s = new Scanner(System.in); while (!num.equals("e")) {
num = s.nextLine();
try {
input = Integer.parseInt(num);
arrays[pos++]=input;
} catch (NumberFormatException e) {
continue;
}
}
for (int i=0;i<pos;i++)
System.out.print(arrays[i] + "\t");
}
}
import java.util.Scanner;public class NO3_B_1 {
public static void main(String[] args)throws Exception {
System.out.print("输入E结束输入:");
Scanner s = new Scanner(System.in);
String str = s.nextLine();
String []arrays = str.split(" ");
for(String i : arrays){
if(!i.endsWith("E"))
System.out.print(i+"\t");
else{
System.out.println(i.substring(0,i.length()-1));
break;
}
}
}
}
运行结果:
输入E结束输入:12 35 63 3E
12 35 63 3