JAVA 包的问题 谢谢解答!!

xtuyaowu 2005-03-10 05:58:53
各位大哥大姐好!!学生初学JAVA
给一个程序写了一个包,觉得有问题但是查不出来,请求帮助!
另外import 包后总是 NOT EXIST??
包://主要是实现数据输入

package liao.prefect.ecommerce;
import java.io.*;
public class ConsoleReader
{ ConsoleReader(){} //这里觉得有问题!!
public static String readLine(){
StringBuffer response=new StringBuffer();
try{
BufferedInputStream buff=new BufferedInputStream(System.in);
int in=0;
char inChar;
do{
in=buff.read();
inChar=(char)in;
if(in!=-1){
response.append(inChar);


}
}while((in !=-1)&(inChar !='\n'));
buff.close();
return response.toString();
} catch(IOException e){
System.out.println("Exception:"+e.getMessage());
return null;
}

}

public static int readInt () //这个方法也不行!!!
{try{
BufferedInputStream buff=new BufferedInputStream(System.in);
int in=0;
char inChar;
do{
in=buff.read();

}while(in !=-1);
buff.close();
return in;
}

catch(IOException e){
System.out.println("Exception:"+e.getMessage());
return 0;}
} }

调用包:import liao.prefect.ecommerce.*;
public class Search
{
public static int[] Data=
{1,7,9,12,15,16,20,32,35,67,78,80,83,89,90,92,97,108,120,177};
public static int Counter =1;
public static void main(String[] args)
{
System.out.println("please enter your key value:");
ConsoleReader console =new ConsoleReader(System.in);//这个在包里怎么对应??
int KeyValue =console.readInt();
if(Seq_Search((int)KeyValue))
{
System.out.println("");
System.out.println("Search time ="+(int)Counter);
}
else
{
System.out.println("");
System.out.println("No found!!");
}
}

public static boolean Seq_Search(int Key)
{int i;
for(i=0;i<20;i++)
{
System.out.println("["+(int)Data[i]+"]");
if((int)Key==(int)Data[i])
return true;
Counter++;
}
return false;
}
}

另外我们学校老师在上数据结构(C 语言版)我该怎么处理,与JAVA的关系!!
...全文
177 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
xtuyaowu 2005-03-24
  • 打赏
  • 举报
回复
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
public class jdbc //定义主类
{ public static void main(String args[])
{
GUI gui=new GUI();//创建类GUI的对象
gui.pack(); //装载执行GUI类
}
}

class GUI extends Frame implements ActionListener
{

TextArea text;Panel panel; TextField sno;Button btn;
GUI()//构造方法
{
super("学生情况查询制作~~~姚伍");
setLayout(new BorderLayout());
setBackground(Color.cyan);
setVisible(true); text=new TextArea();
btn=new Button("查询");
sno=new TextField(16);
panel=new Panel();
panel.add(new Label("输入被查询的学生学号(限10位数字)"));
panel.add(sno);panel.add(btn);
add("North",panel);add("Center",text);
text.setEditable(false);btn.addActionListener(this);
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e)
{
setVisible(false);
System.exit(0);}});}

public void actionPerformed(ActionEvent e){
if(e.getSource()==btn)// 当按下查询按钮时
{text.setText("查询结果"+'\n');
try{
Liststudent();
}
catch(SQLException ee){}
}
}


public void Liststudent() throws SQLException//针对数据库的操作
{
String xh,xm,xb,nl,em,tl;

try{

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}
catch(ClassNotFoundException e){}

Connection con=DriverManager.getConnection("jdbc:odbc:wzgl");//wagl 为数据源名称

Statement sql=con.createStatement();//创建Statement对象

ResultSet rs=sql.executeQuery("select* from xsqk"); //xsqk 数据表
while(rs.next()) //输出被查询的情况
{ xh =rs.getString("学号");
xm=rs.getString("姓名");
xb=rs.getString("性别");
nl=rs.getString("年龄");
em=rs.getString("E—Mail");
tl=rs.getString("电话");
if(xh.trim().equals(sno.getText().trim()))
{
text.append('\n'+"学号"+" "+"姓名"+" "+"性别"+" "+"年龄"+" "+"E-Mail"+" "+"电话"+'\n');
text.append('\n'+xh+" "+xm+" "+xb+" "+nl+" "+em+" "+tl+'\n');


}

}

}
}
xtuyaowu 2005-03-12
  • 打赏
  • 举报
回复
做如下修改 能编译通过 但是运行的时候不行 输入数字后 他就停了!!
大家看看!!!!


package liao;
import java.io.*;
public class ConsoleReader
{ String str;
public ConsoleReader()
{

}
public static String readLine(){
StringBuffer response=new StringBuffer();
try{
BufferedInputStream buff=new BufferedInputStream(System.in);
int in=0;
char inChar;
do{
in=buff.read();
inChar=(char)in;
if(in!=-1){
response.append(inChar);


}
}while((in !=-1)&(inChar !='\n'));
buff.close();
return response.toString();
} catch(IOException e){
System.out.println("Exception:"+e.getMessage());
return null;
}

}

public static int readInt () {
try{
BufferedInputStream buff=new BufferedInputStream(System.in);
int in=0;

do{
in=buff.read();

}
while(in !=-1);
buff.close();
return in;
} catch(IOException e){
System.out.println("Exception:"+e.getMessage());
return 0;}
}
}



import liao.*;
public class Search
{
public static int[] Data=
{1,7,9,12,15,16,20,32,35,67,78,80,83,89,90,92,97,108,120,177};
public static int Counter =1;
public static void main(String[] args)
{
System.out.println("please enter your key value:");
ConsoleReader console =new ConsoleReader();
int KeyValue =console.readInt();
if(Seq_Search((int)KeyValue))
{
System.out.println("");
System.out.println("Search time ="+(int)Counter);
}
else
{
System.out.println("");
System.out.println("No found!!");
}
}

public static boolean Seq_Search(int Key)
{int i;
for(i=0;i<20;i++)
{
System.out.println("["+(int)Data[i]+"]");
if((int)Key==(int)Data[i])
return true;
Counter++;
}
return false;
}
}
liqun5218 2005-03-11
  • 打赏
  • 举报
回复
1:ConsoleReader console =new ConsoleReader(System.in); //这里有错
ConsoleReader中没定义ConsoleReader(InputStream in)这个构造方法,应该在ConsoleReader设定这个构造方法
2:在Search中要调用liao.prefect.ecommerce.ConsoleReader,那么ConsoleReader的构造函数必须设为public,也可以把Search放到liao.prefect.ecommerce这个包下
xtuyaowu 2005-03-10
  • 打赏
  • 举报
回复
环境变量没问题 可就是不行 。各位能否试试!!!
layueer 2005-03-10
  • 打赏
  • 举报
回复
c语言和java语法都很类似,只是不是面向对象的,但很多算法都可以用
贝壳鱼 2005-03-10
  • 打赏
  • 举报
回复
程序应该是没问题的,,不知道你的环境变量设置如何
愤怒的不争 2005-03-10
  • 打赏
  • 举报
回复
我觉得 编译Search 之前要编译 ConsoleReader。 只有 ConsoleReader 编译通过了,才能把ConsoleReader.class import 到 Search。

另外,Search.java 要和 ConsoleReader.java在同一目录下!

我也知道这么多了!

13,100

社区成员

发帖
与我相关
我的任务
社区描述
Java J2ME
社区管理员
  • J2ME社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