I tried to create a calculator using multiple boolean types on one "if" command. I also tried to use the numbers 42(*),43(+),45(-) and 47(/) from the ASCII table instead of the symbols. Now, for some resson it's not working both with the numbers and the symbols and I would like to know why. I know how to solve the problem using different methods but i want to understand the logic of why my programm isn't working, thanks for anyone who can help! One of the different methods: [Trouble with a simple calculator code (Java)
package RemoteSystemsTempFiles;
import java.util.Scanner;
public class SecondLesson2 {
public static void main(String[] args) {
System.out.println("Print an equation with +,-,*,/");
Scanner reader=new Scanner(System.in);
double num5=reader.nextDouble();
char action=reader.next().charAt(0);
double num6=reader.nextDouble();
if (action=='+' || action=='-' || action=='*' || action=='/')
{
System.out.println(num5+action+num6+"=");
}
else System.out.println("You havne't printed it correctly");
}
}
Aucun commentaire:
Enregistrer un commentaire