SlideShare a Scribd company logo
Review Questions for Exam
10/18//2016
1.
public class Question1
{
public static void main(String[ ] args)
{
System.out.print("Here");
System.out.println("There " + "Everywhere");
System.out.println("But not" + "in NJ");
}
}
Write the output after the above program is executed.
2. Consider the following statement:
System.out.println("1 big bad wolft8 the 3 little pigs 4 dinner 2night");
This statement will output ________ lines of text
A) 1
B) 2
C) 3
D) 4
E) 5
public class MyString
{
public static void main(String[] args)
{
System.out.print("1 big bad wolft8 the 3 little pigs 4 dinner 2 night");
}
}
3. The word println is a(n)
A) method
B) reserved word
C) variable
D) class
E) String
4. A Java variable is the name of a
5. What output is produced by the following?
System.out.println ("X: " + 25);
System.out.println ("Y: " + (15 + 50));
System.out.println ("Z: " + 300 + 50);
Of the following types, which one cannot store a numeric value?
6. What is output with the statement System.out.println(""+x+y); if x and y are int values
where x=10 and y=5?
public class MyString
{
public static void main(String[] args)
{
int x=10;
int y = 5;
System.out.println(""+x+y);
}
}
7. What happens if you attempt to use a variable before it has been initialized?
A. A syntax error may be generated by the compiler
B. A runtime error may occur during execution
C. A "garbage" or "uninitialized" value will be used in the computation
D. A value of zero is used if a variable has not been initialized
E. Answers A and B are correct
8. What is the function of the dot operator?
A. It serves to separate the integer portion from the fractional portion of a floating point number
B. It allows one to access the data within an object when given a reference to the object
C. It allows one to invoke a method within an object when given a reference to the object
D. It is used to terminate commands (much as a period terminates a sentence in English)
E. Both B and C are correct
9. Say you write a program that makes use of the Random class, but you fail to include an
import statement for java.util.Random (or java.util.*). What will happen when you attempt to
compile and run your program.
A. The program won't run, but it will compile with a warning about the missing class.
B. The program won't compile-you'll receive a syntax error about the missing class.
C. The program will compile, but you'll receive a warning about the missing class.
D. The program will encounter a runtime error when it attempts to access any member of the
Random class
E. none of the above
10. An API is
A. an Abstract Programming Interface
B. an Application Programmer's Interface
C. an Application Programming Interface
D. an Abstract Programmer's Interface
E. an Absolute Programming Interface
11. When executing a program, the processor reads each program instruction from
12. The main method for a Java program is defined by
13. What will be the result of the following assignment statement? Assume b = 5 and c = 10.
int a = b * (-c + 2) / 2;
public class MyString
{
public static void main(String[] args)
{
int b = 5;
int c = 10;
int a = b * (-c + 2) / 2;
System.out.println("a: "+a);
}
}
14. If the String major = "Computer Science", what is returned by major.charAt(1)?
public class MyString
{
public static void main(String[] args)
{
String major = "Computer Science";
System.out.println(major.charAt(1));
}
}
15. For the following questions, refer to the class defined below:
import java.util.Scanner;
public class Questions15
{
public static void main(String[ ] args)
{
int x, y, z;
double average;
Scanner scan = new Scanner(System.in);
System.out.println("Enter an integer value");
x = scan.nextInt( );
System.out.println("Enter another integer value");
y = scan.nextInt( );
System.out.println("Enter a third integer value");
z = scan.nextInt( );
average = (x + y + z) / 3;
System.out.println("The result of my calculation is " + average);
}
}
16. What is the output of the following program?
public class Precision
{
public static void main(String[] args)
{
int x=5;
int y =5;
int z = 3;
double average;
average = (x + y + z) / 3;
System.out.println("The result of my calculation is " + average);
}
}
ANS: ÏYour gross pay is $1000.0
17. What is the output of the following program?
public class Initialize
{
// This program shows variable initialization.
public static void main(String[] args)
{
int month = 2, days = 28;
System.out.println("Month " + month + " has " +
days + " days.");
}
}
18. What is the output of the following program?
public class Payroll
{
public static void main(String[] args)
{
int hours = 40;
double grossPay, payRate = 25.0;
grossPay = hours * payRate;
System.out.println("Your gross pay is $" + grossPay);
}
}
19.
import java.util.Scanner; // Needed for the Scanner class
/*
This program has a problem reading input.
*/
public class InputProblem
{
public static void main(String[] args)
{
String name; // To hold the user's name
int age; // To hold the user's age
double income; // To hold the user's income
// Create a Scanner object to read input.
Scanner keyboard = new Scanner(System.in);
// Get the user's age.
System.out.print("What is your age? ");
age = keyboard.nextInt();
// Get the user's income
System.out.print("What is your annual income? ");
income = keyboard.nextDouble();
// Get the user's name.
System.out.print("What is your name? ");
name = keyboard.nextLine();
// Display the information back to the user.
System.out.println("Hello " + name + ". Your age is " +
age + " and your income is $" +
income);
}
}
What is your age? 50
¼¼§ÏWhat is your annual income? 1000
ÏϧÏWhat is your name? Hello . Your age is 50 and your income is $1000.0
To fix the problem, add this line before the statement of System.out.print("What is your
name? ");
// Consume the remaining newline.
keyboard.nextLine();
20. What is the output of the following program?
// This program demonstrates the char data type.
public class Letters
{
public static void main(String[] args)
{
char letter;
letter = 'A';
System.out.println(letter);
letter = 'B';
System.out.println(letter);
}
}
21. Write an expression that produces a random integer in the following ranges:
Range
0 to 12
1 to 20
22.
public class MyString
{
//-----------------------------------------------------------------
// Prints a string and various mutations of it.
//-----------------------------------------------------------------
public static void main(String[] args)
{
String str1="Two";
System.out.println( str1 );
int count=str1.length();
System.out.println(count);
System.out.println( str1.length() );
String str3 = str1.substring(1,3);
System.out.println( str3 );
String str2= new String ("Three");
String str6= new String ("THREE");
boolean equalThree1 = str2.equals(str6);
boolean equalThree2 = str2.equalsIgnoreCase(str6);
String str4= str2.concat(" Four");
String str5=str2.replace('e', 'x');
System.out.println( str2 );
System.out.println( str4 );
System.out.println( str5 );
System.out.println( equalThree1 );
System.out.println( equalThree2 );
String str7="AB";
String str8="CD";
System.out.println( str7.compareTo(str8) );
System.out.println( str8.compareTo(str7) );
System.out.println (str7.charAt(0));
}
}
23.
Trace the execution of the following program assuming the input stream contains the numbers
10, 3, and 14.3. Use a table that shows the value of each variable at each step. Also show the
output (exactly as it would be printed).
// FILE: Trace.java
// PURPOSE: An exercise in tracing a program and understanding
// assignment statements and expressions.
import java.util.Scanner;
public class Trace
{
public static void main (String[] args)
{
int one, two, three; //line 1
double what; //line 2
Scanner scan = new Scanner(System.in); //line 3
System.out.print ("Enter two integers: "); //line 4
one = scan.nextInt(); //line 5
two = scan.nextInt(); //line 6
System.out.print("Enter a floating point number: "); //line 7
what = scan.nextDouble() ; //line 8
three = 4 * one + 5 * two; //line 9
two = 2 * one; //line 10
System.out.println ("one " + two + ":" + three); //line 11
one = 46 / 5 * 2 + 19 % 4; //line 12
three = one + two; //line 13
what = (what + 2.5) / 2 ; //line 14
System.out.println (what + " is what!"); //line 15
}
}
24. Write an application that reads values representing a time duration in hours, minutes, and
seconds and then prints the equalivant total number of seconds. (for example, 1 hour, 28 minutes
and 42 seconds is equivalent to 5322 seconds.)
Solution
Hi, Friend please do not post more than 5 questions in a single post.
Please find my answer for first 6 questions.
Please post other questions in other post.
1)
HereThere Everywhere
But notin NJ
Explanation:
System.out.println => peint the argument on TERMINAL
+ => concatenate two string OR one string and other is any data type
2)
Output:
1 big bad wolf 8 the 3 little pigs
4 dinner
2night
Line break with  and  character
Ans: 3
3)
println is a method of System class
Ans: ) method
4)
c.data value stored in memory that can not change its type during the program’s execution
5)
X: 25
Y: 65
Z: 30050
6)
Ans: 105
System.out.println(""+x+y); -=> ""+x = 10 that is string
10(string) + 5(int) => 105 (string)

