Dear experts,
I am trying to code out my assignment but i made a problem with my
break;
within my
if (operator.equals(zero))
.
i have received compilation error stating the following:
HelloWorld.java: break outside switch or loop
Appreciate if someone can point out my mistake. Thank you.
import java.util.*;
public class HelloWorld {
public static void main(String[] args) {
int N; //declare variable to read the number of N lines in the input
int type; // indicate the type
String operator; // indicate if it's AND or OR
int firstBit, secondBit; //indicate the Bits
int zero = 0;
Scanner sc = new Scanner (System.in);
type = sc.nextInt(); // indicate the type
if (type ==1){
N = sc.nextInt();
for (int i=0;i <N; i++){
operator = sc.nextLine(); // read the operator
firstBit = sc.nextInt(); // read first bit
secondBit = sc.nextInt(); // read second bit
}
}
else if (type ==2){
operator = sc.nextLine();
if (operator.equals(zero))
break;
else {
firstBit = sc.nextInt(); // read first bit
secondBit = sc.nextInt(); // read second bit
}
}
else if (type ==3){
//read all the inputs till the end
while(sc.hasNext()){
operator = sc.nextLine(); // read the operator
firstBit = sc.nextInt(); // read first bit
secondBit = sc.nextInt(); // read second bit
}
}
else{
System.out.println("there are no such types");
}
System.out.println(operator + "" + firstBit + "" + secondBit);
}
}