In Java programming, type mismatch errors are a common problem. When we try to convert a long value to an int, we get the error "java type mismatch: cannot convert from long to int". This error message means that we are trying to convert a data type with a larger range to a data type with a smaller range, resulting in the risk of data loss or overflow. In this article, PHP editor Xinyi will analyze the cause of this error for you and provide solutions to solve it.
Question content
long A[]=new long[1000]; Scanner a=new Scanner(System.in); for(long I=0;I<A.length;I++) { A[I]=a.nextLong();//error } return true; }
This is why I'm getting a type mismatch: cannot convert from long to int
I don't understand why we get type mismatch because i is long and a[] is also long So why do we get a long to int type mismatch.
Solution
Use int instead of long in the for loop:
long A[]=new long[1000]; Scanner a=new Scanner(System.in); for(int I=0;I<A.length;I++) { A[I]=a.nextLong();//error }
Unable to index long type array:https://www.php.cn/link/6dfa678a0fa26a0b36addfbc8fdc23e1
The above is the detailed content of java type mismatch: cannot convert from long to int. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

WebStorm Mac version
Useful JavaScript development tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Zend Studio 13.0.1
Powerful PHP integrated development environment

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function
