随便给个100行左右的java小程序,就给分,作业,急

随便给个100行左右的java小程序,就给分,作业,急,第1张

package com.erayt.ctms.Zimport

import java.io.FileInputStream

import java.io.IOException

import java.io.InputStream

import java.lang.reflect.Field

import java.util.ArrayList

import java.util.HashMap

import java.util.Iterator

import java.util.List

import org.apache.commons.collections.functors.ForClosure

import org.apache.poi.hssf.usermodel.HSSFCell

import org.apache.poi.hssf.usermodel.HSSFWorkbook

import org.apache.poi.ss.usermodel.Cell

import org.apache.poi.ss.usermodel.Row

import org.apache.poi.ss.usermodel.Sheet

import org.apache.poi.ss.usermodel.Workbook

import org.apache.poi.xssf.usermodel.XSSFWorkbook

import org.slf4j.Logger

import org.slf4j.LoggerFactory

import com.alibaba.fastjson.JSONArray

import com.alibaba.fastjson.JSONObject

import com.erayt.ctms.system.standard.xnet.CtmsXNetContext

import com.erayt.xnet4j.XNetCommand

import com.erayt.xnet4j.XNetData

public class ReadForwardExcelServiceImpl implements ReadForwardExcelService {

private SearchPosDao searchForwardDao

public SearchPosDao getSearchForwardDao() {

return searchForwardDao

}

public void setSearchForwardDao(SearchPosDao searchForwardDao) {

this.searchForwardDao = searchForwardDao

}

protected Logger logger = LoggerFactory

.getLogger(this.getClass().getName())

private Workbook wb

//private JSONObject jsonObject = new JSONObject()

private List<Object>list_key = new ArrayList<Object>()

private List<Object>list_body = new ArrayList<Object>()

private List<HashMap<String,Object>>list_map = new ArrayList<HashMap<String,Object>>()

private CtmsXNetContext ctmsXNetContext

private String filename3

public String getFilename3() {

return filename3

}

public void setFilename3(String filename3) {

this.filename3 = filename3

}

public String getFilename4() {

return filename4

}

public void setFilename4(String filename4) {

this.filename4 = filename4

}

private String filename4

public void setCtmsXNetContext(CtmsXNetContext ctmsXNetContext) {

this.ctmsXNetContext = ctmsXNetContext

}

public void init() {

readXml(filename3)

}

public void readXml(String fileName) {

try {

InputStream input = new FileInputStream(fileName)// 建立输入流

// 根据文件格式2003来初始化

wb = new HSSFWorkbook(input)

Sheet sheet = wb.getSheetAt(0)// 获得第一个表单

Iterator<Row>rows = sheet.rowIterator()// 获得第一个表单的迭代器

for(int i=0i<sheet.getPhysicalNumberOfRows()i++) {

Row row = rows.next()// 获得行数据

//System.out.println(sheet.getPhysicalNumberOfRows()+"+++++")

Iterator<Cell>cells = row.cellIterator()// 获得第i行的迭代器

HashMap<String, String>HashBegain=new HashMap<String, String>()

for(int j=0j<row.getPhysicalNumberOfCells()j++){

//System.out.println(row.getPhysicalNumberOfCells()+"+++++"+j)

Cell cell = cells.next()

if(i==0||i==7){

list_key.add(cell.getStringCellValue())

}else {

if(cell.getCellType()== cell.CELL_TYPE_NUMERIC){

HashBegain.put((String) list_key.get(j), String.valueOf(cell.getNumericCellValue()))

}

else{HashBegain.put((String) list_key.get(j), cell.getStringCellValue())}

}

}

if(i!=0&&i!=7){

list_body.add(HashBegain)

}

if(i==6){

list_key = new ArrayList<Object>()

}

}

installJson()

readExcelEqual()

} catch (IOException ex) {

ex.printStackTrace()

}

}

// 组装即期交易json报文,并发送

public void installJson() {

String headStr = "{Head:" + "{\"chanelNo\":1508170004977,"

+ "\"dataCount\":\"1\"," + "\"eventType\":\"1\","

+ "\"msgNo\":\"1508170004977-20150917171754\","

+ "\"msgType\":\"1\"," + "\"sendingTime\":\"20150917171754\","

+ "\"source\":\"TR1\"," + "\"subSource\":\"TR1\","

+ "\"version\":\"1.0\"}," + "Body:"

+ JSONArray.toJSONString(list_body).replaceAll("\"", "'") + "}"

System.out.println(headStr)

try {

Thread.sleep(5000)

} catch (InterruptedException e) {

// TODO Auto-generated catch block

e.printStackTrace()

}

sendXNetTradeData(headStr, "RK1IN.Trade", "UTF-8")

}

// 发送到xnetd

public void sendXNetTradeData(String sendJson, String title, String charset) {

XNetData xnetData = new XNetData()

xnetData.setData(sendJson, charset)

xnetData.setTitle(title)

xnetData.setCommand(XNetCommand.TITLE)

if (ctmsXNetContext.getCtmsXnetSocket().isLoginOK()) {

ctmsXNetContext.getCtmsXnetSocket().sendData(xnetData)

} else {

logger.warn("CtmsXnet no login. sendXNetData[" + title

+ "] return.")

}

}

// 打印json属性

public static void printClassInfo(Object object) {

Field[] fields = object.getClass().getDeclaredFields()

for (int i = 0i <fields.lengthi++) {

try {

boolean accessFlag = fields[i].isAccessible()

fields[i].setAccessible(true)

String varName = fields[i].getName()

Object varValue = fields[i].get(object)

System.out.println(varName + "=" + varValue)

fields[i].setAccessible(accessFlag)

} catch (Exception e) {

e.printStackTrace()

}

}

}

//获取excel结果数据,并进行比较

public void readExcelEqual() {

//读取excel头寸数据

HashMap<String, String>HashEnd=new HashMap<String, String>()

Workbook wb1

List<Object>list_keyBody = new ArrayList<Object>()

List<HashMap>list_keyBody2 = new ArrayList<HashMap>()

//List<HashMap<String,Object>>list_keyBody2 = new ArrayList<HashMap<String,Object>>()

boolean END=false

try {

InputStream input = new FileInputStream(filename4)// 建立输入流

wb1 = new HSSFWorkbook(input)

Sheet sheet = wb1.getSheetAt(0)// 获得第一个表单

Iterator<Row>rows = sheet.rowIterator()// 获得第一个表单的迭代器

int i = 0

while (rows.hasNext()) {

HashEnd=new HashMap<String, String>()

Row row = rows.next()// 获得行数据

for (int j = 0j <row.getLastCellNum()j++) {

//System.out.println(row.getLastCellNum()+"XXXXX")

Cell cell = row.getCell(j)

if(i==0){

list_keyBody.add(cell.getStringCellValue())

}else{

if(cell.getCellType()==cell.CELL_TYPE_NUMERIC){

HashEnd.put((String) list_keyBody.get(j), String.valueOf(cell.getNumericCellValue()))

}

else

{

HashEnd.put((String) list_keyBody.get(j), cell.getStringCellValue())

}

}

}

if(i!=0){

list_keyBody2.add(HashEnd)}

i++

}

} catch (IOException ex) {

ex.printStackTrace()

}

//从数据库获取头寸数据

try {

Thread.sleep(10000)

} catch (InterruptedException e) {

// TODO Auto-generated catch block

e.printStackTrace()

}

list_map=searchForwardDao.findForwardPos()

//输出计算正确与否

for(int k=0k<list_map.size()k++){

if(END=list_map.get(k).get("AMOUNT_1").toString().equals((String) list_keyBody2.get(k).get("AMOUNT_1")))

{

logger.debug("远期第"+k+"组 货币1金额计算正确"+" Amount1="+list_map.get(k).get("AMOUNT_1").toString())

}else {

logger.debug("远期第"+k+"组 货币1金额计算不正确"+"left="+list_map.get(k).get("AMOUNT_1").toString()+" right="+list_keyBody2.get(k).get("AMOUNT_1"))

}

if(END=list_map.get(k).get("AMOUNT_2").toString().equals((String) list_keyBody2.get(k).get("AMOUNT_2")))

{

logger.debug("远期第"+k+"组 货币2金额计算正确"+" Amount2="+list_map.get(k).get("AMOUNT_2").toString())

}else {

logger.debug("远期第"+k+"组 货币2金额计算不正确"+"left="+list_map.get(k).get("AMOUNT_2").toString()+" right="+list_keyBody2.get(k).get("AMOUNT_2"))

}

if(END=list_map.get(k).get("START_PL").toString().equals((String) list_keyBody2.get(k).get("START_PL")))

{

logger.debug("远期第"+k+"组 累计损益计算正确"+" START_PL="+list_map.get(k).get("START_PL").toString())

}else {

logger.debug("远期第"+k+"组 累计损益计算不正确"+"left="+list_map.get(k).get("START_PL").toString()+" right="+list_keyBody2.get(k).get("START_PL"))

}

if(END=list_map.get(k).get("DAILY_PL").toString().equals((String) list_keyBody2.get(k).get("DAILY_PL")))

{

logger.debug("远期第"+k+"组 日止损计算正确"+" DAILY_PL="+list_map.get(k).get("DAILY_PL").toString())

}else {

logger.debug("远期第"+k+"组 日止损计算不正确"+"left="+list_map.get(k).get("DAILY_PL").toString()+" right="+list_keyBody2.get(k).get("DAILY_PL"))

}

}

}

}

