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...
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...
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...
In java, write a program that gets 10 integer numbers from the user using user input, and then calculates and display the sum of the numbers that have been read. Program Requirements: Write the program in three versions with three loops. Put all three loops in the main method of your source code. version1: use a while loop. version2: use a do-while loop. version 3: use a for loop. For each version, use a loop to input 10 int numbers from the user...
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]
JAVA Restrictions 1. don't use any other way to implement a loop but recursion (while and for are forbidden). 2. don't use Math.pow\ 3. Pls do not use while or for 1. write a class called MultiplyByItself with a main method 2. the program asks for two integer numbers: x and n. n must be 0 or greater than 0. 3. then the program prints x raised to the n-th power. For example if x is 2 and n is...