Java Program to Find Smallest and Largest Element in an Array

import java.util.Scanner; //import Scanner class in our program class demo { public static void main(String…s) { int i,n,large,small; Scanner sc=new Scanner(System.in); //used to read from keyboard System.out.print(“Enter number of elements:”); n=sc.nextInt(); int a[]=new int[n]; System.out.print(“nEnter elements of Array:”); for(i=0;i<n;++i) a[i]=sc.nextInt(); large=small=a[0]; for(i=1;i<n;++i) { if(a[i]>large) large=a[i]; if(a[i]<small) small=a[i]; } System.out.print(“nSmallest Element:”+small); System.out.println(“nLargest Element:”+large); } }

Difference between Compiler and Interpreter

In this tutorial you will learn about difference between compiler and interpreter i.e. compiler vs interpreter. We know that computers can only understand machine language which is in binary format. But we write in natural programming language (like C, Java etc). So there must be something which converts these programming instructions into machine understandable instructions. …

Difference between Compiler and Interpreter Read More »

this Keyword in Java

this holds the reference of current object. Observe below example: class demo {                 int  x=10;                 void show(int x,demo d1)                 {                                 System.out.println(this.x);                                 System.out.println(d1.x);                                 System.out.println(x);                 }                 public static void main(String…s)                 {                                 demo d1=new demo();                                 d1.show(20,d1);                 } } Output: 10 10 20 In Java by default …

this Keyword in Java Read More »