我做错了什么我一直在非法开始表达式 public static void intro(){ java replit
what am i doing wrong I keep getting illegal start of experssion public static void intro(){ java replit
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
}
}
}
}
我不断收到标题中描述的错误 任何人都可以告诉我为什么我无法弄清楚其他一切都运行良好只是如果我这样做 class 方法一切都出错了 我只是不明白为什么如果任何人都可以帮助我我真的很感激我尝试添加额外的 clurly 括号我在上面有 intro() 所以这不是问题
存在编译错误。此外,最好在提交堆栈溢出之前格式化您的代码,以便其他人更容易审查。
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
}
}
}
}
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
}
}
}
}
我不断收到标题中描述的错误 任何人都可以告诉我为什么我无法弄清楚其他一切都运行良好只是如果我这样做 class 方法一切都出错了 我只是不明白为什么如果任何人都可以帮助我我真的很感激我尝试添加额外的 clurly 括号我在上面有 intro() 所以这不是问题
存在编译错误。此外,最好在提交堆栈溢出之前格式化您的代码,以便其他人更容易审查。
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
}
}
}
}