JAVA ARRAY EXAMPLE PDF



Similar documents
Preet raj Core Java and Databases CS4PR. Time Allotted: 3 Hours. Final Exam: Total Possible Points 75

System.out.println("\nEnter Product Number 1-5 (0 to stop and view summary) :

Sample CSE8A midterm Multiple Choice (circle one)

Introduction to Java

CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013

AP Computer Science Static Methods, Strings, User Input

AP Computer Science Java Mr. Clausen Program 9A, 9B

Scanner sc = new Scanner(System.in); // scanner for the keyboard. Scanner sc = new Scanner(System.in); // scanner for the keyboard

Building Java Programs

Topic 11 Scanner object, conditional execution

MIDTERM 1 REVIEW WRITING CODE POSSIBLE SOLUTION

Basics of Java Programming Input and the Scanner class

CSE 1223: Introduction to Computer Programming in Java Chapter 7 File I/O

IRA EXAMPLES. This topic has two examples showing the calculation of the future value an IRA (Individual Retirement Account).

Introduction to Programming

Building Java Programs

Install Java Development Kit (JDK) 1.8

Introduction to Object-Oriented Programming

(Eng. Hayam Reda Seireg) Sheet Java

CS 121 Intro to Programming:Java - Lecture 11 Announcements

Chapter 2 Introduction to Java programming

Data Structures Lecture 1

Using Two-Dimensional Arrays

Building Java Programs

J a v a Quiz (Unit 3, Test 0 Practice)

Using Files as Input/Output in Java 5.0 Applications

JDK 1.5 Updates for Introduction to Java Programming with SUN ONE Studio 4

You are to simulate the process by making a record of the balls chosen, in the sequence in which they are chosen. Typical output for a run would be:

1) Which of the following is a constant, according to Java naming conventions? a. PI b. Test c. x d. radius

Part I. Multiple Choice Questions (2 points each):

Translating to Java. Translation. Input. Many Level Translations. read, get, input, ask, request. Requirements Design Algorithm Java Machine Language

Building Java Programs

COSC Introduction to Computer Science I Section A, Summer Question Out of Mark A Total 16. B-1 7 B-2 4 B-3 4 B-4 4 B Total 19

Object-Oriented Programming in Java

The following program is aiming to extract from a simple text file an analysis of the content such as:

Introduction to Java. CS 3: Computer Programming in Java

Comp 248 Introduction to Programming

CSE 1223: Introduction to Computer Programming in Java Chapter 2 Java Fundamentals

CS170 Lab 11 Abstract Data Types & Objects

Handout 1. Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner.

Arrays in Java. Working with Arrays

Assignment No.3. /*-- Program for addition of two numbers using C++ --*/

Visit us at

More on Objects and Classes

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.

Chulalongkorn University International School of Engineering Department of Computer Engineering Computer Programming Lab.

Chapter 2: Elements of Java

Classes and Objects in Java Constructors. In creating objects of the type Fraction, we have used statements similar to the following:

Homework/Program #5 Solutions

Masters programmes in Computer Science and Information Systems. Object-Oriented Design and Programming. Sample module entry test xxth December 2013

Chapter 3. Input and output. 3.1 The System class

qwertyuiopasdfghjklzxcvbnmqwerty uiopasdfghjklzxcvbnmqwertyuiopasd fghjklzxcvbnmqwertyuiopasdfghjklzx cvbnmqwertyuiopasdfghjklzxcvbnmq

Course Intro Instructor Intro Java Intro, Continued

CSE 8B Midterm Fall 2015

D06 PROGRAMMING with JAVA

LOOPS CHAPTER CHAPTER GOALS

Programming Fundamentals I CS 110, Central Washington University. November 2015

First Java Programs. V. Paúl Pauca. CSC 111D Fall, Department of Computer Science Wake Forest University. Introduction to Computer Science

java.util.scanner Here are some of the many features of Scanner objects. Some Features of java.util.scanner

Chapter 2. println Versus print. Formatting Output withprintf. System.out.println for console output. console output. Console Input and Output

Software Development with UML and Java 2 SDJ I2, Spring 2010

Scanner. It takes input and splits it into a sequence of tokens. A token is a group of characters which form some unit.

Interactive Applications (CLI) and Math

6.1. Example: A Tip Calculator 6-1

13 File Output and Input

Handout 3 cs180 - Programming Fundamentals Spring 15 Page 1 of 6. Handout 3. Strings and String Class. Input/Output with JOptionPane.

AP Computer Science File Input with Scanner

File class in Java. Scanner reminder. Files 10/19/2012. File Input and Output (Savitch, Chapter 10)

Programmierpraktikum

CSE373: Data Structures and Algorithms Lecture 3: Math Review; Algorithm Analysis. Linda Shapiro Winter 2015

Introduction to Java Applications Pearson Education, Inc. All rights reserved.

Chapter 20 Streams and Binary Input/Output. Big Java Early Objects by Cay Horstmann Copyright 2014 by John Wiley & Sons. All rights reserved.

For live Java EE training, please see training courses

Arrays. Atul Prakash Readings: Chapter 10, Downey Sun s Java tutorial on Arrays:

CompSci 125 Lecture 08. Chapter 5: Conditional Statements Chapter 4: return Statement

This explanations are for absolute beginners. Skilled programmers should (and probably will) use more effective approach.

Week 1: Review of Java Programming Basics

Arrays. Introduction. Chapter 7

Building Java Programs

Chapter 2 Elementary Programming

Creating a Simple, Multithreaded Chat System with Java

D06 PROGRAMMING with JAVA

1.4 Arrays Introduction to Programming in Java: An Interdisciplinary Approach Robert Sedgewick and Kevin Wayne Copyright /6/11 12:33 PM!

Object Oriented Software Design

Example of a Java program

5.2 Q2 The control variable of a counter-controlled loop should be declared as: a.int. b.float. c.double. d.any of the above. ANS: a. int.

Java 進 階 程 式 設 計 03/14~03/21

Some Scanner Class Methods

D06 PROGRAMMING with JAVA

1. Use the class definition above to circle and identify the parts of code from the list given in parts a j.

Line-based file processing

WA2099 Introduction to Java using RAD 8.0 EVALUATION ONLY. Student Labs. Web Age Solutions Inc.

Cohort: BCA/07B/PT - BCA/06/PT - BCNS/06/FT - BCNS/05/FT - BIS/06/FT - BIS/05/FT - BSE/05/FT - BSE/04/PT-BSE/06/FT

CS1020 Data Structures and Algorithms I Lecture Note #1. Introduction to Java

AP Computer Science Java Subset

Third AP Edition. Object-Oriented Programming and Data Structures. Maria Litvin. Gary Litvin. Phillips Academy, Andover, Massachusetts

Explain the relationship between a class and an object. Which is general and which is specific?

CMSC 202H. ArrayList, Multidimensional Arrays

CS 112/ Section 02 Hilal Ünal Aslıhan Ekim Merve Özkılınç Notes of March 11, 2008 and March 13, 2008: Pig Latin: add adday. main.

Transcription:

JAVA ARRAY EXAMPLE PDF Created By: Umar Farooque Khan 1

