Advertisement
RyanSaq

Chapter 6 Programs 1

Jan 27th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.62 KB | None | 0 0
  1. package com.suarez;
  2.  
  3. import java.util.Scanner;
  4.  
  5. /*
  6. Ryan Saqueton
  7. Looks for @ in an email address
  8. */
  9. public class Q62 {
  10. public static void main(String[] args){
  11. String email;
  12. Scanner scan = new Scanner(System.in);
  13. System.out.println("What is your email address?");
  14. email = scan.next();
  15.  
  16. if (email.contains("@")) {
  17. System.out.println("Email address is valid");
  18. } else {
  19. System.out.println("Email address is invalid");
  20. }
  21. }
  22.  
  23. package com.suarez;
  24.  
  25. import java.util.*;
  26. /*
  27. Ryan Saqueton
  28. Converts decimal to binary
  29. */
  30. public class Q64 {
  31. public static void main(String[] args) {
  32. int n, count = 0, a;
  33. String x = "";
  34. Scanner s = new Scanner(System.in);
  35. System.out.println("Enter any decimal number:");
  36. n = s.nextInt();
  37. while (n > 0) {
  38. a = n % 2;
  39. if (a == 1) {
  40. count++;
  41. }
  42. x = x + "" + a;
  43. n = n / 2;
  44. }
  45. System.out.println("Binary number:" + x);
  46. }
  47. }
  48.  
  49. package com.company;
  50.  
  51. import java.util.Scanner;
  52.  
  53.  
  54. /*
  55. Ryan Saqueton
  56. Uses XOR to determine true or false
  57. */
  58. public class Q66 {
  59. public static void main(String[] args) {
  60.  
  61. System.out.println("Input a binary number.");
  62. Scanner input = new Scanner(System.in);
  63.  
  64. String URL = input.nextLine();
  65. int x = 0;
  66. int y = 0;
  67.  
  68. while(URL.indexOf("1") != -1){
  69. URL = URL.replaceFirst("1","_");
  70. y = y+1;
  71. }
  72.  
  73. while(URL.indexOf("0") != -1){
  74. URL = URL.replaceFirst("0","_");
  75. x = x+1;
  76. }
  77.  
  78. if(x==y)
  79. {
  80. System.out.print("0 , False");
  81. }
  82. else
  83. {
  84. System.out.print("1 , True");
  85. }
  86. }
  87. }
  88.  
  89. package com.suarez;
  90.  
  91. import java.util.Scanner;
  92.  
  93. package com.suarez;
  94.  
  95. import java.util.Scanner;
  96.  
  97. /*
  98. Ryan Saqueton
  99. Sees if HTML is Valid
  100. */
  101. public class Q68 {
  102. public static void main(String[] args){
  103. String HTML;
  104. char a = '<';
  105. char b = '>';
  106. Scanner scan = new Scanner(System.in);
  107. System.out.println("Enter your HTML");
  108. HTML = scan.next();
  109. int length = HTML.length();
  110. char first = HTML.charAt(0);
  111. char last = HTML.charAt(length-1);
  112. if (first == a && last == b) {
  113. System.out.println("HTML is valid");
  114. } else {
  115. System.out.println("HTML is invalid");
  116. }
  117. }
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement