Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package nestedif;
- /**
- *
- * @author Ron Ivin Gregorio
- */
- import java.util.*;
- public class hey {
- public static void main(String[] args) {
- char operator;
- double sum = 0.0, prod = 1.0, diff = 0.0, quot = 1.0;
- Scanner input = new Scanner(System.in);
- System.out.print("Enter number of whole numbers to process: ");
- int nnum = Integer.parseInt(input.nextLine());
- int arraywholenum[] = new int[nnum];
- for (int i = 0; i<arraywholenum.length; i++)
- {
- System.out.print("Enter the Whole number " +(i+1)+ " : " );
- arraywholenum[i] = input.nextInt();
- }
- System.out.println();
- System.out.print("Enter operator (+,-,* or /) ");
- operator = input.next().charAt(0);
- switch(operator)
- {
- case '+':
- for (int i = 0; i<arraywholenum.length; i++)
- {
- sum = sum + arraywholenum[i];
- }
- System.out.println("The sum is: " +sum);
- break;
- case '-':
- for (int i = 0; i<arraywholenum.length; i++)
- {
- diff = diff - arraywholenum[i];
- }
- System.out.println("The diff is: " +diff);
- break;
- case '*':
- for (int i = 0; i<arraywholenum.length; i++)
- {
- prod = prod * arraywholenum[i];
- }
- System.out.println("The product is: " +prod);
- break;
- case '/':
- for (int i = 0; i<arraywholenum.length; i++)
- {
- quot = quot / arraywholenum[i];
- }
- System.out.println("The quotient is: " +quot);
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement