I am pretty new to JAVA. I want to know how I can create a little program where the user can have the start and the end input (2 user inputs). And then count the in between numbers. Like this for example:
- User input 1 = 5; User input 2 = 10; The result should be: 5,6,7,8,9,10.
After some research I got this code but something is wrong, I really appreciate the help!
import javax.swing.*;
class Users{
public static void main(String[] args)
{
int a = userinput();
int b = userinput();
for( a = a <= b ; a = a + 1)
{
System.out.println(a);
}
}
public static int userinput()
{
String tekst = JOptionPane.showInputDialog(null, "enter a number", "Users",3);
int number = Integer.parseInt(tekst);
return number;
}
}
a, you can do this:for(; a <= b; a++) { System.out.println(a); }.forloop is incorrect. It could be fixed asfor (; a <=b; a++) { System.out.println(a); }