CS 180 Assignment 6 Arrays.

Slides:



Advertisements
Similar presentations
METHOD OVERRIDING Sub class can override the methods defined by the super class. Overridden Methods in the sub classes should have same name, same signature.
Advertisements

Arrays. What is an array An array is used to store a collection of data It is a collection of variables of the same type.
Java Intro. A First Java Program //The Hello, World! program in Java public class Hello { public static void main(String[] args) { System.out.println("Hello,
Smoking is prohibited 1 CS 101 Second Exam Review Prepared by Dr. Amer Al-Badarneh 
C Primer CAS CS210 Ying Ye Boston University. Outline Hello, world Basics in C Comparison of C and Java.
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
Session One Introduction. Personal Introduction Role of programmers Robot Examination HUD & HID Uploading Code.
Basic Java Programming CSCI 392 Week Two. Stuff that is the same as C++ for loops and while loops for (int i=0; i
Java Quiz Bowl A fun review of the Java you should know from CMPT 201 If you don’t know the answers - this week is for you to study up!
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
Chapter 2: Java Fundamentals
1 Variables. 2 Receipt example What's bad about the following code? public class Receipt { public static void main(String[] args) { // Calculate total.
Can we talk?. In Hello World we already saw how to do Standard Output. You simply use the command line System.out.println(“text”); There are different.
Session Three Review & Conditional Control Flow. Java File Hierarchy Projects Packages Classes Methods.
Chapter 8 Scope of variables Name reuse. Scope The region of program code where it is legal to reference (use) a variable The scope of a variable depends.
1 BUILDING JAVA PROGRAMS CHAPTER 2 PRIMITIVE DATA AND DEFINITE LOOPS.
F27SA1 Software Development 1 7. Java Programming 6 Greg Michaelson.
The assignment expressions. The assignment operator in an assignment statement We have seen the assignment statement: Effect: var = expr; Stores the value.
Java and C++ Transitioning. A simple example public class HelloWorldApp { public static void main(String[] args) { //Display the string. System.out.println("Hello.
 CSC111 Quick Revision. Problem Write a java code that read a string, then show a list of options to the user to select from them, where:  L to print.
© 2007 Lawrenceville Press Slide 1 Chapter 4 Review Assignment Statement An assignment statement gives a value to a variable. Assignment can take several.
Computer Science A 1. Course plan Introduction to programming Basic concepts of typical programming languages. Tools: compiler, editor, integrated editor,
Methods What is a method? Main Method the main method is where a stand alone Java program normally begins execution common compile error, trying.
COMP Inheritance and Polymorphism Yi Hong June 09, 2015.
Last Revision. Question1 Novice Java programmers often write code similar to, class C { public int x;... }... C[] a = new C[10]; for(int i = 0; i < a.length;
Methods. Creating your own methods Java allows you to create custom methods inside its main body. public class Test { // insert your own methods right.
Object Oriented Programming Lecture 2: BallWorld.
MT311 Java Application Development and Programming Languages Li Tak Sing( 李德成 )
CS 106 Introduction to Computer Science I 02 / 15 / 2008 Instructor: Michael Eckmann.
Primitive data types Lecture 03. Review of Last Lecture Write a program that prints the multiplication table of 5. class MultiplicationTable { public.
Introduction to java (class and object). Programming languages: –Easier to understand than CPU instructions –Needs to be translated for the CPU to understand.
Chapter 8 Arrays and the ArrayList Class Arrays of Objects.
Session Three Review & Conditional Control Flow. Java File Hierarchy Projects Packages Classes Methods.
Introduction to programming in java
Test 2 Review Outline.
CS 160 – Summer 16 Exam 1 Prep.
Suppose we want to print out the word MISSISSIPPI in big letters.
A Java Program: // Fig. 2.1: Welcome1.java // Text-printing program.
Class Structure 15-Jun-18.
CHAPTER 7 & 8 REVIEW QUESTIONS
Coming up Constructors Overloading With one parameter
Testing and Exceptions
CS Week 10 Jim Williams, PhD.
CS Week 8 Jim Williams, PhD.
Decision statements. - They can use logic to arrive at desired results
Yong Choi School of Business CSU, Bakersfield
CSC 113 Tutorial QUIZ I.
Manipulating Pictures, Arrays, and Loops part 5
An Introduction to Java – Part I, language basics
Week 6 CS 302 Jim Williams, PhD.
C Programming APP3o.
Exception Handling CSCI293 - C# October 3, 2005.
Exercise 11.1 Write a code fragment that performs the same function as the statement below without using the crash method Toolbox.crash(amount < 0,
Java Tutotrial for [NLP-AI] 2
Multidimensional Arrays
Assignment 7 User Defined Classes Part 2
Java Intro.
Sridhar Narayan Java Basics Sridhar Narayan
CS2011 Introduction to Programming I Arrays (I)
Seoul National University
Namespaces How Shall I Name Thee?.
Arrays.
Scope of variables class scopeofvars {
Arrays in Java.
Copyright © 2013 Elsevier Inc. All rights reserved.
Debugging Exercise 00 Try compiling the code samples.
LCC 6310 Computation as an Expressive Medium
Loops CGS3416 Spring 2019 Lecture 7.
Methods/Functions.
Introduction to java Part I By Shenglan Zhang.
Presentation transcript:

CS 180 Assignment 6 Arrays

Which is a legal array declaration or definition? int[] []x[]; int *x; int x[5]; int[] x = {1,2,3};

D. String[names.length-1 ] = "Hello" ; Which of the following statements puts a reference to the String "Hello" in the last slot of the array? String[] names = new String[10] ; A. names[0] = "Hello" ; B. names[10] = "Hello" ; C. names[9] = "Hello" ; D. String[names.length-1 ] = "Hello" ;

for(int i = 0; i < 3; i++) for(int j = 0; j < 3; j++) if(j = i) What will be the content of array variable table after executing the following code? for(int i = 0; i < 3; i++) for(int j = 0; j < 3; j++) if(j = i) table[i][j] = 1; else table[i][j] = 0; A. 0 0 0 0 0 0 B. 1 0 0 0 1 0 0 0 1 C. This code will result in compiler error D. This code will result in Run Time Exception

What will happen if you try to compile and run the following code? public class Q { public static void main(String argv[]){ int anar[]=new int[5]; System.out.println(anar[0]); } A. Error: anar is referenced before it is initialized B. null C. 0 D. 5 E. 1

A. for ( int j = 0; j < names.length; j++ ) Which of the following fragments prints out the slots of the array from last to first, skipping slots that contain null? A. for ( int j = 0; j < names.length; j++ ) if ( names[j] != null ) System.out.println( names[j] ); B. for ( int j = names.length; j < names.length; j++ ) C. for ( int j = names.length-1; j >= 0; j-- ) D. for ( int j = names.length; j >= 0; j++ )