Patulong sa mga halimaw mag coding! thankyou po agad <3

Status
Not open for further replies.

skadoosh_29

Eternal Poster
Create a program that will process the summation of the inputted integer numbers.
But before you process to the summation, correct key is required. If key is correctly inputted, then the
program will ask how many numbers will be added, then display the result. But if the key is wrong, it will display "Incorrect key, program end!".
Program should have array implementation, like keys will be hold by array, the process of summation and etc.
Pls. refer to the attached image.

output.webp
 
Pa check nalang din ts.
Java:
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int key = 321;
        System.out.print("Enter key for simulation: ");
        int user_key = sc.nextInt();
        if(key != user_key)
            System.out.print("Incorect key, program end");
        else {
             System.out.print("Enter no. of items for simulation: ");
             int array_size = sc.nextInt();
             int number_array[] = new int[array_size];
          
             for(int i = 0; i < array_size; i++){
                  System.out.print("Enter no. for simulation: ["+ (i + 1) + "] ? ");
                  number_array[i] = sc.nextInt();
             }
             int sum = 0;
             for(int items : number_array)
                sum += items;
            System.out.print("Summation result is " + sum);
        }
    }
}

Output:

1625540764338.png
 
Pa check nalang din ts.
Java:
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int key = 321;
        System.out.print("Enter key for simulation: ");
        int user_key = sc.nextInt();
        if(key != user_key)
            System.out.print("Incorect key, program end");
        else {
             System.out.print("Enter no. of items for simulation: ");
             int array_size = sc.nextInt();
             int number_array[] = new int[array_size];
         
             for(int i = 0; i < array_size; i++){
                  System.out.print("Enter no. for simulation: ["+ (i + 1) + "] ? ");
                  number_array[i] = sc.nextInt();
             }
             int sum = 0;
             for(int items : number_array)
                sum += items;
            System.out.print("Summation result is " + sum);
        }
    }
}

Output:

View attachment 1482085
tanung ko lang saan ka ang compile sorry baguhan lang kasi po
 
Status
Not open for further replies.

About this Thread

  • 13
    Replies
  • 761
    Views
  • 3
    Participants
Last reply from:
Arcturus

Trending Topics

Online now

Members online
1,121
Guests online
1,738
Total visitors
2,859

Forum statistics

Threads
2,292,474
Posts
29,077,342
Members
1,209,374
Latest member
akosixio
Back
Top