Java array example for interview pdf Program No: 01 Print Java Array Example using for loop package ptutorial; public class PrintArray { public static void main(string[] args) { int z[]=new int[5]; //declaration z[0]=152; z[1]=120; //initialization z[2]=12; z[3]=10; z[4]=258;//printing array through loop for(int l=0;l<z.length;l++){ System.out.println(z[l]); System.out.println("Length of array = " + z.length); 2

OUTPUT 152 120 12 10 258 Length of array = 5 Note: Please visit website http://www.ptutorial.com for more java array example and java array example for interview. 3

Program No: 02 Print Java array using for each loop Example package ptutorial; class PrintArray1{ public static void main(string s[]){ int z[]={07,38,17,9; for(int i=0;i<z.length;i++) System.out.println(z[i]); 7 38 17 9 OUTPUT 4

User Define Java Array Example Program No: 03 //user define java program to print array package arrayexample; import java.util.scanner; public class ArrayUser { static int n; public static void main(string[] args) { Scanner uk = new Scanner(System.in); System.out.println("Enter the number of element"); n = uk.nextint(); int x[] = new int[n]; System.out.println("Enter "+ n +" numbers"); for(int l=0;l<x.length;l++){ x[l]= uk.nextint(); System.out.println("OuTput:"); System.out.println("Entered numbers are :"); for(int l=0;l<x.length;l++){ System.out.println(x[l]); 5

OUTPUT Enter the number of element 4 Enter 4 numbers 12 38 07 89 OuTput: Entered numbers are : 12 38 7 89 6

Java Sum Of Array Example Program No: 04 package ptutorial; public class SumArray { public static void main(string[] s) { // number is a array variable int[] number = new int[]{ 20, 10, 20, 10, 20; int sum = 0; for (int i=0; i < number.length ; i++) { sum = sum + number[i]; System.out.println("Total value of array : " + sum); OUTPUT Total value of array : 80 7

Java Addition Of Two Array Program No: 05 import java.util.scanner; public class AddTwoArray { public static void input1(int[] b){ Scanner uk=new Scanner(System.in); System.out.println("Enter 2 numbers"); for(int l=0;l&b.length;l++){ b[l]= uk.nextint(); public static void input2(int[] d){ Scanner uk=new Scanner(System.in); System.out.println("Enter 2 numbers"); for(int l=0;l&d.length;l++){ d[l]= uk.nextint(); public static void add(int[] p,int[] k){ System.out.println("Sum of array:"); for(int l=0;l&p.length;l++){ p[l]=p[l]+k[l]; System.out.println(p[l]); public static void main(string[] args) { int x[]=new int[2]; int z[]=new int[2]; AddTwoArray.input2(x); AddTwoArray.input1(z); AddTwoArray.add(z,x); 8

OUTPUT Enter 2 numbers 2 2 Enter 2 numbers 2 2 Sum of array: 4 4 9

Program No: 06 Java Example Program To Print Lower Triangular Matrix //java program to access lower half array element class TringleExample{ public static void main(string... z){ max(new int[][] {{1,2,3,{4,5,6,{7,8,9); static void max(int d[][]){ for(int i=0;i<d.length;i++){ for(int j=0;j<d[i].length;j++) { if(j==i+1) { break; System.out.print(d[i][j]+"\t"); System.out.println("\t"); OUTPUT 1 4 5 7 8 9 10

Java Linear Search Example Program No: 07 import java.util.scanner; public class JavaAraySearch { public static void main(string args[]) { int k, n, temp, num[]; Scanner in = new Scanner(System.in); System.out.println("Enter the array size"); n = in.nextint(); num = new int[n]; System.out.println("Enter " + n + " numbers"); for (k = 0; k < n; k++) num[k] = in.nextint(); System.out.println("Enter integer to search"); temp = in.nextint(); for (k = 0; k < n; k++) { if (num[k] == temp) { System.out.println(temp + " is present at index " + (k + 1) + "."); break; if (k == n) System.out.println(temp + " is not present in the array."); 11

OUTPUT Enter the array size 3 Enter 3 numbers 3 5 8 Enter integer to search 5 5 is present at index 2. 12

Print Diagonal Matrix Java Example Program No: 08 public class PrintDiagonalMatrix { public static void main(string[] args ){ int sum=0; int a3[][]={{1,2,3,4,{10,20,30,40,{100,200,300,40,{1,2,0,4; for(int j=0;j<a3.length;j++){ System.out.println(a3[j][j]); OUTPUT 1 20 300 4 Note: Please visit website http://www.ptutorial.com for more java string example and explanations. 13

If you ever think a java array example is not explained clearly or think we should add a specific java array example suggest me at info@ptutorial.com. We will add String example as soon as possible for better experience. Java Array Example for Interview PDF 14