• Shuffle
    Toggle On
    Toggle Off
  • Alphabetize
    Toggle On
    Toggle Off
  • Front First
    Toggle On
    Toggle Off
  • Both Sides
    Toggle On
    Toggle Off
  • Read
    Toggle On
    Toggle Off
Reading...
Front

Card Range To Study

through

image

Play button

image

Play button

image

Progress

1/56

Click to flip

Use LEFT and RIGHT arrow keys to navigate between flashcards;

Use UP and DOWN arrow keys to flip the card;

H to show hint;

A reads text to speech;

56 Cards in this Set

  • Front
  • Back

9 trig methods in the Math class

Math.sin(radians)


cos(radians)


tan(radians)


asin(radians) //arcsin


acos(radians)


atan(radians)


toRadians(degrees)


toDegrees(radians)

5 exponent methods in the Math class

Math.exp(x); //returns e^x


log(x); //natural log of x


log10(x);


pow(a,b);


sqrt(x);

4 rounding methods in Math class

Math.ceil(x); //rounds up to nearest int. returned as double


Math.floor(x); //rounds down to nearest int. returned as double


rint(x); //rounds up to nearest int. if equally close, even is returned as double


round(x); // Returns (int)Math.floor(x + 0.5) if x is a float and returns (long)Math.floor(x + 0.5) if x is a double.

Syntax for min and max methods

Math.min(a,b);//returns min of these two


Math.max(a,b);

Logic to use Math.random() to generate a random number between a and b, excluding b

a + Math.random()*b



or a + (int)(Math.random())*b

encoding

mapping a character to its binary representation

Unicode and ASCII are ________ ________

encoding schemes

True or false: Unicode is 8 bits. ASCII is 16 bits and includes unicode

FALSE



Unicode is 16 bits and includes ASCII. ASCII is 8 bits

Range for unicode

\u0000 to \uFFFF

How can you easily get the preceding or subsequent Unicode character?

++ or --

Is \a a special character in Java?

no, but the others one I'm used to are

true or false: a char can be cast into any numeric data type

true! and the reverse is also true

Will this casting work?




byte b = '\uFFF4';




byte b = 'a';

no. It will not fit into one byte. it needs two bytes.




yes. that fits into a single byte

What is the value of i?




int i = '2' + '3';

i = 101;




'2' = 50


'3' = 51

True or false: you can compare chars using relational operators

true

7 methods in Character class


Character.isDigit(ch);


Character.isLetter(ch);


isLetterOrDigit(ch);


isLowerCase(ch);


isUpperCase(ch);


toLowerCase(ch);


toUpperCase(ch);

Character.isDigit(ch); //returns bool


Character.isLetter(ch);


isLetterOrDigit(ch);


isLowerCase(ch);


isUpperCase(ch);


toLowerCase(ch); //returns char


toUpperCase(ch);



String is not a primitive type. It is a _____ type

reference type




(the variable declared by a reference type references an object, which in this case is a string)

6 simple methods for String OBJECTS

length();


charAt(index);


concat(s1); //returns a new string that concatenates this string with s1


toUpperCase();


toLowerCase();


trim(); //trims whitspace on either side

These simple methods from String objects can only be invoked from a specific String instance so they are called _______ methods as opposed to ______ methods

instance




static


