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

  Java tv''s newest owner! java tv is the greatest tv channel

Java TV's newest owner! Java TV is the greatest TV channel ever, and it prides itself in its 24 hour interesting ' programming'. To help you run this channel you will need to write a  dynamic  program that uses  Data Lists  to store all its TV show i..

  Display a table of values

Using Netbeans, use repetition to display a table of values showing x, the square of x and the cube of x. X is to go up to 5.

  Write a method that reads the contents of the two files

BoyNames.txt This file contains a list of the 20 most popular names given to boys born in the US in 2011.

  Problem 1 the queue adta queue is a fundamental abstract

problem 1. the queue adta queue is a fundamental abstract data type. it is an ordered collection of items in which the

  Write a program using bucket sort idea to create histograms

The input data are in an external file named election.txt. The first line is an integer N representing the number of candidates. The next N lines are the names of the canditates.

  Write a program in Java to check if a number is even

Write a program in Java to check if a number is even or odd in Java?

  Calculates the cost of a mortgage

Write a class called Mortgage that calculates the cost of a mortgage. Prompt the user to enter the principal amount, the term in years, and the interest rate per year.

  Develop java package comprising of class using encapsulation

Develop the Java package comprising of Class and Student with the given requirements. Encapsulation, Method to print student details alone.

  Develop a java based gui application

Develop a Java based GUI application(using swing) that allows the user to enter Charity/Fund information and display them in a JTable

  You will need a bottomuptwothreefourtree class with a

you will need a bottomuptwothreefourtree class with a bottomuptwothreetreefourtree constructor which takes no

  Design and implement a sorting algorithm

Your task is to design and implement a sorting algorithm and running time grows as a linear function of the array

  Integer expression evaluator

You must implement a bounded generic Stack class. Represent your Stack using an array to hold the stack content - Integer Expression Evaluator

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