More Related Content

Similar to Review Questions for Exam 10182016 1. public class .pdf

OXUS20 JAVA Programming Questions and Answers PART I
OXUS20 JAVA Programming Questions and Answers PART IOXUS20 JAVA Programming Questions and Answers PART I
OXUS20 JAVA Programming Questions and Answers PART I
Abdul Rahman Sherzad
 
Spring 2014 CSCI 111 Final exam of 1 61. (2 points) Fl.docx
Spring 2014 CSCI 111 Final exam   of 1 61. (2 points) Fl.docxSpring 2014 CSCI 111 Final exam   of 1 61. (2 points) Fl.docx
Spring 2014 CSCI 111 Final exam of 1 61. (2 points) Fl.docx
rafbolet0
 
Chapter i(introduction to java)
Chapter i(introduction to java)Chapter i(introduction to java)
Chapter i(introduction to java)
Chhom Karath
 
Lab01.pptx
Lab01.pptxLab01.pptx
Lab01.pptx
KimVeeL
 
Java doc Pr ITM2
Java doc Pr ITM2Java doc Pr ITM2
Java doc Pr ITM2
Aram Mohammed
 
programming for Calculator in java
programming for Calculator in javaprogramming for Calculator in java
programming for Calculator in java
One97 Communications Limited
 
