Quantcast
Viewing all articles
Browse latest Browse all 2703

First time FOR loop - can't figure out how to make it loop

My project is to:

Have user enter a "lower bound" and a "higher bound" for a range of integers that I'm making 0-10.

The code is supposed to automatically calculate and display the squares and the square roots for all numbers in the range.

If the lower bound is greater than the upper bound, the statement "No work is to be performed" should be displayed.
---------------------------------------------

I can make the input work and get the first part to display, but I can't figure out the LOOP part and I can't figure out the if/else to get it to work.

If anyone can help, I would appreciate it. Here is what I have:
------------------------------------------

import java.util.*;

public class P4
{
public static void main(String[] args)
{
int x;
int lowerBound, upperBound;
double square, squareRoot;
Scanner kb = new Scanner(System.in);

for (x = 1; x <= 10; x++);
{
System.out.print("Please enter a lower bound: ");
lowerBound = kb.nextInt();

System.out.print("Please enter an upper bound: ");
upperBound = kb.nextInt();

square = Math.pow(lowerBound,2);
squareRoot = Math.sqrt(lowerBound);

if (lowerBound <= upperBound)
System.out.printf("For the value of " + lowerBound + ", the square is " + "%.2f", +square);
System.out.printf(" and the square root is " + "%.2f%n", +squareRoot);

if (lowerBound > upperBound)
System.out.println("The lower bound is greater than the upper bound.");
System.out.println("No work will be performed.");
}
}}

Viewing all articles
Browse latest Browse all 2703

Trending Articles