Guest User

Untitled

a guest
Jun 22nd, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. public static void main(String[] args) {
  2. //I print an array with letters from A-Z
  3. char abc[]=new char[26];
  4. for(int i=0; i<abc.length; i++) {
  5. abc[i]=(char)('A'+i);
  6. System.out.println(abc[i]);
  7. }
  8. //I ask for positions and save the results in a String
  9. do {
  10. String result="";
  11. Scanner sn = new Scanner(System.in);
  12. int num=sn.nextInt();
  13.  
  14. result=result + abc[num];
  15. }while(num!=-1);
  16. }
  17. }
  18.  
  19. while(true) {
  20. int num=sn.nextInt();
  21. if(num == -1) {
  22. break;
  23. }
  24. //Do stuff
  25.  
  26. int num=sn.nextInt();
  27. //When user inputs -1 to quit num= -1
  28. result=result + abc[num];
  29. //This will call the -1 index of abc
  30.  
  31. while(true) {
  32. try { //Add a try catch to prevent InputMisMatchException
  33. num=sn.nextInt();
  34. }catch(Exception e) {
  35. e.printStackTrace();
  36. }
  37. if(num < 0 || num > 25) { //If it is going to be out of bounds
  38. break;
  39. }
  40. if(num>=0) {
  41. result+=abc[num];
  42. }
  43. }
  44.  
  45. System.out.println(result);
  46.  
  47. public static void main(String[] args) {
  48.  
  49. //I print an array with letters from A-Z
  50. char abc[]=new char[26];
  51. for(int i=0; i<abc.length; i++) {
  52. abc[i]=(char)('A'+i);
  53. System.out.println(abc[i]);
  54. }
  55. //I ask for positions and save the results in a String
  56. Scanner sn = new Scanner(System.in);
  57. int num;
  58. String result = "";
  59.  
  60. while(num = sn.nextInt() != -1) {
  61. result = result + abc[num];
  62. }
  63. System.out.println(result);
  64. }
  65.  
  66. Scanner sn = new Scanner(System.in);
  67. int num;
  68. String result = "";
  69.  
  70. while(true) {
  71. num=sn.nextInt();
  72. if(num == -1) {
  73. break;
  74. }
  75. if(num>=0) {
  76. result+=abc[num];
  77. }
  78. }
  79. System.out.println(result);
Add Comment
Please, Sign In to add comment