Java 有数组a[]={10,20,30,40},数组b[]={1,2,3,0},设计一个程序,求数组c[]=a[i]/b[i]

作者&投稿:滕净 (若有异议请与网页底部的电邮联系)
有数组a[]={10,20,30,40},数组b[]={1,2,3,0},设计程序,求数组c[]=a[i]/b[i],其~

不行的,40/0不行。如果把0换成4的话就是这样的。。
#include
using namespace std;
void main()
{
int a[4]={10,20,30,40},b[4]={1,2,3,4},c[4];
for(int i=0;i<4;i++)
c[i]=a[i]/b[i];
for(i=0;i<4;i++)
cout<<c[i]<<" ";
cout<<endl;
}

#include
void main()
{
int a[4]={10,20,30,40},b[4]={1,2,3,0};
double c[4];
int i,j=0;
for(i=0;i<4;i++)
{
c[j]=a[i]/(b[i]*1.0);
j++;
}
printf("新的数组为:
");
for(j=0;j<4;j++)
{
printf(" %lf ",c[j]);
}
printf("
");
}
//运行看看 那个b[4]改下,别初始为0

int a[]={10,20,30,40};
int b[]={1,2,3,0};
int c[]=new int[a.lenght];
for(int i=0;i<a.length;i++){
try{
c[i]=a[i]/b[i];
}catch(ArithmeticException e){ //分母为零抛出的异常
e.printStackTrace();
}catch(ArrayIndexOutOfBoundsException e){ //数组越界的异常 如果数组 a,b确定长度相等,不用捕捉此异常
break;
e.printStackTrace();
}

int a[]={10,20,30,40};
int b[]={1,2,3,0};
int c[]=new int [16];
int z=-1;
for(int i=0;i<a.length;i++){
for(int j=0;j<b.length;j++){
z++;
try {
c[z]=(a[i]/b[j]);
} catch (Exception e) {
continue; //在continue之前可以统计异常次数
}
}
}

for(int i=0; i<4; i++){
try{
c[i] = a[i]/b[i];
}catch(Exception ex){
ex.printStackTrace();
}
}

请参考

import java.util.Arrays;

public class Array{
public static void main(String[] args){
int[] a = {10,20,30,40,50};
int[] b = {0,2,30};

for(int i=0;i<5;i++){
try{

System.out.println( a[i]/b[i]);
}catch(ArithmeticException e1){
System.out.println("异常:算数错误");
}catch(ArrayIndexOutOfBoundsException e2){
System.out.println("异常:数组越界");
}finally{
System.out.println("运行结束");
}
}
}
}

路过...


禹王台区13834856148: Java 有数组a[]={10,20,30,40},数组b[]={1,2,3,0},设计一个程序,求数组c[]=a[i]/b[i] -
歹哀醋酸: int a[]={10,20,30,40}; int b[]={1,2,3,0}; int c[]=new int[a.lenght]; for(int i=0;i try{ c[i]=a[i]/b[i]; }catch(ArithmeticException e){ //分母为零抛出的异常 e.printStackTrace(); }catch(ArrayIndexOutOfBoundsException e){ //数组越界的异常 如果数组 a,b确定长度相等,不用捕捉此异常 break; e.printStackTrace(); }

禹王台区13834856148: 设有一维数组a[10]={2,32,6,74, - 14,68,0, - 9,41,32},用C语言程序输 -
歹哀醋酸: #include<stdio.h> int main() { int i,j,d,a[10]= {2,32,6,74,-14,68,0,-9,41,32}; int t=a[0]; double s=0; for(i=1; i<10; i++) if(t<a[i]) t=a[i]; printf("最大值为:%d\n",t); for(i=0; i<10; i++) s+=a[i]; printf("平均值为:%.2lf\n",s/10); printf("从小到大...

禹王台区13834856148: 写java程序 一维数组实验 : 定义一个整型数组a【10】,并初始化,求出数组的最大值和最 -
歹哀醋酸: public class TestMaxAndMin {public static void main(String[] args) {int[] arr = new int[10];arr[0]=12;arr[1]=13;arr[2]=14;arr[3]=15;arr[4]=16;arr[5]=17;arr[6]=18;arr[7]=19;arr[8]=23;arr[9]=22;for(int i=0;i<arr.length-1;i++){int temp;for(int j=...

禹王台区13834856148: (Java方法)有两个整形数组,int[]a={10,20,30,40,50},int[] b={10,20,60}, -
歹哀醋酸: 按照你的要求编写的Java程序如下1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28publicclassH2 {publicstaticvoidmain(String[] args) {int[] a={10,20,30,40,50};int[] b={10,20,60};intcount=0;for(inti=0;i<a.length;i++)...

禹王台区13834856148: java定义一个数组a[10],且输出值为0~99之间随机数 -
歹哀醋酸: 1234 int[] a=new int[10]; for(int i=0;i<a.length;i++){ a[i]=(int)(Math.random()*99); }

禹王台区13834856148: java 数组 String[] a={"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10"}; String[] b={"5","0", "1", "2", "3", "5", "6","1", "2", "4", "5
歹哀醋酸:public class test { public static void main(String[] args) { String[] a={"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10"}; String[] b={"5","0", "1", "7","2", "3", "5", "6","1", "2", "4", "5","6",...

禹王台区13834856148: 2、编写一个程序用排序法对数组a[]={10,15,23,50,36,60,75,28,90,88}进行由大到小的排序.
歹哀醋酸: public class a { public static void main(String[] arg) { int a[]={20,10,50,40,30,70,60,80,90,100} ; int i,n,max; for(i=0;i<=8;i++) { for(n=i+1;n<=9;n++) { if(a[i]<a[n]) { max=a[i]; a[i]=a[n]; a[n]=max; } } } for(i=0;i<=9;i++) { System.out.println(a[i]); } } }

禹王台区13834856148: java、获得数组的全部组合 -
歹哀醋酸: import java.util.*; public class eee{public static void main(String[] args){int[] a={0,1,2,3,4,5,6,7,8,9};for(int n=1;n<=a.length;n++){int[] b=new int[n];//存放组合结果的数组int num=getNumber(a.length,n)/getNumber(n,n);System.out.println("...

禹王台区13834856148: java中数组的定义为什么和c等语言不一样,不可以表明数组长度? -
歹哀醋酸: LZ是不是想这样问? 为什么要写成这样:int[] a=new int[10]; 而不是写成这样:int[10] a=new int[10]或int a[10]=new int[10];因为int[] a或int a[]仅仅是声明a是一个int型数组变量(也就是说可以用它来指向一个int型数组),至于长度是多少我们...

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 星空见康网