Advertisement
Guest User

Untitled

a guest
Nov 1st, 2014
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.52 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4.  
  5. static Scanner in = new Scanner(System.in);
  6.  
  7. public static void main(String[] args) {
  8.  
  9.  
  10. iMenuMethod();
  11.  
  12. }
  13.  
  14. public static void iMenuMethod() {
  15.  
  16. int iMenu;
  17.  
  18. do {
  19. System.out.println("Enter the question number you wish to see. and press 6 to exit!");
  20. iMenu = in.nextInt();
  21.  
  22. switch (iMenu) {
  23. case 1:tar1();
  24. break;
  25. case 2:tar2();
  26. break;
  27. case 3:tar3();
  28. break;
  29. case 4:tar4();
  30. break;
  31. case 5:tar5();
  32. break;
  33. case 6:return;
  34. default:System.err.println("You need to enter a number from 1-5!");
  35. break;
  36. }
  37. }while(iMenu != 6);
  38. }
  39.  
  40. public static void tar1(){
  41.  
  42. //prints out 7 stars in a row
  43. for (int j = 1; j<8; j++)
  44. {
  45. System.out.print("*");
  46.  
  47. }
  48.  
  49. System.out.println("\n--------------------");
  50.  
  51. //prints out 7 stars one after the other
  52. for (int i = 1; i < 8; i++)
  53. {
  54. System.out.println("*");
  55. }
  56. System.out.println("--------------------");
  57.  
  58. //counts from 1-10
  59. for (int counter = 1; counter <= 10; counter++)
  60. {
  61. System.out.println(counter);
  62. }
  63.  
  64. System.out.println("--------------------");
  65.  
  66. //counts from 20-35
  67. for(int c = 20; c <= 35; c++)
  68. {
  69. System.out.println(c);
  70. }
  71.  
  72. System.out.println("--------------------");
  73.  
  74. //prints all the odd numbers from 1-50
  75. for(int z = 1; z <= 50; z+=2)
  76. {
  77. System.out.println(z);
  78. }
  79.  
  80. System.out.println("--------------------");
  81.  
  82. //counts all the numbers divisible by 3 from 3-30
  83. for(int i = 3; i <= 30; i+=3)
  84. {
  85. System.out.println(i);
  86. }
  87.  
  88. System.out.println("--------------------");
  89.  
  90. //all the even numbers from 2-100
  91. for (int j = 2; j<=100; j+=2)
  92. {
  93. System.out.println(j);
  94. }
  95.  
  96. }
  97.  
  98.  
  99. /*
  100. * This program will go over the numbers 1-50 and
  101. * if the number can be divided by 8 it will print Nice next to it.
  102. */
  103. public static void tar2(){
  104.  
  105. for (int i = 1; i <= 50; i++) {
  106. if (i % 8 == 0) {
  107. System.out.println(i + " nice");
  108. }
  109. else
  110. {
  111. System.out.println(i);
  112. }
  113. }
  114.  
  115. }
  116.  
  117. public static void tar3(){
  118.  
  119. int iSum1 = 0;
  120. //will count from 1-10 and add the numbers together
  121. for (int i = 1; i <= 10; i++)
  122. {
  123. System.out.println(i);
  124. iSum1 = iSum1 + i;
  125. }
  126. System.out.println("The sum is: " + iSum1);
  127. System.out.println("----------------------------");
  128.  
  129. int iSum2 = 0;
  130. //count from 30-50 and add the numbers together
  131. for (int i = 30; i <= 50; i++)
  132. {
  133. System.out.println(i);
  134. iSum2 = iSum2 + i;
  135. }
  136. System.out.println("The sum is: " + iSum2);
  137. }
  138.  
  139. public static void tar4(){
  140. int iSum = 0;
  141.  
  142. //adds the numbers from 200-300 together
  143. for (int i = 200; i <= 300; i++) {
  144. iSum = iSum + i;
  145. }
  146. System.out.println("The sum is: " + iSum);
  147. }
  148.  
  149. public static void tar5(){
  150. double iSum = 0;
  151.  
  152. //adds the numbers from 1/200 + 1/201... till 1/300 together
  153. for (int i = 200; i <= 300; i++) {
  154. iSum = (1.0 / i);
  155. }
  156. System.out.println("The sum is: " + iSum);
  157. }
  158. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement