公式转java代码 java 公式

已知曲线的公式,如何用JAVA编程将曲线显示出来,要JAVA源代码

代码如下,只是时间仓促有些简陋,没有坐标轴,而且大小比例问题也没有调好。不过功能实现了。嘎嘎,新手上路,腾云驾雾。

目前创新互联建站已为超过千家的企业提供了网站建设、域名、网页空间、绵阳服务器托管、企业网站设计、尼木网站维护等服务,公司将坚持客户导向、应用为本的策略,正道将秉承"和谐、参与、激情"的文化,与客户和合作伙伴齐心协力一起成长,共同发展。

import java.awt.Graphics;

import javax.swing.JFrame;

import javax.swing.JPanel;

public class Bbso extends JPanel{

int x,y,x1,y1,m=100;

double d;

public Bbso() {

JFrame f = new JFrame();

f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

f.setBounds(100,100,500,300);

f.setTitle("画曲线");

f.setVisible(true);

f.getContentPane().add(this);

}

public static void main(String arg[]) {

new Bbso();

}

public void paint(Graphics g) {

super.paintComponent(g);

x1=0;

y1=0;

for(x=-250;x250;x++) {

d=-0.2045*x*x+100.41*x-6736.8; //这里填写公式

y=(int)d;

g.drawLine(x1,y1+m,x,y+m);

x1=x;

y1=y;

}

}

}

这几个公式怎么转化为python或java代码,有没有啥 博客支持和数学高手解答一下??

import os def readPro(): try: res = os.popen("cmd /c aws start"); print res.read(); except: print "Exception"; raise finally: print "Done!"; if __name__ == '__main__': readPro()

输入运算公式 得到结果 java

通过栈实现,先用栈将中缀表达式转化为后缀表达式,然后再用栈计算后缀表达式的值的

package com.saturday;

import java.text.NumberFormat;

import java.util.ArrayList;

import java.util.HashMap;

import java.util.List;

import java.util.Map;

import java.util.Stack;

import java.util.regex.Matcher;

import java.util.regex.Pattern;

public class MyParse {

static MapString,Integer optrOrder;

static {

optrOrder=new HashMapString,Integer();

optrOrder.put("(", 0);

optrOrder.put("*", 1);

optrOrder.put("/", 1);

optrOrder.put("%", 1);

optrOrder.put("+",2);

optrOrder.put("-",2);

optrOrder.put("^",3);

optrOrder.put("#",3);

}

public static void main(String[] args){

ListString tokens;

try{

//词法分析

tokens=lex("+2* (-2+3*4)+-5");

//中缀转后缀

tokens=toRpn(tokens);

//计算结果

System.out.println(calcRpn(tokens));

}catch(Exception ex){

ex.printStackTrace();

}

}

/**

* 将输入串转换为操作符串

* @param sExpres

* @return

*/

public static ListString lex(String sExpres){

ListString tokens=new ArrayListString();

//将表达式分割成符号序列

String sRegExp="(((?=^|\\(|\\+|-|\\*|/|%)(\\+|-))?\\d+(\\.\\d+)?)"

+"|\\(|\\)|\\*|/|\\+|-";

Pattern p=Pattern.compile(sRegExp);

Matcher m=p.matcher(sExpres.replaceAll("\\s+",""));

while(m.find()){

tokens.add(m.group());

}

tokens.add("#");

return tokens;

}

/**

* 将中缀表单时转化为后缀表达式

* @param tokens

* @return

*/

public static ListString toRpn(ListString tokens)

throws Exception{

ListString rpnList=new ArrayListString();

StackString optrStack=new StackString();

optrStack.add("^");

for(String token:tokens){

if(token.matches("^(\\+|-)?\\d+(\\.\\d+)?$")){

rpnList.add(token);

}else{

outputOptr(token,optrStack,rpnList);

}

}

if(!optrStack.isEmpty()

optrStack.lastElement().equals("#")){

return rpnList;

}else{

throw new Exception("后缀表达式转化错误!");

}

}

/**

* 计算后缀表达式的值

* @param rpnTokens

* @return

* @throws Exception

*/

public static double calcRpn(ListString rpnTokens)

throws Exception{

NumberFormat nf=NumberFormat.getInstance();

StackDouble numStack=new StackDouble();

for (String token : rpnTokens) {

if (token.matches("^(\\+|-)?\\d+(.\\d+)?$")) {

token=token.indexOf('+')==0

?token.substring(1)

:token;

numStack.add(nf.parse(token).doubleValue());

} else {

doCalcByOptr(token, numStack);

}

}

if (!numStack.isEmpty() numStack.size() == 1) {

return numStack.lastElement();

} else {

throw new Exception("计算错误!");

}

}

/**

* 将运算符输出到后缀表达式序列.

* @param optr

* @param optrStack

* @param rpnList

* @throws Exception

*/

public static void outputOptr(String optr,

StackString optrStack,

ListString rpnList)

throws Exception{

String preOptr;

if(optr.equals("(")){//处理左括号

optrStack.push(optr);

return;

}

if(optr.equals(")")){//处理右括号

while(!optrStack.isEmpty()){

preOptr=optrStack.pop();

if(!preOptr.equals("(")){

rpnList.add(preOptr);

}else{

break;

}

}

if(optrStack.isEmpty()){

throw new Exception("括号未闭合!");

}

return;

}

/*按优先级处理其他运算符,若当前运算符优先级较高

* 直接入栈,否则将栈中运算符出战直至栈顶运算符

* 低于当前运算符

*/

preOptr=optrStack.lastElement();

if(optrCmp(optr,preOptr)0){

optrStack.push(optr);

}else{

while(!preOptr.equals("(")

!optrStack.isEmpty()

optrCmp(optr,preOptr)=0){

preOptr=optrStack.pop();

if(!preOptr.equals("^")){

rpnList.add(preOptr);

}

}

optrStack.push(optr);

}

}

/**

* 运算符优先级比较函数,optr1优先级大于optr2返回小于0值,

* 优先级相等返回0,optr1小于optr2返回大于0值.

* @param optr1

* @param optr2

* @return

*/

public static int optrCmp(String optr1,String optr2){

int order1=optrOrder.get(optr1);

int order2=optrOrder.get(optr2);

return order1-order2;

}

/**

* 根据运算符对数据栈中的内容进行操作.

* @param optr

* @param numStack

*/

public static void doCalcByOptr(String optr,

StackDouble numStack){

double n1,n2;

n2=numStack.pop();

n1=numStack.pop();

if(optr.equals("+")){

numStack.push(n1+n2);

}else if(optr.equals("-")){

numStack.push(n1-n2);

}else if(optr.equals("*")){

numStack.push(n1*n2);

}else if(optr.equals("/")){

numStack.push(n1/n2);

}else if(optr.equals("%")){

numStack.push(n1%n2);

}

}

}