Java file
Java fileJava file
Java file
simarsimmygrewal
 
Java practical
Java practicalJava practical
Java practical
william otto
 
Wap to implement bitwise operators
Wap to implement bitwise operatorsWap to implement bitwise operators
Wap to implement bitwise operators
Harleen Sodhi
 
C#.net
C#.netC#.net
C#.net
vnboghani
 
Java and j2ee_lab-manual
Java and j2ee_lab-manualJava and j2ee_lab-manual
Java and j2ee_lab-manual
hanumanthu mothukuru
 
java input & output statements
 java input & output statements java input & output statements
java input & output statements
VigneshManikandan11
 
Oracle Certified Associate (OCA) Java SE 8 Programmer II (1Z0-809) - Practice...
Oracle Certified Associate (OCA) Java SE 8 Programmer II (1Z0-809) - Practice...Oracle Certified Associate (OCA) Java SE 8 Programmer II (1Z0-809) - Practice...
Oracle Certified Associate (OCA) Java SE 8 Programmer II (1Z0-809) - Practice...
Udayan Khattry
 
Java Question-Bank-Class-8.pdf
Java Question-Bank-Class-8.pdfJava Question-Bank-Class-8.pdf
Java Question-Bank-Class-8.pdf
Aditya Kumar
 
Modify your solution for PLP04 to allow the user to choose the shape.pdf
Modify your solution for PLP04 to allow the user to choose the shape.pdfModify your solution for PLP04 to allow the user to choose the shape.pdf
Modify your solution for PLP04 to allow the user to choose the shape.pdf
hullibergerr25980
 
Integration Project Inspection 3
Integration Project Inspection 3Integration Project Inspection 3
Integration Project Inspection 3Dillon Lee
 
OCJP Samples Questions: Exceptions and assertions
OCJP Samples Questions: Exceptions and assertionsOCJP Samples Questions: Exceptions and assertions
OCJP Samples Questions: Exceptions and assertions
Hari kiran G
 
Java exercise1
Java exercise1Java exercise1
Java exercise1
Jainul Musani
 
Java language fundamentals
Java language fundamentalsJava language fundamentals
Java language fundamentals
Kapish Joshi
 

Similar to Review Questions for Exam 10182016 1. public class .pdf (20)

OXUS20 JAVA Programming Questions and Answers PART I
OXUS20 JAVA Programming Questions and Answers PART IOXUS20 JAVA Programming Questions and Answers PART I
OXUS20 JAVA Programming Questions and Answers PART I
 
Spring 2014 CSCI 111 Final exam of 1 61. (2 points) Fl.docx
Spring 2014 CSCI 111 Final exam   of 1 61. (2 points) Fl.docxSpring 2014 CSCI 111 Final exam   of 1 61. (2 points) Fl.docx
Spring 2014 CSCI 111 Final exam of 1 61. (2 points) Fl.docx
 
Chapter i(introduction to java)
Chapter i(introduction to java)Chapter i(introduction to java)
Chapter i(introduction to java)
 
Lab01.pptx
Lab01.pptxLab01.pptx
Lab01.pptx
 
Java doc Pr ITM2
Java doc Pr ITM2Java doc Pr ITM2
Java doc Pr ITM2
 
programming for Calculator in java
programming for Calculator in javaprogramming for Calculator in java
programming for Calculator in java
 
Java file
Java fileJava file
Java file
 
Java file
Java fileJava file
Java file
 
Java practical
Java practicalJava practical
Java practical
 
