Can you point out my faults
Simply Put a loop and take input operator and then take input of two digits and then perform the operation till the user inputs ‘x’ or ‘X’.
public static void main(String[] args) {
char ch;
do {
ch = scn.next().charAt(0);
if (ch == '+' || ch == '-' || ch == ' * ' || ch == '/' || ch == '%') {
// Do Arithmetic operations here
} else {
if (ch != 'x' && ch != 'X')
System.out.println("Invalid operation. Try again.");
}
} while (ch != 'x' && ch != 'X');
}
Thankyou !! but why we have used && operator instead of || .
while(n!=‘X’ && n!=‘x’);
@Utkarshsingh5298291,
n should not be equal to X and x, only then we have to print try again. If n = X or x ,we need to exit the loop and terminate the program