为什么java中将数学公式转换为java表达式要报错

Javascript中的类型转换 :首先我们可以看C中间的强制类型转换,只能存在整数可表示类型和浮点数类型之间,比如(int)2.45,这是可以的,但是他们和字符串之间都没有强制转换的可能,因为字符串实际是一个指针。因此不可能出现(char *)2.45就可以获得"2.45"这个字符串的情况,反之也不能。而在C++中,我们可以创建一个类,并且重载强制转换操作,来完成这种情况,那么就必须要求有相应的对象,但是对于基本类型,这也是不可以的。然后,因为JavaScript在对象模型上主要参考了Java,我们可以再参考一下Java的类型转换:在Java中,基本类型之间的强制转换也不是这样的,比如,整数要转换成字符串,必须使用Integer.toString()静态方法或者String.valueOf()静态方法,把字符串转换为整数,必须使用Integer.valueOf()。可见,不能把JavaScript中的类型转换看作为“强制类型转换”。在JavaScript中,Double类型和Int类型都是看作为Number对象,因此无论是typeof 1还是typeof 1.0,都是返回number。这样我们可以不用去管是Int还是Double类型,让JavaScript解释引擎内部去处理。

javascript有两种数据类型的转换方法:一种是将整个值从一种类型转换为另一种数据类型(称作基本数据类型转换),另一种方法是从一个值中提取另一种类型的值,并完成转换工作。

基本数据类型转换的三种方法:1.转换为字符型:String(); 例:String(678)的结果为"678"。2.转换为数值型:Number(); 例:Number("678")的结果为678。3.转换为布尔型:Boolean(); 例:Boolean("aaa")的结果为true。

把公式套到java代码里

public class Test{

public int abs(int n) {

if(n0)

return -n;

return n;

}

public void get() {

int sum = 1 - (25-abs(23)/23);

System.out.println(sum);

}

public static void main(String[] args) {

Test t = new Test();

t.get();

}

}

你可以把需求讲的更详细一点!

用Excel公式实现文本转Java输出文本的问题

public class Excel {

private jxl.Workbook rwb = null;

/**

* 得到当前工作薄的总列数

*

* @parma sheetIndex 工作薄号

* @return int

*/

public int getColCount(int sheetIndex) {

int colCnt = 0;

try {

jxl.Sheet rs = rwb.getSheet(sheetIndex);

colCnt = rs.getColumns();

} catch (Exception e) {

colCnt = 0;

} finally {

try {

} catch (Exception e) {

colCnt = 0;

}

}

return colCnt;

}

/**

* 得到当前工作薄的总行数

*

* @parma sheetIndex 工作薄号

* @return int

*/

public int getRowCount(int sheetIndex) {

int colCnt = 0;

try {

jxl.Sheet rs = rwb.getSheet(sheetIndex);

colCnt = rs.getRows();

} catch (Exception e) {

colCnt = 0;

} finally {

try {

} catch (Exception e) {

colCnt = 0;

}

}

return colCnt;

}

/**

* 打开Excel.

*

* @parma fileName Excel文件名+文件路径(绝对路径)

* @return boolean

*/

public boolean openExcel(String fileName) {

boolean Rtn = false;

try {

is = new FileInputStream(fileName);

rwb = Workbook.getWorkbook(is);

Rtn = true;

} catch (Exception e) {

Rtn = false;

} finally {

try {} catch (Exception e) {}

}

return Rtn;

}

/**

* 取得某个单元格的内容。不论单元格是何种数据类型都将返回字符型。

*

* @parma int col 列号 int row 行号

* @return String

*/

public String getCellContent(int col, int row) {

String cellContent = "";

try {

// 默认打开第一张工作薄。

Sheet rs = rwb.getSheet(0);

// 取得某一单元格的内容

Cell c00 = rs.getCell(col, row);

cellContent = c00.getContents();

} catch (Exception e) {

cellContent = "";

} finally {

try {

} catch (Exception e) {

cellContent = "";

}

}

return cellContent;

}

public static void main(String[] args) {

Excel ex = new Excel();

ex.openExcel("你自己的*.xls");

for (int i = 1; i ex.getRowCount(0); i++) {

for (int j = 0; j ex.getColCount(0); j++) {

System.out.println(ex.getCellContent(j, i));

}

}

}

}

网站题目:公式转java代码 java 公式
文章起源:https://www.cdcxhl.com/article30/dodpepo.html

成都网站建设公司_创新互联,为您提供用户体验关键词优化企业网站制作网站维护定制开发域名注册

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

外贸网站制作