CH 2- JAVA

¡Supera tus tareas y exámenes ahora con Quizwiz!

String firstString = "Carrington Harrod";

Define a String variable, -firstString-, with the value "Your Full Name."

String name; name = JOptionPane.showInputDialog("Enter your name."); -------Carrington Harrod JOptionPane.showMessageDialog(null, "Hello, + name); System.exit(0); causes the program to end

Display a message dialog box using the input method using your name

import javax.swing.JOptionPane; JOptionPane.showMessageDialog(null, "Hello World); Message- Hello World

Display a message dialog box using the output method

single line comment multi-line comment documentation comment

// symbol /*, */ symbol /** */ (can be read and processed by a program named javadoc)

char myChar = firstName.charAt(3) S.o.p( +myChar); the answer will be i

//ex of a char data type String firstName = "carrington"; give the java statement that will determine the 4th character of the String firstName and store into myChar

main method

every java application program must have _____________

x += 5; is equivalent to x=x+5 y-= 2; is equivalent to y = y-2 z*= 10; is equivalent to z = z*10 a /= b; is equivalent to a = a/b c %= 3; is equivalent to c = c%3

examples of combined assigned operators

byte = x; Scanner keyboard = new Scanner (System.in); S.o.p( "Enter a byte value"); x = keyboard.nextByte( ); int number; Scanner keyboard = new Scanner (System.in); S.o.p.("Enter an integer value"); number = keyboard.nextInt( ); String name; Scanner keyboard = new Scanner (System.in); S.o.p( "Enter your name"); name = keyboard.nextLine();

examples of the scanner class methods

littleNum = (short)bigNum; x = (long) 3.7; number = (int) 72.567 value = (float) x; value = (byte) number;

examples of using the cast operator

float number; number = 23.5F;

how to make a float compatible with a double

= 16

how to raise a number to a power in java Math.pow(4.0,2.0);

byte 1, short 2, int 4, long 8, float 4, double 8,

identify the 6 data types and their byte sizes

class header

java source file and the ______ must be the same except for the file extension

final

key word to declare a named constant that cannot be changed in the program

semicolon

marks the end of a statement in Java

variable

named storage location in the computer's memory

.java

names of the Java source code files end with

- (unary negation) * / % + - (lowest precedence)

place the arithmetic operators in order

identifier

programmer-defined name that represents some element of a program

method header

public static void main(String[ ] args)

Today we sold 20 bushels of apples

read what this statement will- int apples; apples = 20; S.o.p.("Today we sold " + apples + " bushels of apples.");

13 2 28 4 6

solve the expressions and their values 5+2*4 10/2-3 8+12*2-4 4+17%2-1 6-3*2+7-1

string concatenation operator

the + sign is known as the when used with strings

char

the _______ type is used to store characters

class definition

the class header (ex. public class Simple(name given) marks the beginning of the ______ ________

string literal

the group of characters inside the quotation marks-SOP("Programming is great fun!"); - is called a

literal

value that is written into the code of a program

true or false

what two variables does the boolean method hold

Programming is great fun! I can't get enough of it!

what will this statement print public class TwoLines { public static void main (String[ ] args) { S.o.pln("Programming is great fun!"); S.o.pln("I can't get enough of it!"); } }

key words

words that have special meaning in java programming

Scanner keyboard = new Scanner (System.in);

write a java statement to create a scanner object (placed inside of the main method)

String firstString = firstString.toUpperCase(); S.o.p( + firstString); CARRINGTON HARROD

Str firstString = "Carrington Harrod"; Give the java statement that will convert String, to all upper case storing result into result1

int stringSize; stringSize = firstString.length(); S.o.p (" The name 'Carrington Harrod' has ) + stringSize + " characters"); result = The name Carrington Harrod has 17 characters

String firstString = "Carrington Harrod"; give a java statement that will print out the length of a string in firstString and store the result into a variable stringSize

import java.util.Scanner;

Write a java statement to import the scanner class (this is placed before the class header

newline, tab

\n \t


Conjuntos de estudio relacionados

Ch. 12: The Endomembrane System and Peroxisomes

View Set

Greek Roots chron, meter, photo, bio, geo, logy

View Set

Nursing Fundamentals exam 3 practice test

View Set

Chapter 4 - Variable Costing and Segmenting Reporting

View Set

District of Columbia Department of Motor Vehicles -- Driver Manual Quiz

View Set

Ch. 11 Lesson 3 Moving Cellular Material

View Set