Advertisement
Guest User

Untitled

a guest
Feb 24th, 2020
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. package app;
  2. //import java.util.Scanner;
  3.  
  4. /**
  5. * Created by sorinapredut on 25/02/2019.
  6. */
  7.  
  8. public class MyClass {
  9. public static void main(String[] arg) {
  10.  
  11. //KeyboardInput in = new KeyboardInput();
  12. //Scanner in = new Scanner(System.in);
  13. char response, c, n1;
  14. boolean found;
  15. int n, i;
  16. int h = 0;
  17. char[] a = new char[20];
  18. do {
  19. //System.out.println("Input an integer between 1 and 20: ");
  20. //n = in.readInteger();
  21. //n=sc.nextInt();
  22. System.out.println(arg[0]);
  23. n = Integer.parseInt(arg[0]);
  24. break;
  25. } while (n < 1 || n > 20);
  26. System.out.println("input " + n + " character(s)");
  27.  
  28. if (n > 1 && n < 20) {
  29. for (i = 0; i < n; i++)
  30. //a[i] = in.readCharacter();
  31. //a[i]=sc.next(".").charAt(0);
  32. a[i] = arg[i + 1].charAt(0);
  33.  
  34. //n1 = in.readCharacter();
  35. do {
  36. //System.out.println("Input character to search for: ");
  37. //c = in.readCharacter();
  38. //c = sc.next(".").charAt(0);
  39. h++;
  40. System.out.println("numarul" + h);
  41. c = arg[n + 1].charAt(0);
  42. System.out.println("Input char to search for " + c);
  43. //n1 = in.readCharacter();
  44. found = false;
  45. for (i = 0; !found && i < n; i++)
  46. if (a[i] == c)
  47. found = true;
  48. if (found)
  49. System.out.println("character " + c + " appears at position " + i);
  50. else
  51. System.out.println("character " + c + " not appear in string");
  52. System.out.println("Search for another character?[y/n]: ");
  53. //response = in.readCharacter();
  54. //response = sc.next(".").charAt(0);
  55. response = arg[n + 2].charAt(0);
  56. //n1 = in.readCharacter();
  57. } while (((response == 'y') || (response == 'Y')) && (h != 3));
  58. }
  59. }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement