System.out.println("Kies een stof waar je meer info over wil: goud, zilver of tin");
System.out.println("type hem hieronder in en druk dan op enter!");
我希望你能帮助我:D。
package javaproject1;
import java.util.Scanner;
public class JavaProject1 {
public static void main(String[] args) {
Scanner Stof = new Scanner(System.in);
String[] MainArr = new String[3];
MainArr[0] = "Goud";
MainArr[1]= "Zilver";
MainArr[2]="Tin";
int x = 1;
System.out.println("Kies een stof waar je meer info over wil: goud, zilver of tin");
System.out.println("type hem hieronder in en druk dan op enter!");
if(Stof.next().equals(MainArr[0]));{
System.out.println("Het is een metaal");
System.out.println("Atoomnummer is 79");
System.out.println("EN-waarde is 2,54");
}
if(Stof.next().equals(MainArr[1]));{
System.out.println("Het is een metaal");
System.out.println("Atoomnummer is 47");
System.out.println("EN-waarde is 1,93");
}
if(Stof.next().equals(MainArr[2]));{
System.out.println("Het is een metaal");
System.out.println("Atoomnummer is 50");
System.out.println("EN-waarde is 1,96");
}
}
}
答案 0 :(得分:2)
你把分号放在不应该的地方。
public String doInBackground(String... params) {
String reg_url="http://10.0.2.2/webapp/Register.php";
String login_url="http://10.0.2.2/webapp/login.php";
String method= params[0];
if (method.equals("login")) {
String login_name = params[1];
String login_pass = params[2];
try {
URL url = new URL(login_url);
HttpURLConnection httpURLConnection=(HttpURLConnection)url.openConnection();
httpURLConnection.setRequestMethod("POST");
httpURLConnection.setDoOutput(true);
httpURLConnection.setDoInput(true);
OutputStream os = httpURLConnection.getOutputStream();
BufferedWriter bufferedWriter= new BufferedWriter(new OutputStreamWriter(os,"UTF-8"));
String data = URLEncoder.encode("login_name","UTF-8")+"="+URLEncoder.encode(login_name,"UTF-8")+"&"+
URLEncoder.encode("login_pass","UTF-8")+"="+URLEncoder.encode(login_pass,"UTF-8");
bufferedWriter.write(data);
bufferedWriter.flush();
bufferedWriter.close();
os.close();
InputStream inputStream=httpURLConnection.getInputStream();
BufferedReader bufferedReader= new BufferedReader(new InputStreamReader(inputStream,"iso-8859-15"));
String response="";
String line="";
while ((line=bufferedReader.readLine())!=null)
{
response+=line;
}
bufferedReader.close();
inputStream.close();
httpURLConnection.disconnect();
return response;
}
return null;
就个人而言,我会在一个无限循环中循环,并选择让用户使用if(Stof.next().equals(MainArr[0])); <---- This will produce unexpected results.
突破循环。
我还将用户从break
中的选项保存在变量stof
中。
建议:您可以做的最好的英语代码。
gekozenStof
答案 1 :(得分:0)
伟大的免费IDE是Eclipse或IntelliJ IDEA社区版。
好的简单循环应该这样做。
while(some condition){
//your code
}