You need to convert sc.nextLine into int
Scanner sc = new Scanner(new File("temperatur.txt")); int[] temp = new int [12]; int counter = 0; while (sc.hasNextLine()) { String line = sc.nextLine(); temp[counter] = Integer.ParseInt(line); counter++; } int sum = 0; for(int i = 0; i < temp.length; i++) { sum += temp[i]; } double snitt = (sum / temp.length); System.out.println("The average temperature is " + snitt); } }
Related Posts:
- What is an instance variable in Java?
- super() in Java
- What’s the syntax for mod in java
- What does the Java assert keyword do, and when should it be used?
- How do I make a delay in Java?
- Casting variables in Java
- Compiler Error “void value not ignored as it ought to be” in C programming [duplicate]
- max value of integer
- How can I prevent java.lang.NumberFormatException: For input string: “N/A”?
- Java compile error: “reached end of file while parsing }”
- Non-static variable cannot be referenced from a static context
- Non-static variable cannot be referenced from a static context
- Non-static variable cannot be referenced from a static context
- What is the difference between == and equals() in Java?
- What does “?” mean in Java?
- Java – No enclosing instance of type Foo is accessible
- Why I am getting java.lang.AbstractMethodError errors?
- fix java.net.SocketTimeoutException: Read timed out
- Else without if
- Error: Could not find or load main class in intelliJ IDE
- How to override equals method in Java
- java.text.ParseException: Unparseable date
- java.io.IOException: Broken pipe
- java.util.NoSuchElementException: No line found
- Even though JRE 8 is installed on my MAC -” No Java Runtime present,requesting to install ” gets displayed in terminal
- Reason for the exception java.lang.VerifyError: Bad type on operand stack
- The specified DSN contains an architecture mismatch between the Driver and Application. JAVA
- Downcasting in Java
- Java “params” in method signature?
- How do I time a method’s execution in Java?
- repaint() Method in Java
- What does “error: ‘.class’ expected” mean and how do I fix it
- Java error: void cannot be converted to String
- Exception in thread “main” java.lang.reflect.InvocationTargetException
- How to set String’s font size, style in Java using the Font class?
- How to use the command update-alternatives –config java
- Fatal error compiling: tools.jar not found:
- java array error “array required but int found”
- this: Cannot use this in static context
- What’s the difference between SoftReference and WeakReference in Java?
- How to draw lines in Java
- NoClassDefFoundError in Java: com/google/common/base/Function
- In Java, what is a shallow copy?
- Error: ‘)’ expected compiler error
- java attempting to assign weaker access privilege error
- Good way to encapsulate Integer.parseInt()
- Eclipse IDE – Error: Build path specifies execution environment Java SE 1.7
- Java: Not a statement
- What is the difference between run-time error and compiler error?
- ArrayList of int array in java
- How to get the filename without the extension in Java?
- intellij idea – Error: java: invalid source release 1.9
- String index out of bounds exception java
- How can I upgrade to Java 1.8 on an Amazon Linux Server?
- Failed to write core dump. minidumps are not enabled by default on client version of windows
- What is .crt and .key files and how to generate them?
- Can’t find mysqladmin on Mac OSX 10.6.8
- how to use proxy on youtube-dl?
- What is an AssertionError? In which case should I throw it from my own code?
- What is an “internal error” and how do I fix it?
- How to write a Unit Test?
- Compiling a java program into an executable
- Java Installation Not Completed / Unable to install Java
- How can I open Java .class files in a human-readable way?
- error: expected primary-expression before ‘)’ token (C)
- What is the difference between application server and web server?
- HTTP Status 405 – Request method ‘POST’ not supported (Spring MVC)
- Missing `server’ JVM (Java\jre7\bin\server\jvm.dll.)
- Convert String array to ArrayList
- java uses or overrides a deprecated API error
- What is setBounds and how do I use it?
- “The certificate chain was issued by an authority that is not trusted” when connecting DB in VM Role from Azure website
- Easiest way to convert a List to a Set in Java
- Exception in thread “main” java.lang.ClassNotFoundException:
- What’s the complete range for Chinese characters in Unicode?
- What does ‘public static void’ mean in Java?
- Error: JAVA_HOME is not defined correctly executing maven
- Eclipse No tests found using JUnit 5 caused by NoClassDefFoundError for LauncherFactory
- Android – SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
- How to sort an array of objects in Java?
- CreateProcess error=2, The system cannot find the file specified
- Converting string to integer VB.NET
- Visual Studio compiles but the exe isn’t there
- calling boolean method, heads or tails
- Android Color Picker
- How to fix an UnsatisfiedLinkError (Can’t find dependent libraries) in a JNI project
- How to Delete a topic in apache kafka [duplicate]
- Java Main Game Loop
- “Integer number too large” error message for 600851475143
- Good way to encapsulate Integer.parseInt()
- What is the difference between “Double” and “double” in Java?
- How to disable an Android button?
- How to set initial value and auto increment in MySQL?
- How can I prevent the WordPress Importer from munging double-newline paragraph breaks to a single newline?
- Any benefit or detriment from removing a pagefile on an 8 GB RAM machine?
- How do I view the details of a digital certificate .cer file?
- How do you validate fstab without rebooting?
- DNS – NSLOOKUP what is the meaning of the non-authoritative answer?
- Why can’t a CNAME record be used at the apex (aka root) of a domain?
- What port should I open to allow remote desktop?