记住格式
//拿来一个扫描器:
Scanner sc = new Scanner(System.in);
//给一个友好性的提示:
System.out.print("请录入一个半径:");
//让扫描器扫描键盘录入的int类型的数据:
int r = sc.nextInt();
double[] score = new double[10];
double sum=0, max = 0,min =0;
Scanner sc = new Scanner(System.in); //ctr+shift+o导包;alt+/代码提示;ctr+alt+上下键复制
for(int i =0;i<score.length;i++) {
System.out.print("请输入第"+(i+1)+"个同学的成绩:");
score[i] = sc.nextDouble();
//string两种写法
//import java.util.Scanner;
class TestWork604{
public static void main(String[] args){
/**
Scanner sc = new Scanner(System.in);
String s = sc.nextline();
System.out.println(s);
**/
String str = "123454321";
str=str.trim();
boolean flag=isPalindrome(str,0,str.length()-1);
System.out.println("Flag is: "+flag);
}
//spit放入数组
正文
/**
1.java中函数是属于类(class)的,必须定义在类中
2.函数无法自己执行,必须通过调用才可以执行
3.java中:静态方法没有办法直接调用非静态方法,只能调用静态方法
4.有参数的函数,调用时必须传递对应的参数
5.函数中,遇到return则立即结束,并且返回
**/
一.函数定义
/**
java定义函数:
访问修饰符 函数返回子类型|void 函数名称([参数列表]){
函数体;
}
**/
二.函数调用
/**
函数调用:
函数名称([参数列表]);
重点内容:函数在内存的调用本质
栈:先进后出
队列:先进先出
执行栈:
函数怎么调用
局部变量
/**
局部变量(本地变量):定义在函数中,作用域是整个函数类,无法跨越
成员变量:在class中 ,作用域是整个类
**/
三.函数分类
/**
函数分类:
有没有参数:
有参数|无参数(未知输入数据;更加灵活)
有没有返回值:
有返回值|无返回值
定义者:
系统函数|第三者|自定义函数
**/
四.代码
//1.函数定义
//1.函数定义
class TestFun{
public static void main(String[] args){
//函数调用
sayHello ();
//注意,在main函数中,如果要调用非静态方法
//必须使用构建对象的方式(面向对象)
//TestFun tf = new TestFun();
//tf.sayHello;
}
public static void sayHello(){
System.out.println("hello, i am function...");
}
}
//2.函数分类
//2.函数分类01
class TestFun{
public static void main(String[] args){
//函数分类
showInfo ('刘莹',20,‘女’);
}
public static void showInfo (String name, int age,char gender)//形参{
System.out.println("name:" + name);
System.out.println("age:" + age);
System.out.println("gender:" + gender)