Write a for loop that computes the sum of all integers

Assignment Help JAVA Programming
Reference no: EM13879275

Q1. What is the output of the following code snippet

1.1

int i = 0;

while (i != 9)

{

System.out.println("" + i);

i = i + 2;

}

 

1.2.

int i;

int sum=0;

for(i=0; i<5;i++)

{

if(i>1)

sum=sum+i;

}

System.out.println("Sum is " + sum); System.out.println("last value of i is" + i);

Q2. 1 Convert the following for loop into a while loop and draw the flow chart.

int sum = 0;

for (int i = 10; i > 10; i--)

sum = sum + i


Q2.2 Write a for loop that computes the sum of all integers from 1 to 10.


Q3: Write complete Java programs, provide a screen snapshot showing your program in execution to receive full credit.


3.1 Generate the following output using any loop statement .

*
**
***
****
*****

3.2 In municipal elections office, voters are checked for eligibility and after registration they can vote. Write a program that asks the user about their name and age, and check if the voter is eligible to cast vote. (For eligibility age should be greater than 18)

Ask the user "do you want to take another voter details (Yes/No)" if the user presses Yes , take name and age again and check eligibility. Do it again until user presses No.

The following is a sample output when user enters Abdullah/23/Yes , Sarah/15/No.


Sample output:

Enter name: Abdullah

Enter Age :23

Abdullah can cast vote

Do you want to take another voter details (Yes/No) :Yes

Enter name :Sarah

Enter Age :15

Sarah cannot cast vote.

Do you want to take another voter details (Yes/No) : No

Reference no: EM13879275

Questions Cloud

Adonis industries changed its method of valuing inventory : 1.In 2013, Adonis Industries changed its method of valuing inventory from the average cost method to the FIFO method.
Case- iams and eukanuba understand people who love pets : Case- Iams and Eukanuba Understand people who love Pets. Why would consumers continue spending on their pets even during an economic downturn? Explain your answer in terms of consumes baying behavior concepts\
Prepare a production cost report for the month ended march : Aromatic Company for its line of perfume products for the month ended March 3. Prepare a production cost report for the month ended March 31, using the average cost method.
Determine the ratio uo-umax : Water flows steadily through the round pipe in the figure. The entrance velocity is Vo. The exit velocity approximates turbulent flow, u = umax(1 - r/R) 1/7. Determine the ratio Uo/umax for this incompressible flow.
Write a for loop that computes the sum of all integers : Write a for loop that computes the sum of all integers from 1 to 10
Reference validation mechanism and toe security functions : What are the conceptual differences between a reference validation mechanism, a trusted computing base, and the TOE Security Functions and How will you explain to the management of this company why their software is not a high assurance software.
Briefly describe the steps j j should take to report : Briefly describe the steps J J should take to report the change
What is the tax treatment of the scholarship : What is the tax treatment of the scholarship? Is Andrew required to include it as income on his tax return? Is Andrew eligible for the education credits?
Determine the total pressure drop : The mercury manometer reads a 6-in height. The pressure drop p2 - p1 is partly due to friction and partly due to gravity. Determine the total pressure drop and also the part due to friction only. Which part does the manometer read? Why?

Reviews

Write a Review

JAVA Programming Questions & Answers

  Encrypt and decrypt the message using caesar cipher

Encrypt and decrypt the message using Caesar cipher

  The data-centric java agricultural image storing application

Develop and test a specified a data-centric Java application. The required application is described in the Agricultural Image storing application- case-study

  Test the invoice application

Study the error message and note the line number in the statement in the InvoiceApp class that caused the crash. Then click on the link to that line of the code.

  Write java program to print price of table-furniture company

Write down the Java program for furniture company. Ask user to select P for Pine, O for Oak or M for Mahogany. Illustrate the price of table produced with chosen wood.

  Calculate the age of a person given the birthdate

Assemble a program to calculate the age of a person given the birthdate. The output should print the line "In 2014 you will be ''the age of the person" years old." Code needs to be in assembly language using motorola 68000.

  Computing the time complexity using the big-o notation

You are required to calculate the time complexity using the big-O notation of the Algorithm_2 given by the following methods defined by the following Java code.

  Given an array with 100,000 entries to sort

Sorting  given an array with 100,000 entries to sort. Under what circumstances would you use each of the following: insertion sort,mergesort'quicksort

  Java shape program console

Program is adequately documented. It's comments identifies its name, purpose, author and date.Throughout the code, comments and/or relevant component names should attempt to make theprogram understandable.

  What is overloading and what is overriding

What is overloading and what is overriding? Please use code to explain it.

  Design a function named "falling distance"

Design a function named "fallingDistance" that accepts an objects falling time, in seconds, as an argument. The function should return the distance, in meters, that the object has fallen during that time interval. Design a program that calls the func..

  Java program to compare two variables if they are equal

Write down program which will ask user to initialize two character arrays, program must compare two variables if they are equal.

  Design a class named linearequation

(Algebra: 2 X 2 linear equations) Design a class named LinearEquation for a 2 X 2 system of linear equations.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd