Advertisement
Guest User

Untitled

a guest
Jan 20th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. // The "MFCOMSCIEXAMreview" class.
  2. import java.awt.*;
  3. import hsa.Console;
  4.  
  5. public class MFCOMSCIEXAMreview
  6. {
  7. static Console c; // The output console
  8.  
  9. public static void main (String[] args)
  10. {
  11. c = new Console ();
  12. String word1 = "";
  13. String word2 = "";
  14. String word3 = "";
  15. int lengthHigh = 0;
  16.  
  17. c.println ("Please enter word 1:");
  18. word1 = c.readLine ();
  19. c.println ("Please enter word 2:");
  20. word2 = c.readLine ();
  21. c.println ("Please enter word 3");
  22. word3 = c.readLine ();
  23.  
  24. lengthHigh = wordLength (word1, word2, word3);
  25. c.print ("The longest length of all three names is ");
  26. c.println (lengthHigh);
  27. }
  28.  
  29.  
  30. public static int wordLength (String word1, String word2, String word3)
  31. {
  32. int word1length = 0;
  33. int word2length = 0;
  34. int word3length = 0;
  35. int total = 0;
  36. int high = 0;
  37. word1length = word1.length ();
  38. word2length = word2.length ();
  39. word3length = word3.length ();
  40.  
  41. String[] word = {word1, word2, word3};
  42. for (int i = 0 ; i < word.length ; i++)
  43. {
  44. if (word [i] > high)
  45. {
  46. high = word [i];
  47. }
  48. }
  49. return high;
  50.  
  51. }
  52.  
  53.  
  54. // Place your program here. 'c' is the output console
  55. // main method
  56. } // MethodApp2 class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement