How to read multiple Integer input in a single line ? and Android Studio Getting Thumbnail to a Video using Glide in a Recyclerview | Java and Python | Know About

READ MULTIPLE INTEGERS IN A SINGLE LINE

If you are searching for how to read multiple Integer inputs in a single line without getting any errors then you are in the write place. In this article we are gonna see how to read multiple Integer inputs in two different programming languages (Java and Python).


JAVA

If you are familiar with Strings it will be easy for you to work with. I tried to split it without changing Integer to String in java but it doesn't work for me and then I searched it on stackoverflow and they said it can't be done. With the help of String Data type you can read Multiple Input values in a single line after getting inputs you can convert it to Integer values.

Example: Reading only two values in a single line


You can use the above while reading a lesser number of inputs, this code will be useful when you are getting fewer than 5 numbers in a single line. If you want to read multiple integers based on end users numbers you can follow the below one.

Example: Multiple Integer Input values in Single Line


Output

In the above program you can give N number of Integer values to read in a Single Line.

It will add those Integer Inputs and give you an output.

Java split method is used to split String into Substrings.

Java parseInt method is used to convert a String to an Integer.

Instead of using the above one you can also use the below code to read Multiple Integer Input in a single line to reduce the number of lines while coding.

Example: Reading Multiple Integer Input in a single line




PYTHON

In python you can easily do it with the help of split method. It can take multiple values in one line and it breaks the given input when the given separator is specified. If separator is not specified, then any white space is a separator.

Example: Multiple Integer Input values in Single Line


Output



Conclusion

In the end it is easy with python when compared to java, python has more features like this. You may have a doubt, then why are so many people still using java? Java has its own features like it is still used for its security reasons and it is also a platform independent language and for many more reasons. Like this every Programming Language has its own pros and cons.



ANDROID STUDIO GETTING THUMBNAIL

Activity

Assume that you're having 3 Activities named as MainActivity, Adapter Class and Model Class. In the Main Class you're going to check whether the Storage Permission is granted or not and link MainActivity with RecyclerView layout. You've to use your Adapter Class to set details about the Video like Name, Duration, Information, Thumbnail, etc. And You're going to use Model Class to Store and Retrieve data for the Video and in other words it is going to hold data.


How do I get Thumbnail form a Video ? Using URI(Uniform Resource Locator).

Main Activity

Get Video's Uri using External Content Uri from Media Storage. And Inside Cursor you've to fetch Url and Thumbnail for every separate Video from Model Class.



Adapter Class

In order to use Glide in your Application you've to implement latest dependencies version in Gradle build path like this:



By Extending Adapter Class to Recycler View you're going to get Videos Uri from Model Class.



Model Class

And in the Model Class you're to return values for methods created in both MainActivity and Adapter Class.





Here is the link for Google KickStart Round A 2020 Plates problem using Java.

0 Comments