(Math uses static methods that don't require an object)

Does this code work?




"Welcome To Java".length();

yes. Java can treat that as a literal

Besides using s1.concat(s2) what's another way to concatenate two strings?

s3 = s1 + s2 + " hi!";

When using + to concatenate, what happens if one of the values is not a string?

It is turned into a string and treated as one

Difference between next() and nextLine() when reading strings from console

inputVar.next(); reads a string that ends with whitespace




inputVar.nextLine(); reads an entire line of text

What shouldn't nextLine() be used after nextInt(), nextDouble(), etc.?

You'll get an input error

How do you read a character from the console?

input.nextLine();




then use stringVar.charAt(0); to get the character

s1.equals(s2);


s1.equalsIgnoreCase(s2);


s1.compareTo(s2);


s1.compareToIgnoreCase(s2);


startsWith(prefix);


endsWith(suffix);


contains(s1);

equals(s1): true if s1 = s2


equalsIgnoreCase(s1): ignores case


compareTo(s1); returns int > 0, < 0, or = 0 to indicate whether >, <, =


compareToIgnoreCase(s1);


startsWith(prefix): true if starts w/ that prefix


endsWith(suffix): true if ends w/ that suffix


contains(s1): true if substring is in string

What does this do?




string1 == string2;

checks whether they refer to same object, not whether contents are the same

Can you use relational operators with strings in Java?

NO




Use .compareTo(s1)

Methods in the String class for obtaining substrings




substring(beginIndex);


substring(beginIndex, endIndex);

returns substring that begins w/ character at the specified starting index and extends until end of string ("hello there") starting at 2 --> ("lo there")




returns substring that begins w/ char at specific starting index and extends until ending index

Methods in the String class for obtaining substrings




index(ch);


indexOf(ch, fromIndex);


indexOf(s);


indexOf(s, fromIndex);

index(ch): returns indx of first occurence of char in string (-1 if not found)


indexOf(ch, fromIndex): starts at that indx


indexOf(s): returns indx of first occurence of substring


indexOf(s, fromIndex): starts at that index

Methods in the String class for obtaining substrings




lastIndexOf(ch);


lastIndexOf(ch, fromIndex);


lastIndexOf(s);


lastIndexOf(s, fromIndex);

lastIndexOf(ch): returns indx of last occrnce of char in string (-1 if not found)


lastIndexOf(ch, fromIndex): starts at that indx


lastIndexOf(s): returns indx of last occrnce of substring in string (-1 if not found)


lastIndexOf(s, fromIndex): starts at the indx

How do you convert a numeric string into an int or double?

Integer.parseInt(myIntString);


intString is something like 123 (int numeric string)




Double.parseDouble(myDoubleString);


doubleString is something like 123.45 (double numeric string)

If you try to convert a non-numeric string into a number, what happens?

runtime error

printf can be used with ____ ______ to format output

format specifiers

What is each part of this format specifier?




System.out.printf("%4.2f" + variable);

%: start of format specifier


4: field width


.2: precision


f: actual format specifier

Format Specifiers




%b


%c


%d


%e


%f


%s

%b boolean


%c char


%d decimal integer (e.g., 200)


%e scientific notation


%f floating-point number


%s string

System.out.printf("count is %d and amount is %f", count, amount);

count is a decimal integer


amount is a floating-point

%5c

field width is 5, so add 4 spaces before the 1 char

%10.2e

Output the floating-point item with width at least 10 including a decimal point, twodigits after the point and the exponent part. If the displayed number in scientificnotation has width less than 10, add spaces before the number.

By default, output is right-justified. How do you make it left-justified?

-




%-5.2f


%-10s

True or false: items have to exactly match format specifiers

true

% denotes format specifier. How do you output a literal % in the format string?

%%

ASCII Unicode positions


blank space

32


ASCII Unicode positions


0-9

48-57


ASCII Unicode positions


A-Z

65-90


ASCII Unicode positions


a-z

97-122

ASCII Unicode positions




Difference between uppercase letter and its lowercase counterpart

32

How do you convert a String object to a character array?
str.toCharArray();
How do you convert a character array back to a String object?

String.valueOf(charArrayName, starting position, number of letters)




can also use String object class


charArrayName = new String (charArrayName);




varName.toString();

How do you replace one character with another in a String?
.replace('E', 'Y')

How do you terminate a program?
System.exit(0);

for-loop in Java vs. C++

The C++ version will work, but Java prefers a test where it can use length


int [] arr = new int[];


for (int x=0; x





Arrays must be dynamically allocated in Java because they are created in the ____, not the _____

heap not stack

All methods in Math return type
double
cast to int if needed

Strings: compareTo


What does it return if they're equal? First is superior? First is inferior?

Equal: returns 0First is superior: returns positive numberFirst is inferior: returns negative number

Compare:




Scanner input = new Scanner(System.in);


(char)System.in.read();

both will read input. The 2nd expects you to enter a single character and returns an integral value, but we're casting to char