What's new

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

Status
Not open for further replies.

skadoosh_29

Eternal Poster
Established
Joined
Jun 24, 2018
Posts
753
Reaction
427
Points
375
Age
25
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.png
 

Attachments

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
 

Attachments

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.
Back
Top