Download Snow Day Homework on 2/3/14 You have to try these problems at

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
Snow Day Homework on 2/3/14
You have to try these problems at home today. We will go over these problems in class
tomorrow. I would assign a graded homework tomorrow that is similar to these problems.
1) Consider the following string
String str = “Yellowstone Park”;
a)Write code to find the length of this string?
b)String bit = str.substring(13);
What is the value stored in bit?
c)String temp = str.substring(0,6);
What is the value stored in temp?
d)char s = str.sharAt(5);
What is the value of s?
i) “o”
ii) ‘o’
iii) “w”
iv)’w’
e)Give a call to the substring method that returns the substring “Park”
f) Give a call to the substring method that returns the substring “stone”
g)Write code to convert Yellowstone Park” to all uppercase
2)What does the following statement sequence print?
String str = "Java Is Good";
int n = str.length();
String mystery = str.substring(n - 4, n) +
str.charAt(4) + str.substring(0, 4);
System.out.println(mystery);
a) Java
b) Good Java
c) Good
d) Is Good
3) Which of the following is the correct syntax for an if statement?
a)
if (x < 10) { size = "Small"; }
else (x < 20) { size = "Medium"; }
b)
if (x < 10); { size = "Small"; }
else (x < 20) { size = "Medium"; }
c)
if (x < 10) { size = "Small"; }
else { size = "Medium"; }
d)
if { size = "Small"; }
else (x < 20) { size = "Medium"; }
4) Assuming that the user provides 303 as input, what is the output of the following code
snippet?
int x;
int y;
x = 0;
Scanner in = new Scanner(System.in);
System.out.print("Please enter a number: ");
y = in.nextInt();
if (y > 300)
{
x = y;
}
else
{
x = 0;
}
System.out.println("x: " + x);
a) x: 0
b) x: 300
c) x: 303
d) There is no output due to compilation errors.
5) Assuming that a user enters 15 as input, what is the output of the following code snippet?
Scanner in = new Scanner(System.in);
System.out.print("Please enter a number: ");
int number = in.nextInt();
if (number > 20)
{
System.out.println("The number is LARGE!");
}
else
{
System.out.println("The number is SMALL!");
}
a)
There is no output due to compilation errors.
b)
The number is LARGE!
c)
The number is SMALL!
d)
The number is LARGE!
The number is SMALL!