一条java算术式java解析xml字符串

 下载
 收藏
该文档贡献者很忙,什么也没留下。
 下载此文档
正在努力加载中...
【精品】表达式求值算法实现
下载积分:800
内容提示:表达式求值算法 表达式求值 表达式求值 java 算术表达式求值 逻辑表达式 求值 先化简再求值 化简求值 对于题目化简并求值
文档格式:DOC|
浏览次数:1|
上传日期: 09:35:20|
文档星级:
该用户还上传了这些文档
下载文档:【精品】表达式求值算法实现.DOC
官方公共微信一个简单java表达式解析的程序 - 下载频道
- CSDN.NET
&&&&一个简单java表达式解析的程序
一个简单java表达式解析的程序
一个简单java表达式解析的程序,需要的可以参考
若举报审核通过,可奖励20下载分
被举报人:
liufei8282
举报的资源分:
请选择类型
资源无法下载
资源无法使用
标题与实际内容不符
含有危害国家安全内容
含有反动色情等内容
含广告内容
版权问题,侵犯个人或公司的版权
*详细原因:
您可能还需要
开发技术下载排行第一题: 图形界面,输入文本地址,在TextFiled里显示内容,点击转换按钮,将大写字母转为小写字母,小写字母转为大写字母并输出在另外一个TextFiled里
&import java.io.F
import java.io.FileInputS
import org.eclipse.swt.widgets.D
import org.eclipse.swt.widgets.S
import org.eclipse.swt.widgets.L
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.T
import org.eclipse.swt.widgets.B
import org.eclipse.swt.events.SelectionA
import org.eclipse.swt.events.SelectionE
import org.eclipse.swt.events.MouseA
import org.eclipse.swt.events.MouseE
public class Task1 {
protected S
private Text textP
private Text textR
private Text textT
* Launch the application.
* @param args
public static void main(String[] args) {
Task1 window = new Task1();
window.open();
} catch (Exception e) {
e.printStackTrace();
* Open the window.
public void open() {
Display display = Display.getDefault();
createContents();
shell.open();
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
* Create contents of the window.
protected void createContents() {
shell = new Shell();
shell.setSize(450, 300);
shell.setText(&\uC\u7F16\u8F91\u5668&);
Label label = new Label(shell, SWT.NONE);
label.setBounds(32, 36, 63, 13);
label.setText(&\u\u8DEF\u5F84\uFF1A&);
textPath = new Text(shell, SWT.BORDER);
textPath.setBounds(121, 36, 266, 19);
Button buttonRead = new Button(shell, SWT.NONE);
buttonRead.addMouseListener(new MouseAdapter() {
public void mouseUp(MouseEvent e) {
String path = textPath.getText();
byte bytes[]= new byte[1024];
int index=0;
File file = new File(path);
if(!file.exists())
textRecord.setText(&文本不存在&);
FileInputStream is = new FileInputStream(file);
while((index = is.read(bytes,0,1024))&0){
String str = new String(bytes,0,index);
textRecord.setText(str);
catch(Exception ee){ee.printStackTrace();}
buttonRead.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
buttonRead.setBounds(71, 71, 82, 23);
buttonRead.setText(&\u8BFB\u5165&);
Button buttonTrans = new Button(shell, SWT.NONE);
buttonTrans.addMouseListener(new MouseAdapter() {
public void mouseUp(MouseEvent e) {
if(textRecord.getText()==null){
textTran.setText(&文本域为空&);
String text=
byte bytes[] = new byte[1024];
char chs[]= new char[1024];
bytes = textRecord.getText().toString().getBytes();
chs = textRecord.getTextChars();
int len = textRecord.getCharCount();
int index =0;
while(index&len){
if(chs[index]&=122&&chs[index]&=97)
chs[index] = (char)((int)chs[index]-32);
else if(chs[index]&=65&&chs[index]&=90)
{chs[index] = (char)((int)chs[index]+32);}
textTran.setText(String.valueOf(chs));
}catch(Exception ee){ee.printStackTrace();}
buttonTrans.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
buttonTrans.setBounds(248, 71, 82, 23);
buttonTrans.setText(&\u8F6C\u6362&);
textRecord = new Text(shell, SWT.BORDER);
textRecord.setBounds(34, 100, 166, 137);
textTran = new Text(shell, SWT.BORDER);
textTran.setBounds(238, 100, 166, 137);
第二题,套接字,客户端输入一个算术式:2+3=,服务器端算出结果,返回到客户端
import java.io.*;
import java.net.*;
public class Task2Client {
* @param args
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println(&开始连接服务器&);
Socket socket = new Socket(&localhost&, 8888);
System.out.println(&已经连接服务器&);
OutputStream os= socket.getOutputStream();
InputStream is = socket.getInputStream();
byte bytes[] = new byte[3];
//InputStreamReader isr = new InputStreamReader(System.in);
char chs[] = new char[50];
int index =0;
System.in.read(bytes);
os.write(bytes);
System.out.println(&已经发送&);
InputStreamReader isr = new InputStreamReader(is);
index=isr.read(chs);
System.out.println(new String(chs,0,index));
}catch(Exception e){e.printStackTrace();}
//服务器端
import java.io.*;
import java.net.*;
public class Task2Server {
* @param args
public static void main(String[] args) {
// TODO Auto-generated method stub
ServerSocket ss = new ServerSocket(8888);
System.out.println(&服务器开启&);
Socket socket = ss.accept();
System.out.println(&找到客户端&);
InputStream is = socket.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
OutputStream os= socket.getOutputStream();
PrintWriter pw = new PrintWriter(os);
char chs[] = new char[3];
int index =0;
float r=0;
while(isr.read(chs)!=-1){
int a = Integer.parseInt(String.valueOf(chs[0]));
int b = Integer.parseInt(String.valueOf(chs[2]));
if(chs[1]=='+')
pw.write(String.valueOf(r));
pw.flush();
System.out.println(r);
else if(chs[1]=='-')
pw.write(String.valueOf(r));
pw.flush();
System.out.println(r);
else if(chs[1]=='*')
pw.write(String.valueOf(r));
pw.flush();
System.out.println(r);
else if(chs[1]=='/')
pw.write(String.valueOf(r));
pw.flush();
System.out.println(chs);
System.out.println(r);
pw.write(&Error&);
pw.flush();
System.out.println(chs);
System.out.println(&Error&);
/*Socket ssocket =new Socket(&localhost&,8889);
OutputStream os =ssocket.getOutputStream();
OutputStreamWriter osw= new OutputStreamWriter(os);*/
isr.close();
is.close();
socket.close();
ss.close();
}catch(Exception e){e.printStackTrace();}
第三题:数据库操作,算平均分
import java.sql.*;
public class Task3 {
* @param args
public static void main(String[] args) {
// TODO Auto-generated method stub
String url =&jdbc:mysql://127.0.0.1:3306/test&;
String user = &root&;
String password =&&;
String driver =&com.mysql.jdbc.Driver&;
Connection conn =
PreparedStatement sql =
ResultSet rs =
String name=
float java = 0;
float j2ee =0;
float aver = 0;
Class.forName(driver);
conn =DriverManager.getConnection(url,user,password);
System.out.println(&连接数据库成功&);
sql = conn.prepareStatement(&select * from score where 1&);
rs = sql.executeQuery();
while(rs.next())
id = rs.getInt(1);
name = rs.getString(2);
java = rs.getFloat(3);
j2ee = rs.getFloat(4);
aver = rs.getFloat(5);
System.out.println(&ID:&+id+& Name:&+name+& Java:&+java+& J2EE&+j2ee+& AverageScroe:&+aver);
System.out.println(&计算平均成绩并存入数据库&);
sql = conn.prepareStatement(&select * from score where 1&);
rs = sql.executeQuery();
while(rs.next())
id = rs.getInt(1);
name = rs.getString(2);
java = rs.getFloat(3);
j2ee = rs.getFloat(4);
aver =(java+j2ee)/2;
sql = conn.prepareStatement(&update score set averagescroe='&+aver+&' where id='&+id+&'&);
sql.executeUpdate();
System.out.println(&输出数据&);
sql = conn.prepareStatement(&select * from score where 1&);
rs = sql.executeQuery();
while(rs.next())
id = rs.getInt(1);
name = rs.getString(2);
java = rs.getFloat(3);
j2ee = rs.getFloat(4);
aver = rs.getFloat(5);
System.out.println(&ID:&+id+& Name:&+name+& Java:&+java+& J2EE&+j2ee+& AverageScroe:&+aver);
rs.close();
sql.close();
conn.close();
}catch(Exception e){e.printStackTrace();}
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:351630次
积分:4270
积分:4270
排名:第2521名
原创:102篇
转载:114篇
评论:76条
(6)(1)(11)(8)(3)(3)(1)(7)(2)(2)(3)(4)(3)(3)(4)(2)(2)(6)(29)(8)(1)(16)(3)(6)(8)(9)(19)(18)(10)(18)java算术运算符 算术运算测试系统 java算术测试 shell 算术运算 算术运算符 小学算..
扫扫二维码,随身浏览文档
手机或平板扫扫即可继续访问
Java算术运算测试程序
举报该文档为侵权文档。
举报该文档含有违规或不良信息。
反馈该文档无法正常浏览。
举报该文档为重复文档。
推荐理由:
将文档分享至:
分享完整地址
文档地址:
粘贴到BBS或博客
flash地址:
支持嵌入FLASH地址的网站使用
html代码:
&embed src='/DocinViewer-4.swf' width='100%' height='600' type=application/x-shockwave-flash ALLOWFULLSCREEN='true' ALLOWSCRIPTACCESS='always'&&/embed&
450px*300px480px*400px650px*490px
支持嵌入HTML代码的网站使用
您的内容已经提交成功
您所提交的内容需要审核后才能发布,请您等待!
3秒自动关闭窗口Posts - 54,
Articles - 0,
Comments - 30
掌控自己,掌控所有可能。
00:30 by Coding Bear, ... 阅读,
动手有益。
输入一个表达式,没有括号,数字小于0-9之间,输出计算结果,所有的中间结果化为整形。例如: &输入:3+8&2/9-2 &输出:2 &
* input a calculate string, calcuate the value
* the number between 0-9
* round the middle vlaue to int
public static void main(String[] args) {
//8*6+2-6/3*6+2
S//=new Scanner(System.in).nextLine();
cal="8*6+2-6/3*6+2";
String[] car=new String[cal.length()];
for (int i = 0; i & car. i++) {
car[i]=""+cal.charAt(i);
System.err.println(car);
//do * and /
for (int i = 0; i & car. i++) {
if(car[i].equals("*"))
car[i+1]= ""+(Integer.parseInt(car[i-1]) * Integer.parseInt(car[i+1]));
car[i-1]="";
car[i]="";
}else if(car[i].equals("/"))
car[i+1]= ""+(Integer)(Integer.parseInt(car[i-1]) / Integer.parseInt(car[i+1]));
car[i-1]="";
car[i]="";
//do + and -
int index=0;
for (int i = 0; i & car. i++) {
if(car[i].equals("+"))
while(car[++index].equals("")){}
car[index]= ""+(Integer.parseInt(car[i-1]) + Integer.parseInt(car[index]));
car[i-1]="";
car[i]="";
}else if(car[i].equals("-"))
while(car[++index].equals("")){}
car[index]= ""+(Integer.parseInt(car[i-1]) - Integer.parseInt(car[index]));
car[i-1]="";
car[i]="";
System.err.println(cal+" = "+car[car.length-1]);}

我要回帖

更多关于 java dom4j解析xml 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信