㈠ eclipse中运行一个继承的java实例报错:方法 main 不能声明为“静态”,只能在静态类型或顶级类型中才能声明
main方法必须放在主类里面,也就是说应该是这样子的
import java.util.NoSuchElementException;
import javax.swing.*;
class Node
{
int data;
Node next;
Node(int dat)
{
data = dat;
next = null;
}
}
class LinkedList{
Node tail;
int count;
public LinkedList(){
tail=null;
count=0;
}
public void insertAt(int item,int index){
if(index<0 || index>=count){
throw new IndexOutOfBoundsException(index+"<0 or >"+(count-1));
}
Node pred=tail;
for(int i=0;i<index;i++)
pred=pred.next;
Node itemnode=new Node(item);
itemnode.next=pred.next;
pred.next=itemnode;
count++;
}
public int removeAt(int index){
if(index<0 || index>=count){
throw new IndexOutOfBoundsException(index+"<0 or >"+(count-1));
}
Node prev=tail;
for(int i=0;i<index;i++)
prev=prev.next;
Node curr=prev.next;
if(count==1){
tail=null;
tail.next=null;
}
else{
prev.next=curr.next;
if(index==count-1)
tail=prev;
}
count--;
return curr.data;
}
}
public class ex7_1
{
public static void main(String args[]){
String s;
int i,n,a,b,c,item;
LinkedList L=new LinkedList();
s=JOptionPane.showInputDialog("请输入第一个元素:");
i=Integer.parseInt(s);
s=JOptionPane.showInputDialog("该链表共有元素:");
n=Integer.parseInt(s);
Node p=new Node(i);
L.tail=p;L.count+=1;
for(int m=0;m<n-1;m++)
{ s=JOptionPane.showInputDialog("请再输入一个元素:");
i=Integer.parseInt(s);
p=new Node(i);
p.next=L.tail;
L.count++;
}
L.tail.next=p;
while(L.count-->0)
{
System.out.print(p.data+" ");
p=p.next;
}
s=JOptionPane.showInputDialog("请把元素a插入:");
a=Integer.parseInt(s);
s=JOptionPane.showInputDialog("插入第b个元素前:");
b=Integer.parseInt(s);
L.insertAt(a,b);
System.out.println("把元素"+a+"插入元素"+b+"之前");
for(int j=0;j<L.count;j++)
{
System.out.print(p.data+" ");
p=p.next;
}
System.out.println();
s=JOptionPane.showInputDialog("把第个c(0<=c<count)元素删除:");
c=Integer.parseInt(s);
item=L.removeAt(c);
System.out.println("把第"+c+"个元素"+item+"删除");
}
}
㈡ 谁能给我一个用Eclipse创建java包的实例,步骤详细点
然后建java文件啊
㈢ java写的用户登陆实例,用eclipse开发的具体步奏和代码
java写的用户登录实例,实际页面展示使用的jsp,那么下面是jsp的登录页面代码:
1、login.jsp代码
<%
string name = request.getparameter("username");
string pwd = request.getparameter("password");
//out.println(name+pwd);
string sql ="select * from info where username='"+name+"' and password='"+pwd+"'";
//out.println(sql);
statement stm= null;
resultset rs =null;
try
{
stm = conn.createstatement();
rs = stm.executequery(sql);
if(rs.next())
{
session.setattribute("username",name);
response.sendredirect("index.html");
}
else
{
response.sendredirect("index1.html");
}
}
catch(sqlexception e)
{
e.printstacktrace();
}
%>
<!--登录的表单-->
<form name="form1" method="post" action="login.jsp">
<p>
<label for="username"></label> 用户名
<input type="text" name="username" id="username">
</p>
<p>
<label for="passwrod"></label> 密码
<input type="text" name="passwrod" id="passwrod">
</p>
<p>
<input type="submit" name="button" id="button" value="提交">
</p>
</form>
2、用户信息表,存放用户名和密码:
user_info 表
create table if not exists `test` (
`id` int(8) not null auto_increment,
`username` char(150) default null,
`password` varchar(32),
`times` int(4) not null,
primary key (`id`)
) engine=myisam default charset=utf8 auto_increment=1 ;
㈣ 如何用eclipse运行别人的java实例
楼主你好:
首先你要确定他给你的是不是Eclipse项目。如果是的话。
打开eclipse
File-->import...
选general里面的existing projects into workspace
找到那个项目导进来就可以了。
满意请采纳。
㈤ 怎么用eclipse编写java程序
使用eclipse编写和运行java程序(基础)
1.首先java程序的运行你需要下载和安装JDK,这是java运行的必备环境。
2.在桌面上找到eclipes,双击打开。
3.在eclipes启动的过程中,会弹出一个窗口,让你填写java工作区的保存目录,在这个目录下会保存你写的所有的源代码文件,建议不要把工作区放在C盘
注:修改工作区路径 File -> Switch Workspace
4.ecplies启动完成之后,会有一个欢迎页面,这个不用管,直接点击左上方的差号,取消掉就可以了,随后就进入eclipes的主界面。
5.新建项目:点击左上角的file =》new =》java-Project,弹出一个小窗口,填上项目名称点击确认。
6.创建包:点击项目,打开它找到src,右键点击new =》package, 写上包名,点击确认。
7.创建java文件:右键软件包,在软件包下创建一个java文件,右键 点击new =》class
8.编写:在源代码编辑器中写上源代码。并且保存。
9,运行:右键文件浏览器中的java文件,再点击run as,下面命令行窗口中机会出现运行结果。
㈥ Java项目实例,写在文件夹里,里面有好多东西,我不知道怎么运行这个实例啊,怎么弄到eclipse里面运行啊
打开eclipse后,在File里有个import,你import exist project就行了