Question
Write a program that accepts two numeric values from the user and displays all integers between these values. Your program will
Accept a starting value
Accept an ending value
Display all the integers (inclusive) between those two values. Your program should count up or down (depending on whether the starting value is greater or less than the ending value)
Here's what I wrote:
String firstString = a.getText();
double a = Double.parseDouble(firstString);
String secondString = b.getText();
double b = Double.parseDouble(secondString);
if(b-a >=1){
for (i=a; i<= b; i++){
outputArea.setText("The value is "+ i);
The issue is that instead of displaying all the numbers between 2 numbers that user enters, my visual calculator only shows the bigger number in a screen. Please help!
Accept a starting value
Accept an ending value
Display all the integers (inclusive) between those two values. Your program should count up or down (depending on whether the starting value is greater or less than the ending value)
Here's what I wrote:
String firstString = a.getText();
double a = Double.parseDouble(firstString);
String secondString = b.getText();
double b = Double.parseDouble(secondString);
if(b-a >=1){
for (i=a; i<= b; i++){
outputArea.setText("The value is "+ i);
The issue is that instead of displaying all the numbers between 2 numbers that user enters, my visual calculator only shows the bigger number in a screen. Please help!
Answers
Ignoring the syntax error of the missing close brace,
all you do is set the text to the latest string displayed. All the other strings are replaced. You need to append a new line for each value of i, not just do a clean reset of the text area each time.
all you do is set the text to the latest string displayed. All the other strings are replaced. You need to append a new line for each value of i, not just do a clean reset of the text area each time.
Related Questions
A program that accepts a plant's name, price, and the plant's light and soil preferences.
A program that accepts a plant's data and displays the results for a plant if it is appropriate for...
write a c program that accepts a name as first name last name but displays the name as last name fir...
a program in c++ that accepts exam marks for 10 students and stores them in an array.the program sho...
Write a program that accepts a person’s weight and displays the number of calories the person
needs...
Make a C program that accepts an integer value at the main method from the keyboard and in turn pass...
c++ program that accepts customer data
,calculates discount based on the age and ticket price depen...
Write a program that accepts salaries of 25 employees into an array into an array and display the fo...
write a program that accepts & displays the pricing of 10 different items from a suppermarket
Create a program that accepts a non- negative integer greater than 2 and determine the number of tim...