0% found this document useful (0 votes)
3 views2 pages

Java

Uploaded by

zxzx930415
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

Java

Uploaded by

zxzx930415
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

package ch10;

public class Ex01 {

public static void main(String[] args) {


// TODO Auto-generated method stub
int[][] a=new int[3][4];
double[][] b=new double[3][3];
for (int i=0;i<3;i++) {
for (int j=0;j<4;j++) {
a[i][j]=(int)(Math.random()*(50))+1;
}
}
for (int i=0;i<3;i++) {
for (int j=0;j<3;j++) {
b[i][j]=Math.random();
}
}

int max1=maxEle(a);
double max2=maxEle(b);
System.out.println("int 最大值為:"+max1);
System.out.println("double 最大值為:"+max2);

static int maxEle(int x[][]) {


int max=x[0][0];
for (int i=0;i<x.length;i++) {
for (int j=0;j<x[i].length;j++) {
if (x[i][j]>max) {
max=x[i][j];
}
}
}
return max;
}

static double maxEle(double x[][]) {


double max=x[0][0];
for (int i=0;i<x.length;i++) {
for (int j=0;j<x[i].length;j++) {
if (x[i][j]>max) {
max=x[i][j];
}
}
}
return max;
}

_______________________________________________________________________

package ch10;

import java.util.Scanner;
public class Ex02 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner keyin = new Scanner(System.in);
System.out.print("輸入數字:");
double x=keyin.nextDouble();
System.out.print("輸入次方:");
int y=keyin.nextInt();
double result=myPower(x,y);
System.out.println(x+"的"+y+"次方:"+result);
}

static double myPower(double x,int y) {


if (y<0) {
return 0;
}
else {
double result=Math.pow(x,y);
return result;
}
}
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy