package method;
public class Demo01 {
public static void main(String[] args) {
//int sum = add(1, 2);
//System.out.println(sum);
test();
}
public static int add(int a,int b){
return a+b;
}
public static void test(){
for (int i=1;i<=1000;i++){
if (i%5==0){
System.out.print(i+"\t");
}
if (i%(3*5)==0){
System.out.println();
//System.out.print("\n");
}
}
}
}
package method;
public class Demo02 {
public static void main(String[] args) {
//int max = max(10, 10);
//System.out.println(max);
int b = max(10,20,30);
System.out.println(b);
double a = max(10.2, 10);
System.out.println(a);
double c = max(10, 10.2);
System.out.println(c);
//Demo02 demo02 = new Demo02();
//int test = demo02.test(3);
//System.out.println(test);
}
public static int max(int num1,int num2){
int result = 0;
if (num1==num2){
System.out.println("num1=num2");
return 0;
}
if (num1>num2){
result = num1;
} else {
result = num2;
}
return result;
}
public static double max(int num1,double num2){
double result = 0;
if (num1==num2){
System.out.println("num1=num2");
return 0;
}
if (num1>num2){
result = num1;
} else {
result = num2;
}
return result;
}
public static double max(double num1,int num2){
double result = 0;
if (num1==num2){
System.out.println("num1=num2");
return 0;
}
if (num1>num2){
result = num1;
} else {
result = num2;
}
return result;
}
public static int max(int num1,int num2,int num3){
int result = 0;
if (num1==num2&&num1==num3){
System.out.println("num1=num2=num3");
return 0;
}
if (num1>num2){
result = num1;
} else {
result = num2;
}
return result;
}
public static double max(double num1,double num2){
double result = 0;
if (num1==num2){
System.out.println("num1=num2");
return 0;
}
if (num1>num2){
result = num1;
} else {
result = num2;
}
return result;
}
public int test(int a){
int sum = 0;
while(a<5){
sum+=a;
a++;
}
return sum;
}
}
package method;
public class Demo03 {
public static void main(String[] args) {
for (int i = 0; i < args.length; i++) {
System.out.println("args["+i+"]:"+args[i]);
}
}
}
package method;
public class Demo04 {
public static void main(String[] args) {
Demo04 demo04 = new Demo04();
demo04.printMax();
demo04.printMax(-10,-20.2,-30,-50,-6.3);
printMax(new double[]{1,2,3});
}
public static void printMax(double... number){
if (number.length==0){
System.out.println("No argument passed.");
return;
}
double result = number[0];
for (int i = 1; i < number.length; i++) {
if (number[i] > result) {
result = number[i];
}
}
System.out.println("The max value is "+result);
}
/*public static void main(String[] args) {
Demo04 demo04 = new Demo04();
demo04.test(1,4,5,65,9);
}
public void test(int x,int... i){
System.out.println(x);
System.out.println(i[0]);
System.out.println(i[1]);
System.out.println(i[2]);
System.out.println(i[3]);
}
*/
}
package method;
public class Demo05 {
public static void main(String[] args) {
Demo05 test = new Demo05();
test.test();
}
public void test(){
test();
}
}
package method;
public class Demo06 {
public static void main(String[] args) {
System.out.println(f(4));
}
public static int f(int i){
if (i==1){
return 1;
}else {
return i*f(i-1);
}
}
}
package method;
import java.util.Scanner;
public class Demo07 {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
while(scan.hasNextLine()){
String operator = scan.nextLine();
double n = scan.nextDouble();
double m = scan.nextDouble();
scan.nextLine();
double result ;
switch(operator){
case "+" :
result = calplus(n,m);
System.out.println(result);
break;
case "-" :
result = calminus(n,m);
System.out.println(result);
break;
case "*" :
result = calmulti(n,m);
System.out.println(result);
break;
case "/" :
result = caldivide(n,m);
System.out.println(result);
break;
default:
System.out.println("输入的运算符不合法");
}
}
scan.close();
}
public static double calplus(double n,double m){
return m+n;
}
public static double calminus(double n,double m){
return n-m;
}
public static double calmulti(double n,double m){
return m*n;
}
public static double caldivide(double n,double m){
return n/m;
}
}
标签:num1,int,double,System,method,result,public
From: https://www.cnblogs.com/799rijiyuelei/p/16851237.html