Advertisement
VivianOlivian

Untitled

Sep 29th, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Multicalculator {
  4. public static void main(String[] args) {
  5. String yourNumbers = enterNum();
  6. int numberOne = stringToInteger(yourNumbers);
  7. for (numberOne = 0; ; numberOne--){
  8. System.out.println("Please, enter a number");
  9. }
  10. }
  11.  
  12. public static String enterNum() {
  13. Scanner scanner = new Scanner(System.in);
  14. System.out.println("How many numbers would you like to enter?");
  15. String yourNumbers = scanner.nextLine();
  16. boolean isItNum = checkString(yourNumbers);
  17. while (!isItNum) {
  18. System.out.println("Please, enter a number:");
  19. yourNumbers = scanner.nextLine();
  20. isItNum = checkString(yourNumbers);
  21. }
  22. return yourNumbers;
  23. }
  24.  
  25. public static int stringToInteger(String numbers) {
  26. return Integer.parseInt(numbers);
  27. }
  28.  
  29. public static boolean checkString(String string) {
  30. try {
  31. Integer.parseInt(string);
  32. return true;
  33. } catch (IllegalArgumentException e) {
  34. return false;
  35. }
  36. }
  37.  
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement