Advertisement
VivianOlivian

Untitled

Sep 29th, 2019
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 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. int numberTwo;
  8. for (numberTwo>0; numberTwo<numberOne; numberTwo++){
  9. System.out.println("Please, enter a number");
  10. }
  11. }
  12.  
  13. public static String enterNum() {
  14. Scanner scanner = new Scanner(System.in);
  15. System.out.println("How many numbers would you like to enter?");
  16. String yourNumbers = scanner.nextLine();
  17. boolean isItNum = checkString(yourNumbers);
  18. while (!isItNum) {
  19. System.out.println("Please, enter a number:");
  20. yourNumbers = scanner.nextLine();
  21. isItNum = checkString(yourNumbers);
  22. }
  23. return yourNumbers;
  24. }
  25.  
  26. public static int stringToInteger(String numbers) {
  27. return Integer.parseInt(numbers);
  28. }
  29.  
  30. public static boolean checkString(String string) {
  31. try {
  32. Integer.parseInt(string);
  33. return true;
  34. } catch (IllegalArgumentException e) {
  35. return false;
  36. }
  37. }
  38.  
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement