java type mismatch: cannot convert from long to int
Feb 09, 2024 pm 03:30 PMIn 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 Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

How to recover diskgenius data diskgenius data recovery tutorial

How to recover files with the partition tool diskgenius How to recover files with the partition tool diskgenius

How long does the motherboard battery last?

How to recover deleted files with Scanner Almighty King_How to recover deleted files with Scanner Almighty King

The easiest way to convert mobile phone videos to MP4 (quick tips for converting mobile phone videos to MP4 format)

How to set disk high temperature alarm with CrystalDiskInfo hard disk detection tool_How to set disk high temperature alarm with CrystalDiskInfo hard disk detection tool

Revealed secrets of cell phone format recovery methods (mobile phone malfunction? Don't worry)

How to forcefully restore your phone to factory settings (detailed steps will teach you how to quickly restore your phone to its original state)