Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Main {
- static Scanner in = new Scanner(System.in);
- public static void main(String[] args) {
- iMenuMethod();
- }
- public static void iMenuMethod() {
- int iMenu;
- do {
- System.out.println("Enter the question number you wish to see. and press 6 to exit!");
- iMenu = in.nextInt();
- switch (iMenu) {
- case 1:tar1();
- break;
- case 2:tar2();
- break;
- case 3:tar3();
- break;
- case 4:tar4();
- break;
- case 5:tar5();
- break;
- case 6:return;
- default:System.err.println("You need to enter a number from 1-5!");
- break;
- }
- }while(iMenu != 6);
- }
- public static void tar1(){
- //prints out 7 stars in a row
- for (int j = 1; j<8; j++)
- {
- System.out.print("*");
- }
- System.out.println("\n--------------------");
- //prints out 7 stars one after the other
- for (int i = 1; i < 8; i++)
- {
- System.out.println("*");
- }
- System.out.println("--------------------");
- //counts from 1-10
- for (int counter = 1; counter <= 10; counter++)
- {
- System.out.println(counter);
- }
- System.out.println("--------------------");
- //counts from 20-35
- for(int c = 20; c <= 35; c++)
- {
- System.out.println(c);
- }
- System.out.println("--------------------");
- //prints all the odd numbers from 1-50
- for(int z = 1; z <= 50; z+=2)
- {
- System.out.println(z);
- }
- System.out.println("--------------------");
- //counts all the numbers divisible by 3 from 3-30
- for(int i = 3; i <= 30; i+=3)
- {
- System.out.println(i);
- }
- System.out.println("--------------------");
- //all the even numbers from 2-100
- for (int j = 2; j<=100; j+=2)
- {
- System.out.println(j);
- }
- }
- /*
- * This program will go over the numbers 1-50 and
- * if the number can be divided by 8 it will print Nice next to it.
- */
- public static void tar2(){
- for (int i = 1; i <= 50; i++) {
- if (i % 8 == 0) {
- System.out.println(i + " nice");
- }
- else
- {
- System.out.println(i);
- }
- }
- }
- public static void tar3(){
- int iSum1 = 0;
- //will count from 1-10 and add the numbers together
- for (int i = 1; i <= 10; i++)
- {
- System.out.println(i);
- iSum1 = iSum1 + i;
- }
- System.out.println("The sum is: " + iSum1);
- System.out.println("----------------------------");
- int iSum2 = 0;
- //count from 30-50 and add the numbers together
- for (int i = 30; i <= 50; i++)
- {
- System.out.println(i);
- iSum2 = iSum2 + i;
- }
- System.out.println("The sum is: " + iSum2);
- }
- public static void tar4(){
- int iSum = 0;
- //adds the numbers from 200-300 together
- for (int i = 200; i <= 300; i++) {
- iSum = iSum + i;
- }
- System.out.println("The sum is: " + iSum);
- }
- public static void tar5(){
- double iSum = 0;
- //adds the numbers from 1/200 + 1/201... till 1/300 together
- for (int i = 200; i <= 300; i++) {
- iSum = (1.0 / i);
- }
- System.out.println("The sum is: " + iSum);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement