🔒 Closed Java Calculator: Badly Need idea or code for my calculation

Status
Not open for further replies.

PHC-DarkJaVa

Eternal Poster
Good day po sa mga programmer!

Badly need ng help para sa calculation ng code ko. ang process nya dapat ma calculate ko ung naka contain sa array by using any operator. ung addition nag wowork using for loop pero other operator hindi na. since si user ung mag ccreate ng length/size para sa array ko. Nahihirapan ako icode manually create variable to store the data since si user mismo ung mag lalagay kung ilang number ba icocompute nya.

ito ung code ko for loop gamit ko sa addition:

Java:
for(int i = 0; i < myArr.length; i++){
                    total = total + myArr[i];
                }
            
                System.out.print("The result of ");
                for(int i = 0; i < size; i++){
                    if (i > 0){
                        System.out.print(" + ");
                    }
                    System.out.print(myArr[i]);
                }
                readInput(total);

sana may makatulong ASAP badly need ko sya :(

Salamat sa inyo!
 
Base sa code mo; yung total is for sum. So, need mo pa ulit gumawa ng panibagong variable for other operations. Palitan mo na lang si total ng "sum" para di ka maguluhan. Bale ganito mangyayari:
Java:
for(int i = 0; i < myArr.length; i++){
                    sum += myArr[i];
                    difference -= myArr[i];
                    product *= myArr[i];
                    qoutient /= myArr[i];
                }
            
                System.out.print("The sum of ");
                for(int i = 0; i < size; i++){
                    if (i > 0){
                        System.out.print(" + ");
                    }
                    System.out.print(myArr[i]);
                }
                readInput(Sum);
 
Base sa code mo; yung total is for sum. So, need mo pa ulit gumawa ng panibagong variable for other operations. Palitan mo na lang si total ng "sum" para di ka maguluhan. Bale ganito mangyayari:
Java:
for(int i = 0; i < myArr.length; i++){
                    sum += myArr[i];
                    difference -= myArr[i];
                    product *= myArr[i];
                    qoutient /= myArr[i];
                }
          
                System.out.print("The sum of ");
                for(int i = 0; i < size; i++){
                    if (i > 0){
                        System.out.print(" + ");
                    }
                    System.out.print(myArr[i]);
                }
                readInput(Sum);
execution will be wrong, values is different from expected output
 
ganito lang yan, no operator choice pero mdas execution.

Java:
import java.util.*;

class Test {
   public static void main(String[] args) {
      Scanner in = new Scanner(System.in);
      int[] arr;
     
      System.out.print("Enter how many numbers to calculate: ");
      int num = in.nextInt();
      arr = new int[num];
      for(int i = 0; i < arr.length; i++) {
         System.out.print("Enter a number: ");
         arr[i] = in.nextInt();
      }

//parts of the code are intentionally excluded

Markdown (GitHub flavored):
Enter how many numbers to calculate: 2
Enter a number: 100
Enter a number: 5
SUM: 105
DIFFERENCE: 95
PRODUCT: 500
QUOTIENT: 20
 
ganito lang yan, no operator choice pero mdas execution.

Java:
import java.util.*;

class Test {
   public static void main(String[] args) {
      Scanner in = new Scanner(System.in);
      int[] arr;
    
      System.out.print("Enter how many numbers to calculate: ");
      int num = in.nextInt();
      arr = new int[num];
      for(int i = 0; i < arr.length; i++) {
         System.out.print("Enter a number: ");
         arr[i] = in.nextInt();
      }

//parts of the code are intentionally excluded

Markdown (GitHub flavored):
Enter how many numbers to calculate: 2
Enter a number: 100
Enter a number: 5
SUM: 105
DIFFERENCE: 95
PRODUCT: 500
QUOTIENT: 20
whoa kung sakaling may execution po operator may way po ba dun? since yun ung required sakin e, kung pwedeng ganto lang gawin ko ays.
 
Status
Not open for further replies.

About this Thread

  • 22
    Replies
  • 2K
    Views
  • 4
    Participants
Last reply from:
FreeAllYouCan-OFFICIAL

Trending Topics

Online now

Members online
988
Guests online
1,140
Total visitors
2,128

Forum statistics

Threads
2,273,853
Posts
28,952,081
Members
1,234,978
Latest member
panda1829
Back
Top