import java.util.Scanner;

public class Demo1 {
public static void main(String[] args) {
System.out.println("请输入一个值");
Scanner sc = new Scanner(System.in);  //创建对象
int input = sc.nextInt();
Demo1 demo1 = new Demo1();//创建对象类名称作为开头
demo1.product(input);
int product = demo1.product(input);
System.out.print(product);
sc.close();//关闭输入接口
}
public int product(int n) {//定义方法
int num =1;
for(int i=1;i<=n;i++) {
num *=i;//阶层
}
return num;
}

}

 

 

 

 

 

package cn.com.emar;

import java.util.Scanner;

public class Demo2 {
public static void main(String[] args) {
System.out.println("请输入两个数值:");
Scanner sc = new Scanner(System.in);
int m = sc.nextInt();
int n = sc.nextInt();
Demo2 demo2 = new Demo2(); //初始化
demo2.size(m,n);//调用方法
sc.close();
}
public void size(int m, int n) {
int sum = m + n;
int product = m*n;
int minus = m-n;
int div = m/n;
System.out.println(m+"+"+n+"="+sum);
System.out.println(m+"*"+n+"="+product);
System.out.println(m+"-"+n+"="+minus);
System.out.println(m+"/"+n+"="+div);
}
}

package cn.com.emar;
//0换到1前面
import java.util.Arrays;

public class Demop {
public static void main(String[] args) {
int [] ary = {0,1,1,0,1,0,1,0,1,1,0,0,1};
int index = 0;
for(int i=0;i<ary.length;i++) {
if (ary[i]==0) { //遇到0 赋值给源数值1.同时index增加1,并且替换源来的1为0
ary[i] = 1;
ary[index++] = 0;
}
}
System.out.println(Arrays.toString(ary));
}
}

 

package cn.com.emar;
//统一数组内出现的数量
public class Demot {
public static void main(String[] args) {
int [] ary = {1,3,4,5,3,2,2,3,1,1,4};
int [] index = new int[10];//新建数组.用于索引统计出现数量
for(int x:ary) {
index[x]++ ; //出现相同值,数组索引自增
}
for(int i =0;i<index.length;i++) {
System.out.println("数值:"+i+" "+"统计个数:"+index[i]);
}
}
}

 

 斐波那数列

package cn.com.emar;

public class Demobd {
public static void main(String[] args) {
Demobd demobd = new Demobd();
for(int i =1;i<10;i++) {
int product=demobd.foo(i);
System.out.print(product+" ");
}
}
public int foo(int n) {
if (n ==2 || n==1) {
return 1;
}else {
return foo(n-1)+foo(n-2);
}
}
}

posted on 2019-01-08 17:31  LV_VL  阅读(112)  评论(0编辑  收藏  举报