可变!确实动态变化 [英] Variable ! does change dynamically
本文介绍了可变!确实动态变化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
获取用户输入并应有条件启动变量的代码
Code that gets user input and should initiate variables conditionally
package inout;
import java.io.InputStreamReader;
import java.io.*;
import java.io.BufferedWriter;
import java.io.BufferedReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.OutputStream;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Scanner;
import java.util.logging.Level;
import java.util.logging.Logger;
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("Word: ");
String Word = reader.readLine();
System.out.print("Y: ");
String a = reader.readLine();
System.out.print("The correct answer is: " + a);
//String a = null ;
String b = "" ;
String c = "" ;
String d = "" ;
if (a=="")
{
b = "D" ;
c = "N" ;
d = "S" ;
}
String n = reader.readLine();
bw.write("<input type='radio' name='rbnNumber' value='You selected (a) " + Word + " which is "+ a + b + c + d + " and the correct answer' />(a) " + Word + "<br/>");
}
catch (IOException e) {
e.printStackTrace();
}
finally
{
try {
if (bw != null)
bw.close();
if (fw != null)
fw.close();
}
catch (IOException ex) {
ex.printStackTrace();
}
}
}
}
如果用户输入表示那么其他变量b,c和d应该改为D,N和S
但它们不会是b $ b
我试过的:
更改了代码并搜索了java类
if user enters " " for a then other variables b, c and d should change to D, N and S
but they dont
What I have tried:
changed code and searched java classes
推荐答案
if (a=="")
不正确。
尝试:
Incorrect.
Try:
if(a.compareTo("")==0)
或
Or
if(a.isEmpty()==true)
这篇关于可变!确实动态变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文