Talk:Java (programming language): Difference between revisions

Content deleted Content added
m Reverted edits by 85.0.140.172 (talk) to last version by Jochem van Hees
Array: new section
Tags: Reverted Mobile edit Mobile web edit
Line 97:
[[File:Information.svg|30px]]
A discussion is taking place to address the redirect [[:Java Programming Language language]]. The discussion will occur at [[Wikipedia:Redirects for discussion/Log/2021 March 15#Java Programming Language language]] until a consensus is reached, and readers of this page are welcome to contribute to the discussion. <!-- from Template:RFDNote --> - '''[[User:Champion|<big>C</big><small>HAMPION</small>]]''' <sup>([[User_talk:Champion#Top|talk]]) ([[Special:Contributions/Champion|contributions]]) ([[Special:Logs/Champion|logs]]) </sup> 23:17, 15 March 2021 (UTC)
 
== Array ==
 
import java.util.Arrays;
import java.util.Scanner;
 
public class Main {
   public static void main(String args[]) {
      int[] myArray = {897, 56, 78, 90, 12, 123, 75};
      System.out.println("Elements in the array are:: ");
      System.out.println(Arrays.toString(myArray));
      Scanner sc = new Scanner(System.in);
      System.out.println("Enter the index of the required element ::");
      try {
         int element = sc.nextInt();
         System.out.println("Element in the given index is :: "+myArray[element]);
      } catch(ArrayIndexOutOfBoundsException e) {
         System.out.println("The index you have entered is invalid");
         System.out.println("Please enter an index number between 0 and 6");
      }
   }
} [[Special:Contributions/2402:8100:300F:3E83:1:2:44C0:DD64|2402:8100:300F:3E83:1:2:44C0:DD64]] ([[User talk:2402:8100:300F:3E83:1:2:44C0:DD64|talk]]) 02:07, 25 March 2022 (UTC)