命令行传递参数
示例图片:
初识java Day5
public static void main(String[] args) {
int i=0;
while (i<100){
i+=1;
System.out.println(i);
if (i==30){
break;
}
}
}
public static void main(String[] args) {
int i=0;
while (i<100){
i++;
if (i%5==0){
System.out.println( );
continue;
}
System.out.print("\t"+i);
}
}
public static void main(String[] args) {
//打印三角形 5行
int i,j;
for (i=1;i<=5;i++){
for (j=5;j>=i;j--){
System.out.print(" ");
}
for (j=1;j<=i;j++){
System.out.print("#");
}
for (j=1;j<i;j++){
System.out.print("#");
}
System.out.println();
}
}
public static void main(String[] args) {
int sum=add(1,2,7);
System.out.println(sum);
//test();
}
//加法
public static int add(int a,int b){
return a+b;
}
public static int add(int q,int w,int e){
return q+w+e;
}
public static int add(int z,int x,int c,int v){
return z+x+c+v;
}
/*
public static void test(){
for (int i = 0; i <= 1000; i++) {
if (i%5==0){
System.out.print(i+"\t");
}
if (i%(3*5)==0){
System.out.print("\n");
}
}
}
*/
public static void main(String[] args) {
int max=max(10,10);
System.out.println(max);
}
public static int max(int m,int n){
int result=0;
if (m==n){
System.out.println("m==n");
return 0;
}
if (m>n){
result=m;
}
if (n>m){
result=n;
}
return result;
}
public static void main(String[] args) {
double max=max(9.0,8);
System.out.println(max);
}
public static int max(int num1, int num2){
int result=0;
if (num1>num2){
result=num2;
}
if (num1>num2){
result=num1;
}
if (num1==num2){
System.out.println("uuu");
return 0;
}
return result;
}
public static double max(double num1, double num2){
double result=0;
if (num1>num2){
result=num2;
}
if (num1>num2){
result=num1;
}
if (num1==num2){
System.out.println("uuu");
return 0;
}
return result;
}
public static void main(String[] args) {
//args.length 数组长度
for (int i=0;i< args.length;i++){
System.out.println("args["+i+"]:"+args[i]);
}
}
public static void main(String[] args) {
Demo05 demo05=new Demo05();
demo05.test(1,2,3,4,555,6);
}
public void test(int... i){
System.out.println(i[0]);
System.out.println(i[1]);
System.out.println(i[2]);
System.out.println(i[3]);
System.out.println(i[4]);
System.out.println(i[5]);
}
public static void main(String[] args) {
//调用可变参数的方法
printMax(34,3,3,2,56,5);
printMax(new double[]{1,2,3});
}
public static void printMax(double... numbers){
if (numbers.length==0){
System.out.println("NO argument passed");
return;
}
double result=numbers[0];
//排序
for (int i=1;i< numbers.length;i++){
if (numbers[i]>result){
result=numbers[i];
}
}
System.out.println("The max value is"+result);
}
public static void main(String[] args) {
System.out.println(f(5));
}
public static int f(int n){
if (n==1){
return 1;
}else {
return n*f(n-1);
}
}
public static void main(String[] args) {
System.out.println("请选择你要进行的计算:+ ,- ,* ,/ ");
Scanner scanner=new Scanner(System.in);
String js= scanner.next();
int m,n;
switch (js){
case "+":
System.out.println("请输入第一个数:");
m = scanner.nextInt();
System.out.println("请输入第二个数:");
n=scanner.nextInt();
System.out.println("结果为:"+m+"+"+n+"="+(m+n));
break;
case "-":
System.out.println("请输入第一个数:");
m = scanner.nextInt();
System.out.println("请输入第二个数:");
n=scanner.nextInt();
System.out.println("结果为:"+m+"-"+n+"="+(m-n));
break;
case "*":
System.out.println("请输入第一个数:");
m = scanner.nextInt();
System.out.println("请输入第二个数:");
n=scanner.nextInt();
System.out.println("结果为:"+m+"*"+n+"="+(m*n));
break;
case "/":
System.out.println("请输入第一个数:");
m = scanner.nextInt();
System.out.println("请输入第二个数:");
n=scanner.nextInt();
System.out.println("结果为:"+m+"/"+n+"="+(m/n));
break;
default:
System.out.println("请输入正确的符号");
}
}
标签:java,int,Day5,System,初步,static,println,public,out
From: https://www.cnblogs.com/determine-boke/p/17991331