Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 递归n/k多线程(用户输入)_Java_Multithreading_Recursion - Fatal编程技术网

Java 递归n/k多线程(用户输入)

Java 递归n/k多线程(用户输入),java,multithreading,recursion,Java,Multithreading,Recursion,我试图重新编程,使其符合我的需要(使用递归计算n^k)。但有些东西似乎有问题,因为我第一次得到的txt文件中没有任何文本;现在,在更改并尝试修复错误后,我什么也得不到:( 3号包; 导入java.io.File; 导入java.io.PrintWriter; 导入java.util.ArrayList; 导入javax.swing.JOptionPane; 公共类HaupThread实现可运行{ //int启动; //int stop; 布尔haupt=false; 字符串文件; 静态int

我试图重新编程,使其符合我的需要(使用递归计算n^k)。但有些东西似乎有问题,因为我第一次得到的txt文件中没有任何文本;现在,在更改并尝试修复错误后,我什么也得不到:(

3号包;
导入java.io.File;
导入java.io.PrintWriter;
导入java.util.ArrayList;
导入javax.swing.JOptionPane;
公共类HaupThread实现可运行{
//int启动;
//int stop;
布尔haupt=false;
字符串文件;
静态int n,k;
公共haupThread(int startvalue、int stopvalue、字符串文件、布尔h){
n=起始值;
k=停止值;
this.file=file;
haupt=h;
}
公开募捐{
ArrayList binominal=新的ArrayList();
如果(haupt=false){
for(int i=n;i n){
showMessageDialog(null,“Ungueltige-Eingabe”);}
否则{
showMessageDialog(null,“Rechne”);
//showMessageDialog(null,“nüber k=“+二项式(n,k));
}        
*/
System.out.println(“Erstelle线程…”);
int-erhoehe=20/螺纹数;
int start=2;
ArrayList线程=新的ArrayList();
对于(int i=0;i
如果(haupt=false){
如果(haupt==false){
@johnymapp
如果(!haupt)
如果(haupt=false){
如果(haupt==false){@johnymapp
如果(!haupt)
package Uebung3;

import java.io.File;
import java.io.PrintWriter;
import java.util.ArrayList;

import javax.swing.JOptionPane;

public class Hauptthread implements Runnable {


    //int start;
    //int stop;
    boolean haupt=false;
    String file;

    static int n, k;


    public Hauptthread(int startvalue, int stopvalue, String file, boolean h){

        n= startvalue;
        k=stopvalue;
        this.file=file;
        haupt=h;

    }


    public void run(){

        ArrayList<Double> binominal=new ArrayList<>();

        if (haupt=false) {

        for (int i = n; i <= k; i++) {

            binominal.add(binomial(n,k));

        }
        try{
            PrintWriter print=new PrintWriter(new File(file));
            for (int i = 0; i < binominal.size() ; i++) {
                    print.println("Test");
                    print.println(binominal.get(i));                
            }
        }
        catch(Exception e){
            System.out.println("Error " + e.getMessage());

        }

    }
    }


      double binomial(int n, int k) {
         if (k == 0) {
                return 1; }
            else {
                return (((double)n/k) * binomial(n-1, k-1)); }

    }

}
package Uebung3;

import java.util.ArrayList;

import javax.swing.JOptionPane;

public class Uebung3  {

        public static int threadcount=4;

        public static int n, k;
        public static int stop=k;


    public static void main(String[] args) {

        /*
        int n = Integer.parseInt(JOptionPane.showInputDialog("n = "));
        int k = Integer.parseInt(JOptionPane.showInputDialog("k = "));

        if (n < 0 || k < 0 || k > n) {
            JOptionPane.showMessageDialog(null, "Ungueltige Eingabe"); }
        else {
            JOptionPane.showMessageDialog(null, "Rechne" ); 
            //JOptionPane.showMessageDialog(null, "n über k = " +binomial(n, k));

        }        
         */

        System.out.println("Erstelle Threads...");

        int erhoehe=20/threadcount;
        int start=2;

        ArrayList <Thread> threads = new ArrayList<>();

        for (int i = 0; i < threadcount; i++) {
            //if(!((i+1)==threadcount)){
            if(start==10){

                threads.add(new Thread(new Hauptthread(start, erhoehe, i+".txt",false)));
            }
            else {
                threads.add(new Thread(new Hauptthread(start, erhoehe, i+".txt",true)));
            }
        }
        for (int i = 0; i < threads.size(); i++) {
        threads.get(i).start();         
        }
        for (int i = 0; i < threads.size(); i++) {
            try {
            threads.get(i).join();      

            } catch (Exception e) {
                System.out.println("Error" +e.getMessage());            
            }
    }





}
}