import java.util.*;
public class Main
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter array size");
int n = sc.nextInt();
int arr[] = new int[n];
int i;
System.out.println("Enter elements of Array");
for(i=0;i<n;i++)
arr[i]= sc.nextInt();
int for_loop_sum = 0;
for(i=0;i<n;i++)
for_loop_sum+=arr[i];
System.out.println("Sum using for loop:" + for_loop_sum);
int while_loop_sum = 0;
i=0;
while(i<n)
{
while_loop_sum+=arr[i];
i++;
}
System.out.println("Sum using while loop:" + while_loop_sum);
i = 0;
int do_while_sum = 0;
do{
do_while_sum+=arr[i];
i++;
}while(i<n);
System.out.println("Sum using do_while loop:" + do_while_sum);
}
}
1) use java to print the sum of the list (any #s) using keyboard, also using...
Java Submit a program in a .java file. The program should print a multiplication table for the numbers 1-9. This requires a nested for loop. The outer loop moves from row to row, while the inner loop prints the row. Use tabs to separate the output, such as in the following statement: System.out.println(“1\t2\t3\t4\t5\t6\t7\t8\t9”); Output should look similar to the following. 1 2 3 4 5 6 7 8 9 ------------------------------------------------------------------ 1 2 3 4 5 6 7 8 9...
All the programs are to be written in java 1. WAP to print American Flag Using Loop in as minimum code as possible. 1.1 Ask user to enter age, sex ( M or F ), marital status ( Y or N ) and then using following rules print their place of service. if employee is female, then she will work only in urban areas. if employee is a male and age is in between 20 to 40 then...
In java language: Ask for keyboard input of a decimal number. Use a loop to keep asking for input of up to ten numbers. Exit the loop if ten numbers are entered or if a sentinel value for “QUIT” is entered. Store the numbers in an array. Sort the array according to ascending number. Get the average for all the numbers in the array. Print out the average. Calculate the distance from the average for each number in the array...
Java questions Part 1 Express the code fragment shown below using only a for loop. int n = 0; while (n <= 100) { int sum = sum + n; n = n + 1; System.out.println (sum); } Part 2 Use a loop structure to determine and print all positive integers between 1 and 100 that are divisible (evenly) by 5 and 8
in C
The preceding LML program reads two numbers from the keyboard and determines and prints the larger value. Note the use of the instruction +4107 as a conditional trans- fer of control, much the same as C's if statement. In-Class Tasks Write LML programs that accomplish each of the following tasks: Use a sentinel-controlled loop to read 10 positive integers and compute and print their sum 1. 2. Use a counter-controlled loop to read seven numbers, some positive and...
Java program: Print the sum, difference, and product of 2 numbers without using variables.
Complete the following code snippet using java so that it finds the sum of doubles the user inputs. Your answer should be a while loop with a condition that needs to be true if the user inputs a double. Your answer should be a single while loop. Scanner scnr = new Scanner(System.in); int sum = 0;
using java find the third most frequent word in a paragraph in an array list. also print the sentences that include this word. the paragraph is stored in an array list. you have to search within the array list the third most used word.
Step 1. Write a program in assembly language (using macros) to print out the following messages on the screen [20 marks]: Hello, programmers! Welcome to the world of, Linux assembly programming! Step 2. Write a C function to passed two numbers to the function and calculate the sum of all the numbers between them (both inclusive). [50 marks] a. Make a version with for loop b. Make a version with while loop c. Make a version with do.. while loop...
Write a for-loop that will loop the following salaries in the list s, sum the salaries, find the average salary, and print the value of the average salary. #complete the code below with your solution sum = 0 n = 0 s = [28000, 42500, 32600, 29700]