Wap to implement bitwise operators
Wap to implement bitwise operatorsWap to implement bitwise operators
Wap to implement bitwise operators
 
C#.net
C#.netC#.net
C#.net
 
Java and j2ee_lab-manual
Java and j2ee_lab-manualJava and j2ee_lab-manual
Java and j2ee_lab-manual
 
java input & output statements
 java input & output statements java input & output statements
java input & output statements
 
Oracle Certified Associate (OCA) Java SE 8 Programmer II (1Z0-809) - Practice...
Oracle Certified Associate (OCA) Java SE 8 Programmer II (1Z0-809) - Practice...Oracle Certified Associate (OCA) Java SE 8 Programmer II (1Z0-809) - Practice...
Oracle Certified Associate (OCA) Java SE 8 Programmer II (1Z0-809) - Practice...
 
Java Question-Bank-Class-8.pdf
Java Question-Bank-Class-8.pdfJava Question-Bank-Class-8.pdf
Java Question-Bank-Class-8.pdf
 
Modify your solution for PLP04 to allow the user to choose the shape.pdf
Modify your solution for PLP04 to allow the user to choose the shape.pdfModify your solution for PLP04 to allow the user to choose the shape.pdf
Modify your solution for PLP04 to allow the user to choose the shape.pdf
 
Integration Project Inspection 3
Integration Project Inspection 3Integration Project Inspection 3
Integration Project Inspection 3
 
OCJP Samples Questions: Exceptions and assertions
OCJP Samples Questions: Exceptions and assertionsOCJP Samples Questions: Exceptions and assertions
OCJP Samples Questions: Exceptions and assertions
 
Java exercise1
Java exercise1Java exercise1
Java exercise1
 
Java language fundamentals
Java language fundamentalsJava language fundamentals
Java language fundamentals
 

More from mayorothenguyenhob69

If the sample means are different from the population mean, what do .pdf
If the sample means are different from the population mean, what do .pdfIf the sample means are different from the population mean, what do .pdf
If the sample means are different from the population mean, what do .pdf
mayorothenguyenhob69
 
How would you define the Wilcoxon Signed Rank TestSolutionThe.pdf
How would you define the Wilcoxon Signed Rank TestSolutionThe.pdfHow would you define the Wilcoxon Signed Rank TestSolutionThe.pdf
How would you define the Wilcoxon Signed Rank TestSolutionThe.pdf
mayorothenguyenhob69
 
How could global climate change affect vector-borne or zoonotic di.pdf
How could global climate change affect vector-borne or zoonotic di.pdfHow could global climate change affect vector-borne or zoonotic di.pdf
How could global climate change affect vector-borne or zoonotic di.pdf
mayorothenguyenhob69
 
How Can Sequence Data Be Used to Track Flu Virus Evolution During Pan.pdf
How Can Sequence Data Be Used to Track Flu Virus Evolution During Pan.pdfHow Can Sequence Data Be Used to Track Flu Virus Evolution During Pan.pdf
How Can Sequence Data Be Used to Track Flu Virus Evolution During Pan.pdf
mayorothenguyenhob69
 
Far from being primitive, bacteria have evolved until they are i.pdf
Far from being primitive, bacteria have evolved until they are i.pdfFar from being primitive, bacteria have evolved until they are i.pdf
Far from being primitive, bacteria have evolved until they are i.pdf
mayorothenguyenhob69
 
