• 玩玩小程序


    一、L的3.41次方+40000L的1.56次方=21780889,帮我算出L

    解决方案,正常算,确实不会算,采用无限趋近法,得到近似值,编程采用递归


    import java.io.BufferedReader;
    import java.io.BufferedWriter;
    import java.io.Console;
    import java.io.File;
    import java.io.FileReader;
    import java.io.FileWriter;
    import java.util.ArrayList;
    import java.util.List;
    
    
    public class Io {
    	
    	public static void main(String args[]) throws Exception{
    		new Io().operate(1, 1000, 1);
    		
    		}
    		
    		private void operate(double min,double max,double add){
    			boolean bool = true;
    			List<Double> list = new ArrayList<Double>();
    			List<Double> listSub = new ArrayList<Double>();
    			double sub = 0;
    			for(double i=min;i<max;i+=add){
    				list.add(i);
    				double result = Math.pow(i, 3.41) + Math.pow(i, 1.56)*40000;
    				if((sub = Math.abs(result-21780889)) < 0.001){
    					bool = false;
    					break;
    				}else{
    					listSub.add(sub);
    				}
    			}
    			if(bool){
    				int pos = 0;
    				for(int j=0;j<listSub.size()-1;j++){
    					pos = j;
    					if(listSub.get(j)<listSub.get(j+1)){
    						break;
    					}
    				}
    				operate(list.get(pos-1), list.get(pos+1), add/10);
    			}else{
    				System.out.println("最终结果:"+list.get(list.size()-1)+"    "+sub);
    			}
    		}
    }
    


    二、


    import java.io.BufferedReader;
    import java.io.BufferedWriter;
    import java.io.Console;
    import java.io.File;
    import java.io.FileReader;
    import java.io.FileWriter;
    import java.util.ArrayList;
    import java.util.List;
    
    
    public class Io {
    	
    	public static void main(String args[]) throws Exception{
    
    
    		String path = "c:\\weibo.txt";
    		String content = null;
    		String account[];
    		
    		//read the txt;
    		content = new Io().readTxt(path);
    		
    		// show all of the accounts on the screen
    		account = content.split("#");
    		for(int i=0,len=account.length;i<len;i++){
    			System.out.println(account[i]);
    		}
    		
    		// " " replace # and save in the floder
    		content = content.replace("#", " ");
    		new Io().writeTxt("c:\\chulihou.txt", content);  //chulihou.txt这出题人也够NB嗒
    		
    		//delete the floder
    		File file = new File(path);
    		file.delete();
    	}
    	
    	private String readTxt(String path) throws Exception{
    		StringBuffer string = new StringBuffer();
    		String temp;
    		BufferedReader in =new BufferedReader(new FileReader(path));
    		while((temp = in.readLine()) != null){
    			string.append(temp);
    		}
    		in.close();
    		return string.toString();
    	}
    	
    	private void writeTxt(String path, String content) throws Exception{
    		FileWriter   fw=new   FileWriter( path ); 
    		BufferedWriter   bw   =new   BufferedWriter(fw); 
    		bw.write( content );
    		bw.flush();
    		bw.close();
    		fw.close();
    	}
    
    }
    


  • 相关阅读:
    OpenVINO Model Server的服务化部署——step3(django服务构建)
    (5)名称空间 namespace 和 using 声明
    (4)#include 指令
    (3)注释
    (2)简单的程序
    (1)Hello World
    javaScript 错误学习 -- throw、try 、catch和 finally
    js 如何在数字前面自动补零,生成序列号、单据号
    vs2015项目运行出现“无法启动IIS Express Web服务器”,如何解决
    Sql Server 2008 如何将数据表导出Excel文件?
  • 原文地址:https://www.cnblogs.com/javawebsoa/p/3067520.html
Copyright © 2020-2023  润新知