APCS Unit 1 (Lessons 1-7)

Ace your homework & exams now with Quizwiz!

Gettysburg address

What will be the value of c: String c; String m= "The Gettysburg address"; c = m.substring(4);

int

a variable used for integers (whole numbers)

double

a variable used for numbers with decimals

String

a variable used for text

method

basically, a recipe on how you want to run your program

run

computer takes the bytecode and executes the program

decrement

decrease by one

count -= 10;

decrease the variable count by 10 using a compound operator.

class

everything in Java has to start with a ____.

length method (variableName.length();)

finds the number of characters in a String

initialize

give the variable a value

j++ j = j + 1 j += 1

give three ways you can write a code to increment integer j by 1.

modulus

gives you the remainder (%)

PEMDAS

in Java, you obey the laws of ____.

IDE (integrated development environment)

in order to actually write a program you need an ___.

increment

increase by one

count +=5

increase the variable count by 5 using a compound operator.

legal

is the following variable name legal or illegal: Double dist = 1003;

illegal

is the following variable name legal or illegal: int alt = 1493.86;

legal

is the following variable name legal or illegal: int num = 1_2_3

...

know this chart

concatenation

merge text together using a +

pick a letter to relates to your variable (int i). capitalize the second word and keep the first word lowercase (largeArea, missSpaunhorst). if you're using the underscore, don't capitalize the second word (miss_spaunhorst).

name some of the traditional ways to name variables.

must start with a letter (s, bean, d72). cannot use spaces (but you can use underscores; miss_Spaunhorst). the only punctuation you can use is an underscore. they cannot be key words (static, int, etc.).

name the rules for variable names.

method

once you are inside your class, the first thing that you need to make is a ____.

substring method (variableName.substring(integer);)

picks a piece of a string - starts at assigned index

String s1 = "Allan Alda"; String s2 = "John Wayne"; String s3 = "Gregory Peck"; String ps1 = s1.substring(2, 7); String ps2 = s2.substring(2, 7); String ps3 = s3.substring(2, 9); System.out.println(s1 + ">>>" + ps1); System.out.println(s2 + ">>>" + ps2); System.out.println(s3 + ">>>" + ps3);

produce the following printout: Allan Alda>>>lan A John Wayne>>>hn Wa Gregory Peck>>>egory P hint - begin your code within the main method as follows. apply the length and substring methods to these Strings to produce the above printout. String s1 = "Allan Alda"; String s2 = "John Wayne"; String s3 = "Gregory Peck";

declare

set a variable as a variable type

compile

successful translation of code into computer language (bytecode)

anything that you write has to go in between those two brackets. anything that is in those brackets is your class. if something is not within those brackets it is not in your class and you cannot use it.

there is a bracket at the end of the public class. what does this do and mean?

int, double, and String

what are the three variables that we focus on?

Eclipse

what environment are we using?

--count ++count Note that this calculates in that line while count -- and count ++ does the calculation on the next line.

what is another way of saying count -- and count ++

Fire Ants

what is printed with the following code: System.out.print("Fire"); System.out.println(" Ants");

nothing is printed because there is an error. you assigned a number with a decimal to an int variable. if you want the code to print 17.87, you would need to make the variable a double.

what is printed with the following code: int cost = 17.87; System.out.println(cost);

1992.37

what is printed with the following code: double def; double f = 1992.37; def = f; System.out.println(def);

3

what is printed with the following code: int a = 100; int b = 200; b /= a; System.out.println(b+1);

109 104

what is printed with the following code: int h = 103; int p = 5; System.out.println(++h +p); System.out.println(h);

\t

what is the escape sequence for tab?

it looks for a method called main. if it doesn't have main, it has no idea where to start.

what is the first thing that your computer does when it runs a Java program?

Bass

what is the output by the following: String pq = "Chuck Bass"; int hm = pq.length(); String ed = pq.substring(hm-4); System.out.println(ed);

JABBA THE HUTT

what is the output of System.out.println(p.toUpperCase()); if p="Jabba the Hutt"?

public class Tester { public static void main(String args[ ]) { } }

what is the skeleton that we will use for nearly every project?

//

what is the syntax for indicated that a line of text is not Java code; rather it is a remark or comment?

you need to write your skeleton.

what is the very first thing that you have to do when you are writing a program?

nothing is wrong

