long[] a不是静态变量,不能被静态方法所引用
成都创新互联公司专业为企业提供无锡网站建设、无锡做网站、无锡网站设计、无锡网站制作等企业网站建设、网页设计与制作、无锡企业网站模板建站服务,十年无锡做网站经验,不只是建网站,更提供有价值的思路和整体网络服务。
修改方法一:在long[] a 前面增加 static;
修改方法二:将long[] a=new long[10]; 整句移入main方法里面;
修改方法三:main方法里面不要引用a[];
int[] numbers = new int[5]{1,2,3,4,5};
public int indexOf(int n){
for(int i = 0; i numbers.length; i++){
if(numbers[i] == n){
return i;
}
}
return -1;
}
public class ef {
public static void main(String[] args) {
int[] a = { 4, 8, 12, 44, 69, 71, 98, 132 ,133};
int m = ef.ef(a, 0, a.length, 71);
if(m!=-1){
System.out.println(a[m]+"====="+m);
}
System.out.println("不存在该数字");
}
public static int ef(int[] a, int from, int to, int b) {
int midel = (from + to) / 2;
if ((to - from) = 1 b != a[midel]) {
return -1;
}
if (b a[midel]) {
return ef(a, midel, to, b);
} else if (b a[midel]) {
return ef(a, from, midel, b);
} else {
return midel;
}
}
}
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
//import java.awt.List;
public class Query {
public ListUserVo showUser(){
Connection conn=null;
Statement stmt=null;
ResultSet rs=null;
ListUserVo list=new ArrayListUserVo();
try{
conn=JDBC_Connection.getConnection();
stmt=conn.createStatement();
rs=stmt.executeQuery("select * from users");
while(rs.next()){
UserVo userVo=new UserVo();
userVo.setId(rs.getInt("id"));
userVo.setName(rs.getString("name"));
userVo.setAge(rs.getInt("age"));
userVo.setTel(rs.getString("tel"));
userVo.setAddress(rs.getString("address"));
list.add(userVo);
}
}catch(SQLException e){
e.printStackTrace();
}finally{
JDBC_Connection.free(rs, conn, stmt);
}
return list;
}
public static void main(String[] args) {
Query query=new Query();
ListUserVo list=query.showUser();
if(list!=null){
System.out.print("id\t");
System.out.print("name\t");
System.out.print("age\t");
System.out.print("tel\t");
System.out.print("address\t");
System.out.println();
for(int i=0;ilist.size();i++){
System.out.print(list.get(i).getId()+"\t");
System.out.print(list.get(i).getName()+"\t");
System.out.print(list.get(i).getAge()+"\t");
System.out.print(list.get(i).getTel()+"\t ");
System.out.print(list.get(i).getAddress()+"\t");
System.out.println();
}
}
}
}
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class RegexTestHarnessV5 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
while (true) {
System.out.printf("输入你要查找的文字: ");
Pattern pattern = Pattern.compile(scanner.nextLine());
System.out.printf("输入字符串: ");
Matcher matcher = pattern.matcher(scanner.nextLine());
boolean found = false;
while (matcher.find()) {
System.out.printf("找到 \"%s\" 开始下标 %d 结束下标 %d.%n",
matcher.group(), matcher.start(), matcher.end());
found = true;
}
if (!found) {
System.out.printf("没有找到.%n");
}
}
}
}
private static String str = "5,95,137.5,125";
public static void main(String[] args) {
String first = str.substring(0, str.indexOf(","));
int firstNum = Integer.parseInt(first);
if(firstNum 5) {
System.out.println(1);
}else if(firstNum == 5) {
System.out.println(0);
}else {
System.out.println(2);
}
}