E1-1 Reporting Amounts on the Four Basic Financial Statements [LO 1-2.pdf
E1-1 Reporting Amounts on the Four Basic Financial Statements [LO 1-2.pdfE1-1 Reporting Amounts on the Four Basic Financial Statements [LO 1-2.pdf
E1-1 Reporting Amounts on the Four Basic Financial Statements [LO 1-2.pdf
mayorothenguyenhob69
 
Do differentiated cells transform into other type of cells How Wha.pdf
Do differentiated cells transform into other type of cells How Wha.pdfDo differentiated cells transform into other type of cells How Wha.pdf
Do differentiated cells transform into other type of cells How Wha.pdf
mayorothenguyenhob69
 
Define the terms activity, layout, intent, and AVDSolutionACT.pdf
Define the terms activity, layout, intent, and AVDSolutionACT.pdfDefine the terms activity, layout, intent, and AVDSolutionACT.pdf
Define the terms activity, layout, intent, and AVDSolutionACT.pdf
mayorothenguyenhob69
 
Describe the similarities and differences between IPv4 & IPv6.So.pdf
Describe the similarities and differences between IPv4 & IPv6.So.pdfDescribe the similarities and differences between IPv4 & IPv6.So.pdf
Describe the similarities and differences between IPv4 & IPv6.So.pdf
mayorothenguyenhob69
 
Compare different sexual and asexual life cycles noting their adapti.pdf
Compare different sexual and asexual life cycles noting their adapti.pdfCompare different sexual and asexual life cycles noting their adapti.pdf
Compare different sexual and asexual life cycles noting their adapti.pdf
mayorothenguyenhob69
 
BackgroundIn many applications, the composition of a collection o.pdf
BackgroundIn many applications, the composition of a collection o.pdfBackgroundIn many applications, the composition of a collection o.pdf
BackgroundIn many applications, the composition of a collection o.pdf
mayorothenguyenhob69
 
11.25In 2010, there were 117,538,000 households in the United Stat.pdf
11.25In 2010, there were 117,538,000 households in the United Stat.pdf11.25In 2010, there were 117,538,000 households in the United Stat.pdf
11.25In 2010, there were 117,538,000 households in the United Stat.pdf
mayorothenguyenhob69
 
Which methodology may be used for detection of incorporated BrdUA.pdf
Which methodology may be used for detection of incorporated BrdUA.pdfWhich methodology may be used for detection of incorporated BrdUA.pdf
Which methodology may be used for detection of incorporated BrdUA.pdf
mayorothenguyenhob69
 
Which of the following is a difference between lightweight and heavy.pdf
Which of the following is a difference between lightweight and heavy.pdfWhich of the following is a difference between lightweight and heavy.pdf
Which of the following is a difference between lightweight and heavy.pdf
mayorothenguyenhob69
 
What are the common conditions resulting in thrombocytosis Explain .pdf
What are the common conditions resulting in thrombocytosis Explain .pdfWhat are the common conditions resulting in thrombocytosis Explain .pdf
What are the common conditions resulting in thrombocytosis Explain .pdf
mayorothenguyenhob69
 
What are some differences between the xylem and the phloem Solu.pdf
What are some differences between the xylem and the phloem  Solu.pdfWhat are some differences between the xylem and the phloem  Solu.pdf
What are some differences between the xylem and the phloem Solu.pdf
mayorothenguyenhob69
 
Two families of sloths exist commonly in Central and South America (t.pdf
Two families of sloths exist commonly in Central and South America (t.pdfTwo families of sloths exist commonly in Central and South America (t.pdf
Two families of sloths exist commonly in Central and South America (t.pdf
mayorothenguyenhob69
 
Two populations of rats are discovered on nearby islands. Describe t.pdf
Two populations of rats are discovered on nearby islands. Describe t.pdfTwo populations of rats are discovered on nearby islands. Describe t.pdf
Two populations of rats are discovered on nearby islands. Describe t.pdf
mayorothenguyenhob69
 
30-32 Nuclear pores permit the passage of chromosomes outward. glu.pdf
30-32 Nuclear pores permit the passage of  chromosomes outward.  glu.pdf30-32 Nuclear pores permit the passage of  chromosomes outward.  glu.pdf
30-32 Nuclear pores permit the passage of chromosomes outward. glu.pdf
mayorothenguyenhob69
 
B-tree insertion (Draw node) Show the results of inserting the keys .pdf
B-tree insertion (Draw node) Show the results of inserting the keys .pdfB-tree insertion (Draw node) Show the results of inserting the keys .pdf
B-tree insertion (Draw node) Show the results of inserting the keys .pdf
mayorothenguyenhob69
 

More from mayorothenguyenhob69 (20)

If the sample means are different from the population mean, what do .pdf
If the sample means are different from the population mean, what do .pdfIf the sample means are different from the population mean, what do .pdf
If the sample means are different from the population mean, what do .pdf
 
How would you define the Wilcoxon Signed Rank TestSolutionThe.pdf
How would you define the Wilcoxon Signed Rank TestSolutionThe.pdfHow would you define the Wilcoxon Signed Rank TestSolutionThe.pdf
How would you define the Wilcoxon Signed Rank TestSolutionThe.pdf
 
How could global climate change affect vector-borne or zoonotic di.pdf
How could global climate change affect vector-borne or zoonotic di.pdfHow could global climate change affect vector-borne or zoonotic di.pdf
How could global climate change affect vector-borne or zoonotic di.pdf
 
How Can Sequence Data Be Used to Track Flu Virus Evolution During Pan.pdf
How Can Sequence Data Be Used to Track Flu Virus Evolution During Pan.pdfHow Can Sequence Data Be Used to Track Flu Virus Evolution During Pan.pdf
How Can Sequence Data Be Used to Track Flu Virus Evolution During Pan.pdf
 
Far from being primitive, bacteria have evolved until they are i.pdf
Far from being primitive, bacteria have evolved until they are i.pdfFar from being primitive, bacteria have evolved until they are i.pdf
Far from being primitive, bacteria have evolved until they are i.pdf
 
E1-1 Reporting Amounts on the Four Basic Financial Statements [LO 1-2.pdf
E1-1 Reporting Amounts on the Four Basic Financial Statements [LO 1-2.pdfE1-1 Reporting Amounts on the Four Basic Financial Statements [LO 1-2.pdf
E1-1 Reporting Amounts on the Four Basic Financial Statements [LO 1-2.pdf
 
Do differentiated cells transform into other type of cells How Wha.pdf
Do differentiated cells transform into other type of cells How Wha.pdfDo differentiated cells transform into other type of cells How Wha.pdf
Do differentiated cells transform into other type of cells How Wha.pdf
 
Define the terms activity, layout, intent, and AVDSolutionACT.pdf
Define the terms activity, layout, intent, and AVDSolutionACT.pdfDefine the terms activity, layout, intent, and AVDSolutionACT.pdf
Define the terms activity, layout, intent, and AVDSolutionACT.pdf
 
Describe the similarities and differences between IPv4 & IPv6.So.pdf
Describe the similarities and differences between IPv4 & IPv6.So.pdfDescribe the similarities and differences between IPv4 & IPv6.So.pdf
Describe the similarities and differences between IPv4 & IPv6.So.pdf
 
Compare different sexual and asexual life cycles noting their adapti.pdf
Compare different sexual and asexual life cycles noting their adapti.pdfCompare different sexual and asexual life cycles noting their adapti.pdf
Compare different sexual and asexual life cycles noting their adapti.pdf
 
BackgroundIn many applications, the composition of a collection o.pdf
BackgroundIn many applications, the composition of a collection o.pdfBackgroundIn many applications, the composition of a collection o.pdf
BackgroundIn many applications, the composition of a collection o.pdf
 
11.25In 2010, there were 117,538,000 households in the United Stat.pdf
11.25In 2010, there were 117,538,000 households in the United Stat.pdf11.25In 2010, there were 117,538,000 households in the United Stat.pdf
11.25In 2010, there were 117,538,000 households in the United Stat.pdf
 
Which methodology may be used for detection of incorporated BrdUA.pdf
Which methodology may be used for detection of incorporated BrdUA.pdfWhich methodology may be used for detection of incorporated BrdUA.pdf
Which methodology may be used for detection of incorporated BrdUA.pdf
 
Which of the following is a difference between lightweight and heavy.pdf
Which of the following is a difference between lightweight and heavy.pdfWhich of the following is a difference between lightweight and heavy.pdf
Which of the following is a difference between lightweight and heavy.pdf
 
What are the common conditions resulting in thrombocytosis Explain .pdf
What are the common conditions resulting in thrombocytosis Explain .pdfWhat are the common conditions resulting in thrombocytosis Explain .pdf
What are the common conditions resulting in thrombocytosis Explain .pdf
 
What are some differences between the xylem and the phloem Solu.pdf
What are some differences between the xylem and the phloem  Solu.pdfWhat are some differences between the xylem and the phloem  Solu.pdf
What are some differences between the xylem and the phloem Solu.pdf
 
Two families of sloths exist commonly in Central and South America (t.pdf
Two families of sloths exist commonly in Central and South America (t.pdfTwo families of sloths exist commonly in Central and South America (t.pdf
Two families of sloths exist commonly in Central and South America (t.pdf
 
Two populations of rats are discovered on nearby islands. Describe t.pdf
Two populations of rats are discovered on nearby islands. Describe t.pdfTwo populations of rats are discovered on nearby islands. Describe t.pdf
Two populations of rats are discovered on nearby islands. Describe t.pdf
 
30-32 Nuclear pores permit the passage of chromosomes outward. glu.pdf
30-32 Nuclear pores permit the passage of  chromosomes outward.  glu.pdf30-32 Nuclear pores permit the passage of  chromosomes outward.  glu.pdf
30-32 Nuclear pores permit the passage of chromosomes outward. glu.pdf
 
B-tree insertion (Draw node) Show the results of inserting the keys .pdf
B-tree insertion (Draw node) Show the results of inserting the keys .pdfB-tree insertion (Draw node) Show the results of inserting the keys .pdf
B-tree insertion (Draw node) Show the results of inserting the keys .pdf
 

Recently uploaded

Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
bennyroshan06
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
EduSkills OECD
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
Excellence Foundation for South Sudan
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdfESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
Fundacja Rozwoju Społeczeństwa Przedsiębiorczego
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
PedroFerreira53928
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
PedroFerreira53928
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
AzmatAli747758
 

Recently uploaded (20)

Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdfESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
 

Review Questions for Exam 10182016 1. public class .pdf

  • 1. Review Questions for Exam 10/18//2016 1. public class Question1 { public static void main(String[ ] args) { System.out.print("Here"); System.out.println("There " + "Everywhere"); System.out.println("But not" + "in NJ"); } } Write the output after the above program is executed. 2. Consider the following statement: System.out.println("1 big bad wolft8 the 3 little pigs 4 dinner 2night"); This statement will output ________ lines of text A) 1 B) 2 C) 3 D) 4 E) 5 public class MyString { public static void main(String[] args) {
  • 2. System.out.print("1 big bad wolft8 the 3 little pigs 4 dinner 2 night"); } } 3. The word println is a(n) A) method B) reserved word C) variable D) class E) String 4. A Java variable is the name of a 5. What output is produced by the following? System.out.println ("X: " + 25); System.out.println ("Y: " + (15 + 50)); System.out.println ("Z: " + 300 + 50); Of the following types, which one cannot store a numeric value? 6. What is output with the statement System.out.println(""+x+y); if x and y are int values where x=10 and y=5? public class MyString { public static void main(String[] args)
  • 3. { int x=10; int y = 5; System.out.println(""+x+y); } } 7. What happens if you attempt to use a variable before it has been initialized? A. A syntax error may be generated by the compiler B. A runtime error may occur during execution C. A "garbage" or "uninitialized" value will be used in the computation D. A value of zero is used if a variable has not been initialized E. Answers A and B are correct 8. What is the function of the dot operator? A. It serves to separate the integer portion from the fractional portion of a floating point number B. It allows one to access the data within an object when given a reference to the object C. It allows one to invoke a method within an object when given a reference to the object D. It is used to terminate commands (much as a period terminates a sentence in English) E. Both B and C are correct 9. Say you write a program that makes use of the Random class, but you fail to include an import statement for java.util.Random (or java.util.*). What will happen when you attempt to compile and run your program. A. The program won't run, but it will compile with a warning about the missing class. B. The program won't compile-you'll receive a syntax error about the missing class. C. The program will compile, but you'll receive a warning about the missing class. D. The program will encounter a runtime error when it attempts to access any member of the Random class
  • 4. E. none of the above 10. An API is A. an Abstract Programming Interface B. an Application Programmer's Interface C. an Application Programming Interface D. an Abstract Programmer's Interface E. an Absolute Programming Interface 11. When executing a program, the processor reads each program instruction from 12. The main method for a Java program is defined by 13. What will be the result of the following assignment statement? Assume b = 5 and c = 10. int a = b * (-c + 2) / 2; public class MyString {
  • 5. public static void main(String[] args) { int b = 5; int c = 10; int a = b * (-c + 2) / 2; System.out.println("a: "+a); } } 14. If the String major = "Computer Science", what is returned by major.charAt(1)? public class MyString { public static void main(String[] args) { String major = "Computer Science"; System.out.println(major.charAt(1)); } } 15. For the following questions, refer to the class defined below: import java.util.Scanner; public class Questions15 { public static void main(String[ ] args) { int x, y, z; double average; Scanner scan = new Scanner(System.in);
  • 6. System.out.println("Enter an integer value"); x = scan.nextInt( ); System.out.println("Enter another integer value"); y = scan.nextInt( ); System.out.println("Enter a third integer value"); z = scan.nextInt( ); average = (x + y + z) / 3; System.out.println("The result of my calculation is " + average); } } 16. What is the output of the following program? public class Precision { public static void main(String[] args) { int x=5; int y =5; int z = 3; double average; average = (x + y + z) / 3; System.out.println("The result of my calculation is " + average); } } ANS: ÏYour gross pay is $1000.0 17. What is the output of the following program?
  • 7. public class Initialize { // This program shows variable initialization. public static void main(String[] args) { int month = 2, days = 28; System.out.println("Month " + month + " has " + days + " days."); } } 18. What is the output of the following program? public class Payroll { public static void main(String[] args) { int hours = 40; double grossPay, payRate = 25.0; grossPay = hours * payRate; System.out.println("Your gross pay is $" + grossPay); } } 19. import java.util.Scanner; // Needed for the Scanner class /* This program has a problem reading input. */
  • 8. public class InputProblem { public static void main(String[] args) { String name; // To hold the user's name int age; // To hold the user's age double income; // To hold the user's income // Create a Scanner object to read input. Scanner keyboard = new Scanner(System.in); // Get the user's age. System.out.print("What is your age? "); age = keyboard.nextInt(); // Get the user's income System.out.print("What is your annual income? "); income = keyboard.nextDouble(); // Get the user's name. System.out.print("What is your name? "); name = keyboard.nextLine(); // Display the information back to the user. System.out.println("Hello " + name + ". Your age is " + age + " and your income is $" + income); } } What is your age? 50 ¼¼§ÏWhat is your annual income? 1000 ÏϧÏWhat is your name? Hello . Your age is 50 and your income is $1000.0
  • 9. To fix the problem, add this line before the statement of System.out.print("What is your name? "); // Consume the remaining newline. keyboard.nextLine(); 20. What is the output of the following program? // This program demonstrates the char data type. public class Letters { public static void main(String[] args) { char letter; letter = 'A'; System.out.println(letter); letter = 'B'; System.out.println(letter); } } 21. Write an expression that produces a random integer in the following ranges: Range 0 to 12 1 to 20 22. public class MyString
  • 10. { //----------------------------------------------------------------- // Prints a string and various mutations of it. //----------------------------------------------------------------- public static void main(String[] args) { String str1="Two"; System.out.println( str1 ); int count=str1.length(); System.out.println(count); System.out.println( str1.length() ); String str3 = str1.substring(1,3); System.out.println( str3 ); String str2= new String ("Three"); String str6= new String ("THREE"); boolean equalThree1 = str2.equals(str6); boolean equalThree2 = str2.equalsIgnoreCase(str6); String str4= str2.concat(" Four"); String str5=str2.replace('e', 'x'); System.out.println( str2 ); System.out.println( str4 ); System.out.println( str5 ); System.out.println( equalThree1 ); System.out.println( equalThree2 ); String str7="AB"; String str8="CD"; System.out.println( str7.compareTo(str8) ); System.out.println( str8.compareTo(str7) ); System.out.println (str7.charAt(0)); } } 23. Trace the execution of the following program assuming the input stream contains the numbers
  • 11. 10, 3, and 14.3. Use a table that shows the value of each variable at each step. Also show the output (exactly as it would be printed). // FILE: Trace.java // PURPOSE: An exercise in tracing a program and understanding // assignment statements and expressions. import java.util.Scanner; public class Trace { public static void main (String[] args) { int one, two, three; //line 1 double what; //line 2 Scanner scan = new Scanner(System.in); //line 3 System.out.print ("Enter two integers: "); //line 4 one = scan.nextInt(); //line 5 two = scan.nextInt(); //line 6 System.out.print("Enter a floating point number: "); //line 7 what = scan.nextDouble() ; //line 8 three = 4 * one + 5 * two; //line 9 two = 2 * one; //line 10 System.out.println ("one " + two + ":" + three); //line 11 one = 46 / 5 * 2 + 19 % 4; //line 12
  • 12. three = one + two; //line 13 what = (what + 2.5) / 2 ; //line 14 System.out.println (what + " is what!"); //line 15 } } 24. Write an application that reads values representing a time duration in hours, minutes, and seconds and then prints the equalivant total number of seconds. (for example, 1 hour, 28 minutes and 42 seconds is equivalent to 5322 seconds.) Solution Hi, Friend please do not post more than 5 questions in a single post. Please find my answer for first 6 questions. Please post other questions in other post. 1) HereThere Everywhere But notin NJ Explanation: System.out.println => peint the argument on TERMINAL + => concatenate two string OR one string and other is any data type 2) Output: 1 big bad wolf 8 the 3 little pigs 4 dinner 2night Line break with and character Ans: 3 3) println is a method of System class Ans: ) method
  • 13. 4) c.data value stored in memory that can not change its type during the program’s execution 5) X: 25 Y: 65 Z: 30050 6) Ans: 105 System.out.println(""+x+y); -=> ""+x = 10 that is string 10(string) + 5(int) => 105 (string)