Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/324.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
嘿,伙计们。我该怎么在我的KBC中实现50%的生命线,或者谁想成为百万富翁?在我的以下代码中? 包kbc; 导入java.io.*; 导入java.util.*; 公共类质量保证{ 字符串问题; 字符串应答器1、应答器2、应答器3、应答器4; 字符串正确答案; } mykbc类{ 最终静态整数=25; 公共静态void main(字符串[]args){ 试一试{ 扫描仪输入; 输入=新扫描仪(System.in); RandomAccessFile raf=新的RandomAccessFile(“hello.txt”、“r”); ArrayList=新的ArrayList(); TreeMaptm=新的TreeMap(); long filelength=raf.length(); 对于(int loop=0;loop_Java - Fatal编程技术网

嘿,伙计们。我该怎么在我的KBC中实现50%的生命线,或者谁想成为百万富翁?在我的以下代码中? 包kbc; 导入java.io.*; 导入java.util.*; 公共类质量保证{ 字符串问题; 字符串应答器1、应答器2、应答器3、应答器4; 字符串正确答案; } mykbc类{ 最终静态整数=25; 公共静态void main(字符串[]args){ 试一试{ 扫描仪输入; 输入=新扫描仪(System.in); RandomAccessFile raf=新的RandomAccessFile(“hello.txt”、“r”); ArrayList=新的ArrayList(); TreeMaptm=新的TreeMap(); long filelength=raf.length(); 对于(int loop=0;loop

嘿,伙计们。我该怎么在我的KBC中实现50%的生命线,或者谁想成为百万富翁?在我的以下代码中? 包kbc; 导入java.io.*; 导入java.util.*; 公共类质量保证{ 字符串问题; 字符串应答器1、应答器2、应答器3、应答器4; 字符串正确答案; } mykbc类{ 最终静态整数=25; 公共静态void main(字符串[]args){ 试一试{ 扫描仪输入; 输入=新扫描仪(System.in); RandomAccessFile raf=新的RandomAccessFile(“hello.txt”、“r”); ArrayList=新的ArrayList(); TreeMaptm=新的TreeMap(); long filelength=raf.length(); 对于(int loop=0;loop,java,Java,简单,让玩家2试着猜一下。我知道这并不完全是一条50/50的生命线,但它的行为应该是一样的。这是因为选择正确答案的概率保持不变。例如,在一条正确的50/50生命线中,获胜的概率是1/2。通常获胜的概率是1/4。因此,两次猜测获胜的概率是2*1/4=2/4=1/2,因此获胜的概率是相同的 通过使用一个简单的for循环可以实现这一点,您可以在字符串opt=input.nextLine();中添加: package kbc; import java.io.*; import java.util.*;

简单,让玩家2试着猜一下。我知道这并不完全是一条50/50的生命线,但它的行为应该是一样的。这是因为选择正确答案的概率保持不变。例如,在一条正确的50/50生命线中,获胜的概率是1/2。通常获胜的概率是1/4。因此,两次猜测获胜的概率是2*1/4=2/4=1/2,因此获胜的概率是相同的


通过使用一个简单的
for
循环

可以实现这一点,您可以在
字符串opt=input.nextLine();
中添加:

package kbc;

import java.io.*;
import java.util.*;


public class qa {


    String question;
    String answer1,answer2,answer3,answer4;
    String correctanswer;
}
class mykbc{
    final static int noques=25;
    public static void main(String []args){
        try{
            Scanner input;
            input=new Scanner(System.in);
            RandomAccessFile raf=new RandomAccessFile("hello.txt","r");
            ArrayList<Integer>al=new ArrayList<Integer>();
            TreeMap<Integer,qa>tm=new TreeMap<Integer,qa>();
            long filelength= raf.length();
            for(int loop=0;loop<15;++loop){
                int currentques;
                do{
                    currentques=(int)(Math.random()*noques);
                    if(!al.contains(currentques)){
                        al.add(currentques);
                        break;
                    }


                }
                while(true);

                raf.seek(0);
                int track=0;
                qa cqa=new qa();

                while(raf.getFilePointer()< filelength){
                    cqa.question=raf.readLine();
                    cqa.answer1=raf.readLine();
                    if(cqa.answer1.charAt(0)=='$'){


                        cqa.answer1=cqa.answer1.substring(1,cqa.answer1.length());


                        cqa.correctanswer=cqa.answer1;




                                        }
                cqa.answer2=raf.readLine();
                if(cqa.answer2.charAt(0)=='$'){
                    cqa.answer2=cqa.answer2.substring(1,cqa.answer2.length());
                    cqa.correctanswer=cqa.answer2;
                }
                cqa.answer3=raf.readLine();
                if(cqa.answer3.charAt(0)=='$'){
                    cqa.answer3=cqa.answer3.substring(1,cqa.answer3.length());
                    cqa.correctanswer=cqa.answer3;

                }
                cqa.answer4=raf.readLine();
                if(cqa.answer4.charAt(0)=='$'){
                    cqa.answer4=cqa.answer4.substring(1,cqa.answer4.length());
                    cqa.correctanswer=cqa.answer4;
                }
                if(++track==currentques){
                    tm.put(loop+1,cqa);
                    break;
                }

                }           

            }
System.out.println("Welcome to KBC");
Set myset=tm.entrySet();
Iterator itr =myset.iterator();
while(itr.hasNext()){
    Map.Entry me=(Map.Entry)itr.next();
    System.out.println("Question No"+me.getKey());
    qa temp=(qa)me.getValue();
    System.out.println("A:"+temp.answer1);
    System.out.println("B:"+temp.answer2);
    System.out.println("C:"+temp.answer3);
    System.out.println("D:"+temp.answer4);
    System.out.println("Enter the Correct option :");


    System.out.println("Answer is:");
     String opt = input.nextLine();
     if(opt.equals("A"))
     {
        if(temp.answer1.equals(temp.correctanswer))
        {
             temp.correctanswer = temp.answer1;      
             System.out.println ("correct answer");
             System.out.println("You Won 1000rs :)\n");
        }
        else
        {
            System.out.println("Wrong Answer");
            System.out.println("");
            System.out.println("You Lost :(");
            break;
        }
     }
     if(opt.equals("B"))
     {
        if(temp.answer2.equals(temp.correctanswer))
        {
             temp.correctanswer = temp.answer2;      
             System.out.println ("correct answer");
             System.out.println("You Won 20000rs :)\n");
        }
        else
        {
            System.out.println("Wrong Answer");
            System.out.println("You Lost :(");
            break;
        }
     }
     if(opt.equals("C"))
     {
        if(temp.answer2.equals(temp.correctanswer))
        {
             temp.correctanswer = temp.answer2;      
             System.out.println ("correct answer");
             System.out.println("You Won 30000rs :)\n");
        }
        else
        {
            System.out.println("Wrong Answer");
            System.out.println("You Lost :(");
            break;
        }
     }   
     if(opt.equals("C"))
     {
        if(temp.answer3.equals(temp.correctanswer))
        {
             temp.correctanswer = temp.answer3;      
             System.out.println ("correct answer");
             System.out.println("You Won 40000rs :)\n");
        }
        else
        {
            System.out.println("Wrong Answer");
            System.out.println("You Lost :(");
            break;
        }
     }
     if(opt.equals("D"))
     {
        if(temp.answer4.equals(temp.correctanswer))
        {
             temp.correctanswer = temp.answer4;      
             System.out.println ("correct answer");
             System.out.println("You Won 50000rs :)\n");
        }
        else
        {
            System.out.println("Wrong Answer");
            System.out.println("You Lost :(");
            break;


        }
     }
  }
   raf.close();
  }
  catch(IOException ex ){
     System.out.println(ex.getLocalizedMessage());
  }
    }
}

我想成为百万富翁。我想调试你的代码,这样我就可以成为百万富翁。但是错误是什么?我想在我的游戏中实现一个生命线50 50 50 50,我不知道如何做到这一点,请帮助我,问题是你发布了大量的代码,没有明确的问题陈述。请访问我已经在顶部提到了你提到了一个aB把你想发生的事情简单地说出来。你需要更具体一些:在这种情况下,程序应该做什么?打印一些具体的东西,暂停,等待输入?描述期望的行为,需要发生什么的“算法”。这样,那些不知道“谁想成为百万富翁”的人问题是要理解它。还要指出你写的代码与问题的关系,以及你想在哪里添加缺少的部分。
        String opt = input.nextLine();
        if(opt.equals("50-50"))
        {

              Vector v = new Vector(); //java.util.Vector;

              v.addElement(temp.answer1);
              v.addElement(temp.answer2);
              v.addElement(temp.answer3);
              v.addElement(temp.answer4);

              v.removeElement(temp.correctanswer);

              String wa = v.elementAt(new Random().nextInt(3)); // java.util.Random;  1 wrong answer
              String opca="", opwa="";
              switch(temp.correctanswer)
              {

                    case temp.answer1:
                    opca = "A";
                    break;

                    case temp.answer2:
                    opca = "B";
                    break;

                    case temp.answer3:
                    opca = "C";
                    break;

                    case temp.answer4:
                    opca = "D";
                    break;

              }

              switch(wa)
              {

                    case temp.answer1:
                    opwa = "A";
                    break;

                    case temp.answer2:
                    opwa = "B";
                    break;

                    case temp.answer3:
                    opwa = "C";
                    break;

                    case temp.answer4:
                    opwa = "D";
                    break;

              }

              System.out.println("After 50-50 lifeline, Your options are :");
              System.out.println(opca+": "+temp.correctanswer);
              System.out.println(opwa+": "+wa);

        }