daniel_lawson9999

Daniel Lawson Chapter 4 Self Check 20-28 even

Apr 20th, 2016
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.86 KB | None | 0 0
  1. /**
  2.  * Created by Daniel on 4/20/2016.
  3.  */
  4. 20.
  5. it prints all the letters in a range of two letters
  6. efg
  7. nopqrs
  8.  
  9. qr
  10.  
  11. 21.
  12. String s = [words]
  13. char s = s.charAt(0);
  14. if(isUpperCase(c)){
  15. //statements
  16. }
  17. 22.
  18. It uses the incorrect syntax of s.charAt(i).toLowerCase(), when it should be:
  19. Character.toLowerCase(s.charAt(i))
  20. 24.
  21. /**
  22.  * Created by Daniel on 4/20/2016.
  23.  */
  24. //create a code to examine astring and determine how many of its letters come from the second half of the alhabet
  25. // have values of 'n' or subsequent letters, assume every character in a string is a letter, case intensively
  26. import java.util.*;
  27. public class selfCheck24 {
  28.     public static void main(String[] args) {
  29.         Scanner c = new Scanner(System.in);
  30.         v(c);
  31.     }
  32.  
  33.     public static void v(Scanner c) {
  34.         System.out.print("Enter a string:");
  35.         String s = c.next();
  36.         int count = 0;
  37.         for (int i = 0; i < s.length(); i++) {
  38.             if (Character.toLowerCase(s.charAt(i)) >= 'n') {
  39.                 count++;
  40.             }
  41.         }
  42.         System.out.printf("total count %d",count);
  43.     }
  44. }
  45. 26.
  46. In the parameters of the method one must enter the grade percentage value
  47. so that later in the method it can convert the previously gien values to a value between 0.0-4.0
  48. 28.
  49. modified version to work in the situation that a != 0... because if a = 0 then you would not be using a quadratic.
  50.  public static String quadratic(int a, int b, int c){
  51.       String answer = "Error, [int a] must not be equal to zero";
  52.       if(a != 0){
  53.         double xplus = (b*-1 + Math.sqrt((b*b)-(4*a*c)*1.0)) / 2*a ;
  54.         double xminus = (b*-1 - (Math.sqrt((b*b)-(4*a*c)*1.0)) ) / 2*a ;
  55.         answer = "x = " + (int)xplus + "," + "x = " + (int)xminus;
  56.         }
  57.       return answer;
  58.     }
  59. //In this new version, the program returns an error message if a equals 0.
Advertisement
Add Comment
Please, Sign In to add comment