Advertisement
Crenox

Practice Java Program

Sep 11th, 2015
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Main
  4. {
  5. Scanner sc = new Scanner(System.in);
  6.  
  7. public void print()
  8. {
  9. String a = "";
  10. System.out.println("What would you like to display on the console?");
  11. a = sc.nextLine();
  12. System.out.println("\"" + a + "\"");
  13. }
  14.  
  15. public void loop()
  16. {
  17. String a = "";
  18. int count = 1;
  19. System.out.println("What would you like to display on the console 10 times in a row?");
  20. a = sc.nextLine();
  21. for (int i = 0; i < 10; i++)
  22. {
  23. System.out.println(count + "." + " \"" + a + "\"");
  24. count++;
  25. }
  26. }
  27.  
  28. public void arr()
  29. {
  30. int number = 0;
  31. int count = 1;
  32. System.out.println("How many entries would you like in your String array?");
  33. number = sc.nextInt();
  34. String[] a = new String[number];
  35.  
  36. System.out.println("What are the values you'd like to display?");
  37.  
  38. for (int i = 0; i < number; i++)
  39. {
  40. a[i] = sc.nextLine();
  41. System.out.println(count + "." + " \"" + a + "\"");
  42. count++;
  43. }
  44. }
  45.  
  46. public void methods()
  47. {
  48. // trim()
  49. String input = " some thing ";
  50. System.out.println("TRIM");
  51. System.out.println("Before -->" + input + "<--");
  52. System.out.println("After -->" + input.trim() + "<--");
  53. }
  54.  
  55. public static void main(String args[])
  56. {
  57.  
  58. }
  59. }
  60. ------------------------------------------------------------------------------------------------------------------------------
  61. public class Tester
  62. {
  63. public static void main(String args[])
  64. {
  65. Main m = new Main();
  66.  
  67. m.print();
  68. System.out.println("=======================================================================");
  69. m.loop();
  70. System.out.println("=======================================================================");
  71. m.arr();
  72. System.out.println("=======================================================================");
  73. m.methods();
  74. }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement