代码!确实动态地改变变量 [英] Code ! does changes variables dynamically

查看:68
本文介绍了代码!确实动态地改变变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

应更改变量a,b,c,d的代码,如果在a的提示值处输入a,则初始化为但b,c和d未初始化





  public   class  BufferedReaderFromUserAnd 
{
private static final String FILENAME = F: /Android.txt;

public static void main( String args []) throws IOException
{
BufferedWriter bw = null;
FileWriter fw = null;

尝试
{
fw = new FileWriter (文件名);
bw = new BufferedWriter(fw);

BufferedReader reader = new BufferedReader( new InputStreamReader(System.in)) ;
System.out.print( Word1:);
String Word1 = reader.readLine();
System.out.print( Word2:);
String Word2 = reader.readLine();
System.out.print( Word3:);
String Word3 = reader.readLine();
System.out.print( Word4:);
String Word4 = reader.readLine();
System.out.print( Y:);
String y = reader.readLine();
String a = reader.readLine();
String b = reader.readLine();
String c = reader.readLine();
String d = reader.readLine();

if (y.compareTo(a)== 0)
{
b = not;
c = not;
d = not;
}

if (y.compareTo(b)== 0)
{
a = < span class =code-string>
not;
c = not;
d = not;
}

if (y.compareTo(c)== 0)
{
b = < span class =code-string> not;
a = not;
d = not;
}

如果(y.compareTo(d)== 0)
{
a = < span class =code-string> not;
c = not;
d = not;
}


字符串 n = reader.readLine();

bw.write( < input type ='radio'name ='rbnNumber' value ='您选择了(a) + Word1 + 这是 + a + 正确答案'/>(a) + Word1 + < br />);
bw.write( < input type ='radio'name ='rbnNumber'value ='你选中(a) + Word2 + 这是 + b + 正确答案'/>(a) + Word2 + < br />);
bw.write( < input type ='radio'name ='rbnNumber'value ='你选中(a) + Word3 + 这是 + c + 正确答案'/>(a) + Word3 + < br />);
bw.write( < input type ='radio'name ='rbnNumber'value ='你选中(a) + Word4 + 这是 + d + 正确答案'/>(a) + Word4 + < br />);
}
catch (IOException e){
e.printStackTrace();
}
最后
{
尝试 {
if (bw!= null)
bw.close();
if (fw!= null)
fw.close();
}
catch (IOException ex){
ex.printStackTrace();
}
}
}
}





如果在提示时输入a结果是



 <  输入   类型  ='  radio'    name   ='  rbnNumber'     =' 您选择了(a)Android,这是正确答案'    /  > (a)Android < span class =code-keyword><   br /  >  
< 输入 类型 =' radio' 名称 =' rbnNumber' value =' 您选择了(a)CS,这是正确答案' / > (a)CS < br / >
< 输入 type =' radio' 名称 =' rbnNumber' value =' 您选择了(a)OS是正确答案' / > (a)OS < br / >
< input type =' radio' 名称 =' rbnNumber' value =' 您选择了(a)代码是正确答案' / > (a)代码< br / >



所需要的是:

 <   input     type   ='  radio'    name   ='  rbnNumber'     =' 您选择了(a)Android,这是正确答案'    /  > (a) Android <   br /  >  
< 输入 type =' radio' 名称 =' rbnNumber' value =' 您选择了(a)CS,这不是正确答案' / > (a)CS < br / >
< span class =code-keyword>< input type =' radio' 名称 =' rbnNumber' value =' 您选择了(a)不是正确答案的操作系统 / > (a)操作系统< br / >
< input type = ' radio' name =' rbnNumber' value =' 您选择了(a)不正确答案的代码' / > ( a)代码< br / >





我的尝试:



搜索代码和Java类

解决方案

您不断重新发布此问题,尽管我们试图帮助您,但每次都会继续编写完全相同的错误。我建议你去 Java™教程 [ ^ ]并通过它们来正确理解您尝试使用的语言。

