admin管理员组文章数量:1398093
I'm making a console calculator in java, but I can't make it so that I can enter an infinite number of numbers and strings alternately, how can this be implemented?
import java.util.InputMismatchException; import java.util.Scanner; public class Calculate { private static boolean stopper = true; private static double result; public static void calculate(Scanner scanner) { while (stopper) { try { double a = scanner.nextDouble(); scanner.nextLine(); String symbol = scanner.nextLine(); scanner.nextLine(); double b = scanner.nextDouble(); // подумай как убрать white-space символы if (symbol.equals("=")) { stopper = false; System.out.println(result); } else if (symbol.equals("+")) { result = a + b; } else if (symbol.equals("-")) { result = a - b; } } catch (InputMismatchException e) { System.out.println("Неправильный ввод данных"); break; } } } }
I tried to do this, but nothing came out, I also tried other ways, but nothing works either. Help please
本文标签: doublehow to provide infinite input of numbers and strings alternately in javaStack Overflow
版权声明:本文标题:double - how to provide infinite input of numbers and strings alternately in java - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744147086a2592887.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论