import java.util.Scanner;
public class Main {
static Scanner input = new Scanner(System.in);
public static void main(String[] args) {
intro();
int numcorrect = 0;
int answer;
System.out.println("Welcome to envoirnmental travia");
System.out.println("What should you do when you want to throw your device away");
System.out.println("1 throw it in the garbage");
System.out.println("2 recyle it");
System.out.println("3 do nothing");
answer = input.nextInt();
while (answer < 2 || answer > 2) {
System.out.println("Please retry"); {
if (answer == 2)
System.out.println("correct");
numcorrect = 1;
}
System.out.println("Why is it unsafe to throw electronics in the garbage");
System.out.println("1 because chemicals will get released that will harm the air and soil");
System.out.println("2 Its not bad there will be no diffrence");
System.out.println("3 Why do I care");
answer = input.nextInt();
while (answer < 1 || answer > 1) {
System.out.println("Please retry"); {
if (answer == 1)
System.out.println("correct");
numcorrect = 1;
}
System.out.println("Are all computers and electroninc devices bad for the envoirnment");
System.out.println("1 Yes");
System.out.println("2 kinda");
System.out.println("3 no because some devices help the envoirnment like the envirbot which helps with ocean pollution by cleaning the ocean from any metal plastic because it detects contamination and finds the source by swimming");
answer = input.nextInt();
while (answer < 3 || answer > 3) {
System.out.println("Please retry"); {
if (answer == 3)
System.out.println("correct");
numcorrect = 1;
}
int totalQuestions = 3;
double score = (100 * numcorrect) / totalQuestions;
System.out.println(" You scored " score "%");
}
public static void intro() {
System.out.println("Welcome to the facts about the envoirnment");
String Fact;
String answer;
boolean yn;
System.out.println("Enter a fact about the envoirnment");
Fact = input.nextLine();
System.out.println("You entered " Fact);
System.out.println("Did you know there are aproximatly 50 miilon tons of waste every year Did you know this fact or not enter yes or no");
String[] Links = new String[8];
System.out.println("please visit these links for more info");
Links[1] = "https://www.ewaste1.com/what-is-e-waste/";
System.out.println(Links[1]);
Links[2] = "https://www.toronto.ca/services-payments/recycling-organics-garbage/electronic-waste/";
System.out.println(Links[2]);
Links[3] = "https://earth911.com/eco-tech/e-waste-why-you-should-recycle-electronics/";
System.out.println(Links[3]);
System.out.println("yes/no");
while (true) {
answer = input.nextLine().trim().toLowerCase();
if (answer.equals("yes")) {
System.out.println("Congrats you know this fact");
yn = true;
break;
} else if (answer.equals("no")) {
System.out.println("Sorry you didn't know this fact at least you know now");
yn = false;
break;
} else {
System.out.println("Please enter Yes or NO");
//My program represents environmental caring
}
}
}
}
我不斷收到我在標題中描述的錯誤,誰能告訴我為什么我無法弄清楚其他一切都運行良好只是如果我使用那個類方法它就會出錯我只是不明白為什么如果有人可以幫助我我真的會意識到它我嘗試添加額外的大括號我在頂部有 intro() 所以這不是問題
uj5u.com熱心網友回復:
出現編譯錯誤。此外,最好在提交堆疊溢位之前格式化您的代碼,以便其他人更容易查看。
缺少 2 個右大括號。我已經添加了它們。你可以試試下面的代碼。
import java.util.Scanner;
public class Main {
static Scanner input = new Scanner(System.in);
public static void main(String[] args) {
intro();
int numcorrect = 0;
int answer;
System.out.println("Welcome to envoirnmental travia");
System.out.println("What should you do when you want to throw your device away");
System.out.println("1 throw it in the garbage");
System.out.println("2 recyle it");
System.out.println("3 do nothing");
answer = input.nextInt();
while (answer < 2 || answer > 2) {
System.out.println("Please retry");
{
if (answer == 2)
System.out.println("correct");
numcorrect = 1;
}
System.out.println("Why is it unsafe to throw electronics in the garbage");
System.out.println("1 because chemicals will get released that will harm the air and soil");
System.out.println("2 Its not bad there will be no diffrence");
System.out.println("3 Why do I care");
answer = input.nextInt();
while (answer < 1 || answer > 1) {
System.out.println("Please retry");
{
if (answer == 1)
System.out.println("correct");
numcorrect = 1;
}
System.out.println("Are all computers and electroninc devices bad for the envoirnment");
System.out.println("1 Yes");
System.out.println("2 kinda");
System.out.println(
"3 no because some devices help the envoirnment like the envirbot which helps with ocean pollution by cleaning the ocean from any metal plastic because it detects contamination and finds the source by swimming");
answer = input.nextInt();
while (answer < 3 || answer > 3) {
System.out.println("Please retry");
{
if (answer == 3)
System.out.println("correct");
numcorrect = 1;
}
int totalQuestions = 3;
double score = (100 * numcorrect) / totalQuestions;
System.out.println(" You scored " score "%");
}
}
}
}
public static void intro() {
System.out.println("Welcome to the facts about the envoirnment");
String Fact;
String answer;
boolean yn;
System.out.println("Enter a fact about the envoirnment");
Fact = input.nextLine();
System.out.println("You entered " Fact);
System.out.println(
"Did you know there are aproximatly 50 miilon tons of waste every year Did you know this fact or not enter yes or no");
String[] Links = new String[8];
System.out.println("please visit these links for more info");
Links[1] = "https://www.ewaste1.com/what-is-e-waste/";
System.out.println(Links[1]);
Links[2] =
"https://www.toronto.ca/services-payments/recycling-organics-garbage/electronic-waste/";
System.out.println(Links[2]);
Links[3] = "https://earth911.com/eco-tech/e-waste-why-you-should-recycle-electronics/";
System.out.println(Links[3]);
System.out.println("yes/no");
while (true) {
answer = input.nextLine().trim().toLowerCase();
if (answer.equals("yes")) {
System.out.println("Congrats you know this fact");
yn = true;
break;
} else if (answer.equals("no")) {
System.out.println("Sorry you didn't know this fact at least you know now");
yn = false;
break;
} else {
System.out.println("Please enter Yes or NO");
// My program represents environmental caring
}
}
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/413827.html
標籤:
上一篇:如何在陣列內搜索過濾器陣列項
下一篇:從大量整數初始化向量時出錯