(1). import javax.swing.JFrame

import javax.swing.JOptionPane

public class HelloWorld {

public static void main(String args[]){

JFrame ff=new JFrame()

String R=JOptionPane.showInputDialog("哗搜请输宏芦掘入圆的半径:")

double r=Double.parseDouble(R)

JOptionPane.showMessageDialog(ff, "圆的面积为:"+3.14*r*r+"\n"+"圆的周蔽核长为:"+2*3.14*r)

}

}

(2). import java.util.Scanner

public class HelloWorld {

public static void main(String args[]){

Scanner scan=new Scanner(System.in)

int a=scan.nextInt()

int b=scan.nextInt()

int c=scan.nextInt()

if(a+b>c&&b+c>a&&a+c>b){

if((a*a==b*b+c*c)||(c*c==a*a+b*b)||(b*b==a*a+c*c))

System.out.print("是直角三角形")

}else

System.out.print("不能构成三角形")

}

}

(3). public static void main(String args[]){

int a=1000,i=0,sum=0

while(i<=a)

{

if(i%2==0)

sum=sum+i

i++

}

System.out.print(sum)

}

(4). public static void main(String args[]){

int a=12454,i=0

while(a>0){

a=a/10

i++

}

System.out.println(i)

}

(5). import java.util.Scanner

public class HelloWorld {

public static void main(String args[]){

Scanner scan=new Scanner(System.in)

int road=scan.nextInt()

int weight=scan.nextInt()

double sum=0

if (road<=100){

sum=weight*road*1

}else if(road<=300){

sum=weight*road*0.9

}else if(road<=500){

sum=weight*road*0.8

}else if(road<=1000){

sum=weight*road*0.7

}else

sum=weight*road*0.6

System.out.print(sum)

}

}

(6). public static void main(String args[]){

int sum=0

int total=1

for(int i=1i<=4i++){

for(int j=1j<=ij++)

total=total*j

sum=sum+total

total=1

}

System.out.println(sum)

}

参考下,建议自己动手,进步更快哦


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/12539571.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-26
下一篇 2023-05-26

发表评论

登录后才能评论

评论列表(0条)

保存