Code that should change variables a,b,c, d, if a is entered at prompt value of a is initialized to " " but b, c and d are not initialized


public class BufferedReaderFromUserAnd
{
  private static final String FILENAME = "F:/Android.txt";

  public static void main(String args[]) throws IOException
  {
    BufferedWriter bw = null;
    FileWriter fw = null;

    try
    {
      fw = new FileWriter(FILENAME);
      bw = new BufferedWriter(fw);

      BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
      System.out.print("Word1: ");
      String Word1 = reader.readLine();
      System.out.print("Word2: ");
      String Word2 = reader.readLine();
      System.out.print("Word3: ");
      String Word3 = reader.readLine();
      System.out.print("Word4: ");
      String Word4 = reader.readLine();
      System.out.print("Y: ");
      String y = reader.readLine();
      String a = reader.readLine();
      String b = reader.readLine();
      String c = reader.readLine();
      String d = reader.readLine();      
           
      if(y.compareTo(a)==0)
      {                
        b = "not" ;       
        c = "not" ;                       
        d = "not" ;       
      }                
          
      if(y.compareTo(b)==0)
      {                
        a = "not" ;       
        c = "not" ;                       
        d = "not" ;       
      }
          
      if(y.compareTo(c)==0)
      {                
        b = "not" ;       
        a = "not" ;                       
        d = "not" ;       
      }                
          
      if(y.compareTo(d)==0)
      {                
        a = "not" ;       
        c = "not" ;                       
        d = "not" ;       
      }    
      

      String n = reader.readLine();

      bw.write("<input type='radio' name='rbnNumber' value='You selected (a) " + Word1 + "  which is " + a +  " the correct answer' />(a) "  + Word1 + "<br/>");
      bw.write("<input type='radio' name='rbnNumber' value='You selected (a) " + Word2 + "  which is " + b +  " the correct answer' />(a) "  + Word2 + "<br/>");
      bw.write("<input type='radio' name='rbnNumber' value='You selected (a) " + Word3 + "  which is " + c +  " the correct answer' />(a) "  + Word3 + "<br/>");
      bw.write("<input type='radio' name='rbnNumber' value='You selected (a) " + Word4 + "  which is " + d +  " the correct answer' />(a) "  + Word4 + "<br/>");
    }
    catch (IOException e) {
      e.printStackTrace();
    }
    finally
    {
      try {
        if (bw != null)
          bw.close();
        if (fw != null)
          fw.close();
      }
      catch (IOException ex) {
        ex.printStackTrace();
      }
    }
  }
}



if a is entered at prompt the result is

<input type='radio' name='rbnNumber' value='You selected (a) Android  which is  the correct answer' />(a) Android<br/>
<input type='radio' name='rbnNumber' value='You selected (a) CS  which is  the correct answer' />(a) CS<br/>
<input type='radio' name='rbnNumber' value='You selected (a) OS  which is  the correct answer' />(a) OS<br/>
<input type='radio' name='rbnNumber' value='You selected (a) Code  which is  the correct answer' />(a) Code<br/>


what is required is :

<input type='radio' name='rbnNumber' value='You selected (a) Android  which is  the correct answer' />(a) Android<br/>
<input type='radio' name='rbnNumber' value='You selected (a) CS  which is not  the correct answer' />(a) CS<br/>
<input type='radio' name='rbnNumber' value='You selected (a) OS  which is not  the correct answer' />(a) OS<br/>
<input type='radio' name='rbnNumber' value='You selected (a) Code  which is not the correct answer' />(a) Code<br/>



What I have tried:

Searched Code and Java Classes

解决方案

You keep reposting this question, and despite our attempts to help you, you continue to code the exact same errors every time. I suggest you go to The Java™ Tutorials[^] and work through them to get a proper understanding of the language you are trying to use.


这篇关于代码!确实动态地改变变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