sir, i have no idea about the code of the problem . sir please suggest me the correct answer.
Here is my two approach to go towards the answer. so please correct me out. and tell me what i have to do.
1.
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner src = new Scanner(System.in);
char ch = src.next().charAt(0);
if(ch == '+' || ch == '-' || ch == '*' || ch == '/' || ch == '%' ) {
int N1 = src.nextInt();
int N2 = src.nextInt();
if(ch == '+') {
System.out.println(N1 + N2);
}
else if(ch == '-') {
System.out.println(N1 - N2);
}
else if(ch == '*') {
System.out.println(N1 * N2);
}
else if(ch == '/') {
System.out.println(N1 / N2);
}
else if(ch == '%') {
System.out.println(N1 % N2);
}
}
while(ch == 'X' || ch == 'x' ) {
if(ch =='X') {
System.out.println();
break;
}
else if(ch =='x') {
break;
}
} while (ch != '+' || ch != '-' || ch != '*' || ch != '/' || ch != '%' || ch!='x' || ch!='X'){
System.out.println("Invalid operation. Try again");
break;
}
}
}
import java.util.Scanner;
public class Main {
public static Scanner src = new Scanner(System.in);
static char ch = src.next().charAt(0);
public static void main(String[] args){
if(ch==β+β||ch==β-β||ch==ββ||ch==β/β||ch==β%β||ch==βXβ||ch==βxβ) {
cal();
}
else {
System.out.println(βInvalid operation.Try againβ);
cal();
}
}
public static void cal() {
int N1 = src.nextInt();
int N2 = src.nextInt();
while(ch==β+β||ch==β-β||ch==ββ||ch==β/β||ch==β%β||ch==βXβ||ch==βxβ) {
switch(ch){
caseβ+β:{
System.out.println(N1+N2);
break;
}
caseβ-β:{
System.out.println(N1-N2);
break;
}
caseββ:{
System.out.println(N1N2);
break;
}
caseβ/β:{
System.out.println(N1/N2);
break;
}
caseβ%β:{
System.out.println(N1%N2);
break;
}
caseβXβ:{
break;
}
caseβxβ:{
break;
}
}
}
}
}