zoukankan      html  css  js  c++  java
  • 玩玩小程序

    一、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();
    	}
    
    }
    


  • 相关阅读:
    06列表的常用基本操作
    05字符串的常用基本操作
    什么是全量表,增量表,快照表,拉链表,维度表,事实表,实体表
    什么是拉链表
    数仓设计
    pandas学习
    矩阵和数组的区别
    中文文本关键词抽取的三种方法(TF-IDF、TextRank、word2vec)
    python使用结巴分词(jieba)创建自己的词典/词库
    scrapy是广度优先还是深度优先?
  • 原文地址:https://www.cnblogs.com/javawebsoa/p/3067520.html
Copyright © 2011-2022 走看看