Advertisement
Arush22

Page 338 62-64-66-68

Jan 28th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.18 KB | None | 0 0
  1. 62.
  2. package com.company;
  3. import java.util.*;
  4. import java.lang.*;
  5.  
  6. public class EmailChecker {
  7. public static void main(String[] args)
  8. {
  9. Scanner input = new Scanner(System.in);
  10. System.out.println("Type in your email");
  11. String email = input.next();
  12. int length = email.length();
  13. int counter = 0;
  14. int atCounter = 0;
  15. char currentLetter = email.charAt(counter);
  16. while(counter < length-1){
  17. if( currentLetter == '@'){
  18. atCounter++;
  19. }
  20. counter++;
  21. currentLetter = email.charAt(counter);
  22. }
  23. if(atCounter == 1){
  24. System.out.println("The email is valid");
  25. }
  26. else{
  27. System.out.println("The email is invalid");
  28. }
  29. }
  30. }
  31.  
  32.  
  33.  
  34.  
  35.  
  36. 64.
  37. package com.company;
  38. import java.util.*;
  39. import java.lang.*;
  40.  
  41. public class DecimalToBinary {
  42. public static void main(String[] args)
  43. {
  44. Scanner input = new Scanner(System.in);
  45. System.out.println("Type in a number");
  46. int num = input.nextInt();
  47. System.out.println("The binary form is: "+Integer.toBinaryString(num));
  48. }
  49. }
  50.  
  51.  
  52.  
  53.  
  54. 66.
  55. package com.company;
  56. import java.util.*;
  57. import java.lang.*;
  58.  
  59. public class XOReplicator {
  60. public static void main(String[] args)
  61. {
  62. Scanner input = new Scanner(System.in);
  63. System.out.println("Type in a binary number");
  64. String email = input.next();
  65. int length = email.length();
  66. int counter = 1;
  67. int falseCounter = 0;
  68. int trueCounter = 0;
  69. char currentLetter = email.charAt(counter);
  70. char previousLetter = email.charAt(counter-1);
  71. while(counter < length-1){
  72. if( currentLetter == previousLetter){
  73. falseCounter++;
  74. }
  75. else{
  76. trueCounter++;
  77. }
  78. counter+=2;
  79. currentLetter = email.charAt(counter);
  80. previousLetter = email.charAt(counter-1);
  81. }
  82. if(falseCounter == trueCounter){
  83. System.out.println("False");
  84. }
  85. else{
  86. System.out.println("True");
  87. }
  88. }
  89. }
  90.  
  91.  
  92.  
  93.  
  94.  
  95. 68.
  96. package com.company;
  97. import java.util.*;
  98. import java.lang.*;
  99.  
  100. public class HTMLvalidator {
  101. public static void main(String[] args)
  102. {
  103. Scanner input = new Scanner(System.in);
  104. System.out.println("Type in your code");
  105. String code = input.next();
  106. int length = code.length();
  107. int counter = 0;
  108. int symbolCounter1 = 0;
  109. int symbolCounter2 = 0;
  110. char currentLetter = code.charAt(counter);
  111. while(counter < length-1){
  112. if( currentLetter == '<'){
  113. symbolCounter1++;
  114. }
  115. if( currentLetter == '>'){
  116. symbolCounter2++;
  117. }
  118. counter++;
  119. currentLetter = code.charAt(counter);
  120. }
  121. if(symbolCounter1 == symbolCounter2){
  122. System.out.println("The code is valid");
  123. }
  124. else{
  125. System.out.println("The code is invalid");
  126. }
  127. }
  128. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement