import java.io.*;
import java.lang.*;
public class Test {
public String b[] = {"aaaa","bbbb","cccc","dddd","eeee"};
public BufferedReader in;
public Test() {
in = new BufferedReader(new InputStreamReader(System.in));
} public boolean xunhuan(String s) {
for(int i=0;i<b.length;i++){
if(s.equals(b[i]) ) {
System.out.println("yep");
return true;
}
}
System.out.println("wrong");
return false;
} public static void main(String[] args) throws IOException{
Test temp=new Test();
System.out.println("Enter a word let me correct it:"); String str = temp.in.readLine();
temp.xunhuan(str);
}
}
import java.lang.*;
public class Test {
public String b[] = {"aaaa","bbbb","cccc","dddd","eeee"};
public BufferedReader in;
public Test() {
in = new BufferedReader(new InputStreamReader(System.in));
} public boolean xunhuan(String s) {
for(int i=0;i<b.length;i++){
if(s.equals(b[i]) ) {
System.out.println("yep");
return true;
}
}
System.out.println("wrong");
return false;
} public static void main(String[] args) throws IOException{
Test temp=new Test();
System.out.println("Enter a word let me correct it:"); String str = temp.in.readLine();
temp.xunhuan(str);
}
}
解决方案 »
- 想知道这个方法的用法
- jdbc里怎么一次只从数据库读取一个数据而不是一行数据
- 关于服务器并发数的测试疑问
- com.sun.image.codec.jpeg包,哪里有啊??
- 求助JComboBox组件的鼠标响应事件和键盘事件的代码!在线等待。20分
- servlet的doGet(), doPost(), doPut(), doDelete()是响应哪些请求的方法啊?请描述一下,谢谢
- 关于jar文件的类路径(在线)
- 请教我为何在jb7下不能使用连接池
- 怎样为Java Application加背景图片?
- 请教大神一个小白问题。。。如何做一个计算器出来
- **jayde(胡不归) 和tuhongyu(牵着老鼠打劫) 进来**
- 初学者的问题,关于方法的调用
不过从控制台读入字符串,可以
public class Test
{
public static void main(String args[])
{
String str1=args[0];
String str2=args[1];
System.out.println(str1);
} System.out.println(str2);
}例如在命令行下
c:\java Test hello world!
hello就是args[0],world!就是args[1]
在程序中就可以引用args数组
import java.io.*;
import java.lang.*;
import java.sql.*;
import java.util.*;public class test {
public String[] b;
// public String b[]={"aaaa","bbbb","cccc","dddd","eeee"};//storge the data
public BufferedReader in;
public test() {
in = new BufferedReader(new InputStreamReader(System.in));
}
public void DataAccess() throws ClassNotFoundException, SQLException{
ResultSet rs=null;
Connection con=null;
Statement stmt=null;
ArrayList m = new ArrayList();
String query = "select word from words";
String url = "jdbc:odbc:dsn";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con =DriverManager.getConnection(url,"", "");
stmt = con.createStatement(); rs = stmt.executeQuery(query);
while (rs.next()) {
m.add(rs.getString(1));
}
stmt.close();
con.close();
b = new String[m.size()];
for(int i =0 ;i<m.size();i++)
b[i] = (String )m.get(i);
}
public boolean xunhuan(String s) {//check word correst or not
for(int i=0;i<b.length;i++){
if(s.equals(b[i]) ){
System.out.println("yep");
return true;
}
}
System.out.println("wrong");
return false;
}
public static void main(String[] args) throws IOException{
test temp=new test();
System.out.println("Enter a word let me correct it:");//enter word
String str = temp.in.readLine();//read a word from console
temp.xunhuan(str);//test it from xunhuan method
}
}
这是我的全部程序,可以编译,当我输入任何单词的时候他都说
Enter a word let me correct it:
men
java.lang.NullPointerException
at test.xunhuan(test.java:43)
at test.main(test.java:59)
Exception in thread "main"
怎么回事?
这样盲目的做程序没有用。