I'm new to coding so I'm really sorry if you guys find this question foolish.
so this is my code so far, also I'm using netbeans.
package act.pkg3.program.pkg1;
public class Act3Program1 {
import java.util.Scanner;
public static void main(String[] args) {
int intComputer;
System.out.println("please enter the number of computer/monitor you own:");
intComputer = keyedInput.nextInt();
System.out.println("The total number of tons of water used to manufacture:");
intComputer = intComputer * 1,5 ;
}
}
I tried to search for the answer and I heard people said to uncheck the "compile on save". I did turn it off but the code still couldn't run properly, and I'm also not sure if something could be wrong with my code.
the output look like this:
ant -f "C:\\Users\\Vee\\Documents\\NetBeansProjects\\Act 3 program 1" -Dnb.internal.action.name=run run
init:
Deleting: C:\Users\Vee\Documents\NetBeansProjects\Act 3 program 1\build\built-jar.properties
deps-jar:
Updating property file: C:\Users\Vee\Documents\NetBeansProjects\Act 3 program 1\build\built-jar.properties
Compiling 1 source file to C:\Users\Vee\Documents\NetBeansProjects\Act 3 program 1\build\classes
C:\Users\Vee\Documents\NetBeansProjects\Act 3 program 1\src\act\pkg3\program\pkg1\Act3Program1.java:9: error: illegal start of type
import java.util.Scanner;
C:\Users\Vee\Documents\NetBeansProjects\Act 3 program 1\src\act\pkg3\program\pkg1\Act3Program1.java:9: error: <identifier> expected
import java.util.Scanner;
C:\Users\Vee\Documents\NetBeansProjects\Act 3 program 1\src\act\pkg3\program\pkg1\Act3Program1.java:17: error: ';' expected
intComputer = intComputer * 1,5 ;
3 errors
BUILD FAILED (total time: 1 second)
CodePudding user response:
You can do in this way:) happy coding.
package act.pkg3.program.pkg1;
public class Act3Program1 {
import java.util.Scanner;
public static void main(String[] args) {
int intComputer;
Scanner s = new Scanner(System.in);
System.out.println("please enter the number of computer/monitor you own:");
intComputer = scan.nextInt();
System.out.println("The total number of tons of water used to manufacture:");
intComputer = intComputer * 1,5 ;
}
}
CodePudding user response:
This class definition is invalid:
public class Act3Program1 {
import java.util.Scanner;
}
While this one is valid:
import java.util.Scanner;
public class Act3Program1 {
}
The only difference is where the "import" statement went. Import statements go at the top, outside of a class definition.