Advertisement
Arush22

Untitled

Jan 29th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.69 KB | None | 0 0
  1. 61.
  2. package com.company;
  3. import java.util.*;
  4. import java.lang.*;
  5.  
  6. public class ExamScores {
  7. public static void main(String[] args)
  8. {
  9. Scanner input = new Scanner(System.in);
  10. int min = 100;
  11. int max = 0;
  12. int avg;
  13. int gradeSum = 0;
  14. System.out.println("Please type 10 of your grades.");
  15. int grade = input.nextInt();
  16. int counter = 1;
  17. gradeSum += grade;
  18. while(counter <= 10) {
  19. if (grade < 0 || grade > 100) {
  20. System.out.println("This grade is invalid");
  21. counter = 13;
  22. } else {
  23. if (grade < min) {
  24. min = grade;
  25. }
  26. if (grade > max) {
  27. max = grade;
  28. }
  29. if (counter != 10) {
  30. System.out.println("Please type another one of your grades.");
  31. grade = input.nextInt();
  32.  
  33.  
  34. gradeSum += grade;
  35. }
  36. counter++;
  37. }
  38. }
  39. avg = gradeSum/10;
  40. if(counter == 11) {
  41. System.out.println("The smallest number that you typed is " + min);
  42. System.out.println("The largest number that you typed is " + max);
  43. System.out.println("The average of the numbers is " + avg);
  44. }
  45. }
  46. }
  47.  
  48.  
  49.  
  50. 63.
  51. package com.company;
  52. import java.util.*;
  53. import java.lang.*;
  54.  
  55. public class IDentifier {
  56. public static void main(String[] args)
  57. {
  58. Scanner input = new Scanner(System.in);
  59. System.out.println("Type in your ID");
  60. String id = input.next();
  61. int length = id.length();
  62. int counter = 0;
  63. int digitCounter = 0;
  64. char currentChar = id.charAt(counter);
  65. while(counter < length-1){
  66. if( currentChar == '1'||currentChar == '2'||currentChar == '3'||currentChar == '4'||currentChar == '5'||currentChar =='6'||currentChar == '7'||currentChar == '8'||currentChar == '9'||currentChar == '0'){
  67. digitCounter++;
  68. }
  69. counter++;
  70. currentChar = id.charAt(counter);
  71. }
  72. if(digitCounter == 2){
  73. System.out.println("The id is valid");
  74. }
  75. else{
  76. System.out.println("The id is invalid");
  77. }
  78. }
  79. }
  80.  
  81.  
  82.  
  83.  
  84. 65.
  85. package com.company;
  86. import java.util.*;
  87. import java.lang.*;
  88.  
  89. public class BinaryToDecimal {
  90. public static void main(String[] args)
  91. {
  92. Scanner input = new Scanner(System.in);
  93. System.out.println("Type in a binary number");
  94. String binaryNum = input.next();
  95. System.out.println("The binary form is: "+Integer.parseInt(binaryNum,2));
  96. }
  97. }
  98.  
  99.  
  100.  
  101. 67.
  102. package com.company;
  103. import java.util.*;
  104. import java.lang.*;
  105.  
  106. public class PalindromeChecker {
  107. public static void main(String[] args)
  108. {
  109. Scanner input = new Scanner(System.in);
  110. System.out.println("Type in a sentence");
  111. String word = input.nextLine();
  112. String trueWord = word.toLowerCase();
  113. int length = trueWord.length();
  114. int counter1 = 0;
  115. int truthChecker = 1;
  116. char currentLetter1 = trueWord.charAt(counter1);
  117. for(int i = 1; i < length; i++){
  118. if(currentLetter1 == trueWord.charAt(length-i)){
  119. counter1++;
  120. currentLetter1 = trueWord.charAt(counter1);
  121. truthChecker++;
  122. }
  123.  
  124. }
  125. if(truthChecker==length){
  126. System.out.println("This is a palindrome");
  127. }
  128. else
  129. {
  130. System.out.println("Not a palindrome");
  131. }
  132. }
  133. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement