Код ! изменяет ли переменные динамически
Код,который должен изменить переменные 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; 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(); } } } }
если a вводится в командной строке то результат будет следующим
<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/>
требуется :
<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/>
Что я уже пробовал:
Искомый код и классы Java