import javax.swing.*; public class EvenNums { public static void main(String[]ar
ID: 3611593 • Letter: I
Question
import javax.swing.*;public class EvenNums
{
public static void main(String[]args)throws Exception
{
int response = 0;
while (response ==0)
{
String word = JOptionPane.showInputDialog(null,"Type in an integer");
String word1 = JOptionPane.showInputDialog(null,"Type in a second integer");
int num1 =Integer.parseInt(word);
int num2 =Integer.parseInt(word1);
int a;
String numbers = "";
for(a = num1;a<= num2; a++)
{
if(a%2 == 0);
numbers += ""+ a + " ";
}
JOptionPane.showMessageDialog(null,"The even numbers between "+ num1 + " and" + num2+ " are " +numbers);
response = JOptionPane.showConfirmDialog(null,"Do you want torepeat?");
}
}
}
I don't know how to print even numbers, can you help?
import javax.swing.*;
public class EvenNums
{
public static void main(String[]args)throws Exception
{
int response = 0;
while (response ==0)
{
String word = JOptionPane.showInputDialog(null,"Type in an integer");
String word1 = JOptionPane.showInputDialog(null,"Type in a second integer");
int num1 =Integer.parseInt(word);
int num2 =Integer.parseInt(word1);
int a;
String numbers = "";
for(a = num1;a<= num2; a++)
{
if(a%2 == 0);
numbers += ""+ a + " ";
}
JOptionPane.showMessageDialog(null,"The even numbers between "+ num1 + " and" + num2+ " are " +numbers);
response = JOptionPane.showConfirmDialog(null,"Do you want torepeat?");
}
}
}
I don't know how to print even numbers, can you help?
Explanation / Answer
please rate - thanks import javax.swing.*; public class EvenNums { public static void main(String[] args)throws Exception { int response = 0,start; while (response == 0) { String word = JOptionPane.showInputDialog(null, "Type in aninteger"); String word1 = JOptionPane.showInputDialog(null, "Type in a secondinteger"); int num1 = Integer.parseInt(word); int num2 = Integer.parseInt(word1); int a; if(num1%2==1) start=num1+1; else start=num1; String numbers = " "; for(a = start; aRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.