Advertisement
Vendrick-Xander

Pg 338 HW programs

Jan 26th, 2019
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.65 KB | None | 0 0
  1. 62.
  2. package com.Suarez;
  3.  
  4. /*
  5. Xander Fermier
  6. 1/25/19
  7. Checks if the entered email adress is valid
  8. */
  9.  
  10. import java.util.*;
  11. import java.lang.*;
  12. public class EmailAddressValidator {
  13. public static void main(String []args)
  14. {
  15. Scanner scan = new Scanner(System.in);
  16. System.out.println("Give me an email address to check");
  17. String input = scan.next();
  18. int inputLength = input.length();
  19. int atCheck = 0;
  20. for (int i = 0; i <= inputLength-1; i++)
  21. {
  22. char inputchar = input.charAt(i);
  23. String atSymbol = String.valueOf(inputchar);
  24. if (atSymbol == "@")
  25. {
  26. atCheck++;
  27. }
  28. atSymbol = "";
  29. }
  30. if (atCheck == 1)
  31. {
  32. System.out.println("The email address is valid.");
  33. }
  34. else
  35. {
  36. System.out.println("The email address is not valid.");
  37. }
  38. }
  39. }
  40. 64.
  41. package com.Suarez;
  42.  
  43. /*
  44. Xander Fermier
  45. 1/25/19
  46. covnerts the users. entered decimal value to binary
  47. */
  48.  
  49. import java.util.*;
  50.  
  51. public class UserDecimalToBinary {
  52. public static void main(String []args)
  53. {
  54. Scanner scan = new Scanner(System.in);
  55. System.out.println("Give me your number to convert.");
  56. String input = scan.next();
  57. System.out.println(Integer.parseInt(input, 2));
  58. }
  59. }
  60. 66.
  61. package com.Suarez;
  62.  
  63. /*
  64. Xander fermier
  65. 1/25/19
  66. this program simulates XOR
  67. */
  68.  
  69. import java.util.*;
  70.  
  71. public class XORSimulator {
  72. public static void main(String[]args)
  73. {
  74. Scanner scan = new Scanner(System.in);
  75. System.out.println("Give me a XOR to check");
  76. String input = scan.next();
  77. char first;
  78. char second;
  79. String truth = "10";
  80. String falseth = "11";
  81. String truth2 = "01";
  82. String falseth2 = "00";
  83. int inputLength = input.length();
  84. StringBuilder check= new StringBuilder();
  85. for (int i = 0; i <= inputLength; i+=2)
  86. {
  87. first = input.charAt(i);
  88. second = input.charAt(i+1);
  89.  
  90. check.append(first);
  91. check.append(second);
  92. }
  93. if (check.equals(truth) || check.equals(truth2))
  94. {
  95. System.out.println("True");
  96. }
  97. else if( check.equals(falseth) || check.equals(falseth2))
  98. {
  99. System.out.println("False");
  100. }
  101. else
  102. {
  103. System.out.println("Invalid entry");
  104. }
  105. }
  106. }
  107. 68.
  108. package com.Suarez;
  109.  
  110. /*
  111. xander Fermier
  112. 1/25/19
  113. this program checks whether the entered HTML is valid based on whether or not it has the same amount of <>
  114. */
  115.  
  116. import java.util.*;
  117.  
  118. public class HTMLChecker {
  119. public static void main(String []args)
  120. {
  121. Scanner scan = new Scanner(System.in);
  122. System.out.println("Give me your line to check");
  123. String input = scan.nextLine();
  124. int inputLength = input.length()-1;
  125. int openBracket = 0;
  126. int closeBracket = 0;
  127. for (int i = 0; i <= inputLength; i++)
  128. {
  129. char inputChar = input.charAt(i);
  130. String bracket = String.valueOf(inputChar);
  131. if (bracket == "<")
  132. {
  133. openBracket++;
  134. }
  135. if (bracket == ">")
  136. {
  137. closeBracket++;
  138. }
  139. bracket = "";
  140. }
  141. if (openBracket == closeBracket)
  142. {
  143. System.out.println("Your HTML is valid.");
  144. }
  145. else
  146. {
  147. System.out.println("Your HTML is not valid.");
  148. }
  149. }
  150. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement