Doing some homework here (second assignment, still extremely green…). The object is to read in number x and y and provide the number in the hundreds position.
For this, I need to use int’s I’d assume, as a requirement is to utilize value-returning methods.
I’m just starting to code this, however I’m hitting compile errors already:
Exception in thread “main” java.lang.Error: Unresolved compilation
problems:
Illegal modifier for parameter anum; only final is permitted
Illegal modifier for parameter bnum; only final is permitted
Type mismatch: cannot convert from String to int at Hundreds.main(Hundreds.java:6)
Where am I going wrong?
Here is the code so far:
import java.util.Scanner;
public class Hundreds {
public static void main (String [] args) {
Scanner input = new Scanner(System.in);
private int anum,bnum;
System.out.println("Hello, for this assignment we are going to require the user to enter two distinct numbers of their choosing");
System.out.println("Please ensure the numbers are between 100 and 9999");
System.out.println("\n");
System.out.println("Please enter your first Number: ");
anum = input.nextLine();
Since those variables are local, you can’t set visibility scopes to them like private, public, protected.
Move them out of the main function if you intend their scope to be larger.