what is wrong with the following "skeleton" of a Java program: public class MyClass { public static void main(String args[]) { { }

double

what type of variable would you use to store the square root of 2?

int

what type of variable would you use to store your age?

String

what type of variable would you use to store your name?

17

what will be that value of count: int count; String s = "Programs complete"; count = s.length();

ore a

what will be the value of c: String b = "Four score and seven years ago,"; String c = b.substring(7, 12);

n

which character is at the 5th index in the String "Herman Munster

Scooter 13 and doubled

which of the following are legal variable names: Scooter13 139_scooter homer-5 ;mary public ab c doubled

groovyDude and groovy_dude

which of the following is the most acceptable way of naming a variable: GroovyDude GROOVYDUDE groovyDude Groovydude groovy_dude groovydude

String s = "The number of rabbits is", report; int argh = 129; report = s + " " + argh + "."; System.out.println(report);

write a code in which a String variable s contains "The number of rabbits is". an integer variable argh has a value of 129. concatenate these variables into a String called report. then print report. the printout should yield: The number of rabbits is 129.

double p, j; j = 8.426; p = j; System.out.println(p); this will print: 8.426

write a code that stores 8.426 into a double variable named j. then, assign the value of j to p and print p. what will be printed?

int x = 0; System.out.println(++x);

write a code that stores the value 0 in an integer variable named x and then prints it while incrementing it.

String s = "Avengers Assemble!"; System.out.println(s);

write a code that uses a variable to print (name the variable s): Avengers Assemble!

String firstName, lastName, fullName; firstName = "Hannah "; lastName = "Padgette"; fullName = firstName + lastName; System.out.println(fullName); System.out.println(fullName.length()); this will print: Hannah Padgette 15

write a code that will concatenate your name into one variable and then print it and then count the number of characters in your name and print it. what will be printed?

String firstName, lastName, fullName; firstName = "Hannah "; lastName = "Padgette"; fullName = firstName + lastName; System.out.println(fullName); this will print: Hannah Padgette

write a code that will concatenate your name into one variable and then print it. what will be printed?

String m = "Look here!"; System.out.println("\"" + m + "\"" + " has " + m.length() + " characters.");

write a code that will look at the number of characters in String m = "Look here!"; and then print: "Look here!" has 10 characters.

System.out.println("25/5 is "); System.out.println(25/5);

write a code that will print: 25/5 is 5

System.out.print("25/5 is "); System.out.println(25/5);

write a code that will print: 25/5 is 5

System.out.println("From: Bill Smith"); System.out.println("Address: Dell Computer, Bldg 13"); System.out.println("Date: April 12, 2005"); System.out.println(" "); System.out.println("To: Jack Jones"); System.out.println(" "); System.out.println("Message: Help! I'm trapped inside a computer!");

write a code that will print: From: Bill Smith Address: Dell Computer, Bldg 13 Date: April 12, 2005 To: Jack Jones Message: Help! I'm trapped inside a computer!

System.out.println("Hello.\nHello again.");

write a code that will produce the following printout using only a single println(): Hello. Hello again.

double x = 2%3; System.out.println(x) this will print: 2.0

write a code that will store 2 modulus 3 in a double variable named x and then print it. what will be printed?

String quote = "Did you just say \"no\"?"; System.out.println(quote); this will print: Did you just say "no"?

write a code that will store Did you just say "no"? in a String variable named quote and then print it. what will be printed?

String donut = "How many donuts did you eat? "; int sad = 5; System.out.println(donut + sad); this will print: How many donuts did you eat? 5

write a code that will store How many donuts did you eat? in a String variable named donut and concatenate is with an integer variable named sad that is 5. what will be printed?

String jedi = "Obi-Wan Kenobi"; String part = jedi.substring(4); System.out.println(part); this will print: Wan Kenobi

write a code that will store the name Obi-Wan Kenobi in a String variable and then create a variable named part that will count from the 4th character on and then print it. what will be printed?

String jedi = "Obi-Wan Kenobi"; String part = jedi.substring(4, 10); System.out.println(part); this will print: Wan Ke

write a code that will store the name Obi-Wan Kenobi in a String variable and then create a variable named part that will count from the 4th character on and then stop at character 10 and then print it. what will be printed?

String jedi = "Obi-Wan Kenobi"; System.out.println(jedi.toUpperCase()); this will print: OBI-WAN KENOBI

write a code that will store the name Obi-Wan Kenobi in a String variable and then print it in all caps. what will be printed?

String jedi = "Obi-Wan Kenobi"; System.out.println(jedi.toLowerCase()); this will print: obi-wan kenobi

write a code that will store the name Obi-Wan Kenobi in a String variable and then print it in all lower case. what will be printed?

int count = 15; count = count + 5; System.out.println(count); this will print: 20

write a code that will store the value 15 in an int variable named count and then increase it by 5 and print it. what will be printed?

int count = 15; count = count + 5; count = count - 10; System.out.println(count); this will print: 10

write a code that will store the value 15 in an int variable named count and then increase it by 5, decreaseit by 10, and print it. what will be printed?

int i = 79 + 3 * (4 + 82 - 68) - 7 + 19; int j = (179+21+10) / 7 + 181; int k = 10389 * 56 * 11 + 2246; System.out.println("79 + 3 * (4 + 82 - 68) - 7 + 19" + " = " + i); System.out.println("(179 + 21 + 10) / 7 + 181" + " = " + j); System.out.println("10389 * 56 * 11 + 2246" + " = " + k);

write a code thatwill calculate and print the results of the following arithmetic problems: 79 + 3 * (4 + 82 -68) - 7 +19 (179 +21 +10) / 7 + 181 10389 * 56 * 11 + 2246 The printout should look like the following: 79 + 3 * (4 + 82 - 68) - 7 + 19 = 145 (179 + 21 + 10) / 7 + 181 = 211 10389 * 56 * 11 + 2246 = 6401870

double cost; cost = 1.52E80; System.out.println(cost);

write a line of code that declare and initializes on separate lines and prints the following (name the variable cost): 1.52E80

bankBalance = 136.05;

write a line of code that initializes the double precision variable bankBalance to 136.05. Assume this variable has already been declared.

double p = 3, q = 4; p += q; System.out.println(p); this prints: 7.0

write a line of code that stores the value of 3 in the double variable p and the value of 4 in the double variable q. then, use a compound operator to add q to p. what will be printed?

double p = 3, q = 4; p /= q; System.out.println(p); this prints: 0.75

write a line of code that stores the value of 3 in the double variable p and the value of 4 in the double variable q. then, use a compound operator to divide p by q. what will be printed?

double p = 3, q = 4; p %= q; System.out.println(p); this prints: 3.0

write a line of code that stores the value of 3 in the double variable p and the value of 4 in the double variable q. then, use a compound operator to do p%q. what will be printed?

double p = 3, q = 4; p *= q; System.out.println(p); this prints: 12.0

write a line of code that stores the value of 3 in the double variable p and the value of 4 in the double variable q. then, use a compound operator to multiply p and q. what will be printed?

double p = 3, q = 4; p -= q; System.out.println(p); this prints: -1.0

write a line of code that stores the value of 3 in the double variable p and the value of 4 in the double variable q. then, use a compound operator to subtract q from p. what will be printed?

double p = 3, q = 4; p--; System.out.println(p); this prints: 2.0

write a line of code that stores the value of 3 in the double variable p. then, decrement p. what will be printed?

double p = 3, q = 4; p++; System.out.println(p); this prints: 4.0

write a line of code that stores the value of 3 in the double variable p. then, increment p. what will be printed?

double cost = 17.87; System.out.println(cost);

write a line of code that uses a variable to print (name that variable cost): 17.87

int i = 17; System.out.println(i);

write a line of code that uses a variable to print (name the variable i): 17

int count;

write a line of code that will declare the variable count to be of type int. don't initialize.

count --;

write a single line of code that decrements the variable count.

count ++;

write a single line of code that increments the variable count.

System.out.println("Here is one line\nHere is another"); this will print: Here is one line Here is another

write a single line of code that prints Here is one line Here is another in two separate lines. what will be printed?

int lion = 5, tiger = 3, bear;

write a single line of code that stores the value 5 in the int variable lion, the value 3 in the int variable tiger, and declares the int variable bear.

String my_name = "Hannah Padgette";

write a single line of code that will create a String variable called my_name and store your name in it.

double p = 1.921E-16;

write a single line of code that will create a double precision variable called p and store 1.921x10-16 in it.

int i = 407;

write a single line of code that will create an integer variable called i and store 407 in it.

System.out.println("Hello World!");

write a single line of code that will print : "Hello World!"

System.out.println(25/5); //this will print "5"

write a single line of code that will print the answer to the equation 25/5

System.out.println(zulu + " " + --zulu);

write a single line of code that will print the integer variable zulu and then decrement its value by 1.

String g = "Computer Science is my favorite class"; System.out.println(g.toLowerCase());

write code that will assign the value of "Computer Science is my favorite class" to the String variable g. then have it print this String with nothing but "small" letters.

+= (i +=3; adds 3 to i, or i = i 3) -= (x -= b - 2; subtracts (b - 2) from x, or x = x - (b-2) *= (z *= 46; multiplies 46 to z or z = z * 46) /= (p /= x - z; divides p by (x - z) or p = p/)=(x-z) %= (i %= 2; gives the remainder of i/2 or i = i%2)

write the syntax of the main operations that we will use (add, subtract, multiply, divide, and modulus.


Related study sets

Med Surg Quiz 2 -- Ch. 37, 38, 60, 61 Testbankgo questions

View Set

Chapter 35: Assessment of Immune Function Prep-U

View Set

POLI 190 Quiz #2 Study Guide: CH 7,8,10,12

View Set