- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 34494 Articles for Programming
452 Views
To avoid hard coding you can read the size of the array from the user using command line arguments of the reader classes like Scanner. Then using this value create an array:Exampleimport java.util.Arrays; import java.util.Scanner; public class PopulatingAnArray { public static void main(String args[]) { System.out.println("Enter the required size of the array :: "); Scanner s = new Scanner(System.in); int size = s.nextInt(); int myArray[] = new int [size]; System.out.println("Enter the elements of the array one by one "); for(int i=0; i
7K+ Views
To find the intersection of two arrays in java use two loops. The outer loop is to iterate the elements of the first array whereas, the second loop is to iterate the elements of the second array. Within the second loop compare the elements of the two arrays:ExampleLive Demopublic class IntersectionOfTwoArrays { public static void main(String args[]) { int myArray1[] = {23, 36, 96, 78, 55}; int myArray2[] = {78, 45, 19, 73, 55}; System.out.println("Intersection of the two arrays ::"); for(int i = 0; i
579 Views
While writing the name of the constants it is suggested to write all the letters in upper case. If constant contains more than one word they should be separated by underscore (_). Example Live Demo public class ConstantsTest { public static final int MIN_VALUE = 22; public static final int MAX_VALUE = 222; public static void main(String args[]) { System.out.println("Value of the constant MIN_VALUE: "+MIN_VALUE); System.out.println("Value of the constant MAX_VALUE: "+MAX_VALUE); } } Output Value of the constant MIN_VALUE: 22 Value of the constant MAX_VALUE: 222
6K+ Views
To read data from user create a scanner class. Read the size of the array to be created from the user using nextInt() method. Create an array with the specified size. In the loop read the values from the user and store in the array created above.Exampleimport java.util.Arrays; import java.util.Scanner; public class PopulatingAnArray { public static void main(String args[]) { System.out.println("Enter the required size of the array :: "); Scanner s = new Scanner(System.in); int size = s.nextInt(); int myArray[] = new int [size]; ... Read More
801 Views
While choosing a package name you need to keep the following points in mind. The name of the package should be in small letters. It is suggested to start the name of the package with the top level domain level followed by sub domains, ex: com.example.tutorialspoint. Example You can declare a package as in. package com.mypackage.tutorialspoint; Public class Sample { Public static void main(String args[]) { System.out.println("Welcome to Tutorialspoint"); } } Executing a package You need to compile the file with packages using –d ... Read More
614 Views
The openStream() method of the URL class opens a connection and returns an InputStream. Using this stream, you can you read contents from that connection.Exampleimport java.io.InputStream; import java.net.URL; import java.util.Scanner; public class ReadingURL { public static void main(String args[]) throws Exception { URL url = new URL("http://www.tutorialspoint.com/"); InputStream inputStream = url.openStream(); Scanner s = new Scanner(inputStream); while(s.hasNext()) { System.out.println(s.nextLine()); } } }OutputLearn CouchDB Learn DB2 Learn DocumentDB SQL Learn DocumentDB Learn DynamoDB Learn H2 Database Learn HSQLDB Learn IMS DB …………………………………………………………………………………………. ………………………………………………………………………………………………… ………………………………………………………………………………………………
543 Views
While writing an interface/class names you need to keep the following points in mind. First letter of the interface/class name should be capital and remaining letters should be small (mixed case). interface Sample Likewise, first letter of each word in the name should be capital an remaining letters should be small. interface MYInterface Keeping interface names simple and descriptive is suggestable. Better not to use acronyms while writing interface/class names. Example Live Demo interface MyInterface { void sample(); void demo(); } ... Read More
965 Views
Declaring a constructor is in Java is similar to methods. While naming the constructor of a class in Java you need to keep the following points in mind. The name of the constructor should be the same (same case) as the class name (along with the access specifier). A constructor should not have any return type. Constructor cannot be static, final, abstract and, synchronized. Example Following Java program is an example of a constructor. Live Demo public class Sample { Sample() { System.out.println("This is an example of ... Read More
20K+ Views
In Python, there are two ways to provide input information to a program. One in which we directly assign input objects to object references/variables; and the other in which the program takes user input dynamically (during runtime). Python 2.x versions use raw_input() function to take user input dynamically; whereas, Python 3.x versions use input() function. The input() function only takes input values in the form of strings, by default. In this article, we will learn how to read the input as “Numbers” in Python 3.x using input() function. Reading Inputs as Numbers Python, like any other programming languages, accepts two ... Read More