CSE1322 StudyGuide
Given this method: public static int do_stuff(int x) { if(x==0) { return 1; } else { return do_stuff(x-1); } } What will the method return if called as follows: do_stuff(15);
1
What is the output of the following code? using System; class MainClass { public static void addtwo(int[] numArray) { numArray[0]+=2; } public static void Main (string[] args) { int[] myNumbers = new int[] {1,2,3,4,5}; Console.WriteLine(myNumbers[0]); } } A. 1 B. 3 C. 2 D. 4
1
Assuming you have a Queue (myQueue), what is the output of the following operations? Java myQueue.enqueue(1); myQueue.enqueue(2); myQueue.enqueue(3); System.out.println(myQueue.dequeue()); System.out.println(myQueue.peek()); System.out.println(myQueue.peek()); C# myQueue.enqueue(1); myQueue.enqueue(2); myQueue.enqueue(3); Console.WriteLine(myQueue.dequeue()); Console.WriteLine(myQueue.peek()); Console.WriteLine(myQueue.peek());
1 2 2
What is the value of head.next.next.data in this linked list? ________ next _________ next _________ next head --> | data=5 | ------> | data=10 | ------> | data=15 | ------|| ---------- --------- ---------
15
What is the output of the following code? using System; interface IA { void do_stuff1(); } abstract class B { public abstract void do_stuff2(); public int do_stuff3() { return 2; } } class C : B,IA { public void do_stuff1() { int a=1; } public override void do_stuff2() { int b=1; } } class MainClass { public static void Main (string[] args) { C myC=new C(); Console.WriteLine(myC.do_stuff3()); } }
2
What is the output of the following code? using System.Collections.Generic; class Stuff { private int x; public void setx(int y) { x=y; } public int getx() { return x; } } class MainClass { public static void Main (string[] args) { List<Stuff> myNumbers = new List<Stuff>(); for(int i=0;i<5;i++) { Stuff myStuff = new Stuff(); myStuff.setx(i*10); myNumbers.Add(myStuff); } Console.WriteLine(myNumbers[2].getx()); } }
20
Given the following method: public static int recursive(int n,int m) { if(n<=1) { return 1; } else { return m+recursive(n/2,m*2); } } What is the value of x after the following call: int x = recursive(6,8);
25
Given the following method: public static int myFunc(int x, int y) { if(x==0) { return y; } else { return myFunc(x-1,y+1); } } What is the value of x after the following call: int x = myFunc(0,4);
4
What is the output of the following code? using System.Collections; class MainClass { public static void Main (string[] args) { ArrayList myNumbers = new ArrayList(); myNumbers.Add(10); myNumbers.Add(20); myNumbers.Add(30); myNumbers.Add(40); Console.WriteLine(myNumbers[myNumbers.Count-1]); } }
40
What is the value of head.next.previous.data in this linked list? ________ next _________ next _________ next head --> | data=5 | ------> | data=10 | ------> | data=15 | ------|| ||-------| |<-------- | | <--------| | previous| | previous | | previous| | ---------- --------- ---------
5
What is the output of the following code: using System; class MainClass { public static void do_stuff() { int[] myNums = new int[5]; myNums[5]=1; } public static void Main (string[] args) { try { do_stuff(); } catch(IndexOutOfRangeException e) { Console.WriteLine("A"); } catch(SystemException e) { Console.WriteLine("B"); } catch(Exception e) { Console.WriteLine("C"); } } }
A
What is the output of the following code? class A { public void do_it() { Console.WriteLine("A"); } } class B : A { public void do_stuff() { Console.WriteLine("B"); } } class MainClass { public static void Main (string[] args) { A myClass=new A(); myClass=new B(); myClass.do_it(); } } A B A B This code does not compile
A
What is the output of the following code: using System; class MainClass { public static void do_stuff() { int[] myNums = new int[5]; myNums[5]=1; } public static void Main (string[] args) { try { do_stuff(); } catch(Exception e) { Console.WriteLine("A"); } finally { Console.WriteLine("X"); } } }
A X
Which of the following statements are valid? A constructor can return a integer A constructor can return a char A constructor cannot return anything A constructor can return a void
A constructor cannot return anything
Which of the following statements is true? A. A try/catch block should never be used with fileIO B. A try/catch block should be used only when writing to a file C. A try/catch block should be used only when reading from a file. D. A try/catch block should be used when reading and writing to a file.
A try/catch block should be used when reading and writing to a file.
After executing the following code, what will be the contents of A.txt? using System; using System.IO; class MainClass { public static void write_file(string filename, string line, int x) { try { StreamWriter theFile = new StreamWriter(filename); for(int i=0;i<x;i++) { theFile.WriteLine(line); } theFile.Close(); } catch(IOException e) { Console.WriteLine("Error reading file: "+e.Message); } } public static void Main (string[] args) { write_file("A.txt","Hi",3); write_file("A.txt","Hi",3); } } A. A.txt wll not exist after running this code. B. A.txt will be empty C. A.txt will contain the word Hi on three lines D. A.txt will contain the word Hi on six lines
A.txt will contain the word Hi on three lines
After executing the following code, what will be the contents of A.txt? using System; using System.IO; class MainClass { public static void write_file(string filename, string line, int x) { try { StreamWriter theFile = new StreamWriter(filename); for(int i=0;i<x;i++) { theFile.WriteLine(line); } theFile.Close(); } catch(IOException e) { Console.WriteLine("Error reading file: "+e.Message); } } public static void Main (string[] args) { write_file("A.txt","Hi",3); } } A. A.txt wll not exist after running this code. B. A.txt will be empty C. A.txt will contain the word Hi on three lines D. A.txt will contain the word Hi on six lines
A.txt will contain the word Hi on three lines
We cannot create instance of A Nested class B Child class C Abstract class D Parent class
Abstract class
An object is created with a new keyword? A. At compile time B. Depends on the code C. None D. At run time
At run time
What is the output of the following code? class A { public virtual void do_it() { Console.WriteLine("A"); } } class B : A { public override void do_it() { Console.WriteLine("B"); } } class MainClass { public static void Main (string[] args) { A myClass=new B(); myClass.do_it(); } }
B
What does the following code output? public static int do_things(int x) { return x+=10; } public static void Main (string[] args) { int a=5; int b=do_things(a); int c=a+b; Console.WriteLine("C is "+c); }
C is 20
What is the output of the following code? class MainClass { public static void swap(string str1, string str2) { String holdString; holdString = str1; str1 = str2; str2 = holdString; } public static void Main (string[] args) { string s1 = "Computers"; string s2 = "Rock"; swap(s1, s2); Console.WriteLine(s1+" "+s2); } }
Computers Rock
What is the output of the following code? using System; class Node { public char letter; public Node next; public Node(char letter) { this.letter=letter; next=null; } } class MainClass { public static void dostuff(Node head) { if(head!=null) { dostuff(head.next); Console.Write(head.letter); } } public static void Main (string[] args) { Node head = null; head=new Node('A'); head.next=new Node('B'); head.next.next=new Node('C'); head.next.next.next=new Node('D'); head.next.next.next.next=new Node('E'); dostuff(head); } }
EDCBA
All the following are OOP concepts except A. Exception B. Encapsulation C. Abstraction D. Polymorphism
Exception
(True or False) Arrays are not fixed length and can grow or shrink depending on if the size of the data set varies.
False
(True or False) Code written to take advantage of parallel processing will always run faster than code which is not written for parallel processing?
False
(True or False) Constructor can return a value?
False
(True or False) Making a program multithreaded will always ensure it runs faster?
False
(True or False) To facilitate encapsulation, most attributes and methods in a class should be private?
False
The Socket object in Java, and the TCPClient object in C# can be used to read information from a remote server, but not write to it?
False
GUI stands for A. Graphical User Interface B. Graphical Utility Interface C. Geographical User Internet
Graphical User Interface
What is the output of the following code? class MainClass { public static void dostuff(int x, int y) { Console.WriteLine("Hi from dostuff 1"); } public static void dostuff(int x) { Console.WriteLine("Hi from dostuff 2"); } public static void dostuff(char x) { Console.WriteLine("Hi from dostuff 3"); } public static void dostuff(bool x) { Console.WriteLine("Hi from dostuff 4"); } public static void Main (string[] args) { dostuff(7); dostuff('c'); dostuff(true); } }
Hi from dostuff 2 Hi from dostuff 3 Hi from dostuff 4
Given the following class, which of the following statements are invalid? class House { public int square_footage; public int stories; public House() { square_footage=0; stories=1; } public House(int sf, int s) { square_footage=sf; stories=s; } }
House h1=new House(1500,1,1);
What is the output of the following code? using System; using System.Threading; class MyFirstThread { static int next_tid=1; int tid; public MyFirstThread() { tid=next_tid++; } public void run() { Console.WriteLine("I'm thread "+tid); } } class MainClass { public static void Main (string[] args) { MyFirstThread t1 = new MyFirstThread(); MyFirstThread t2 = new MyFirstThread(); MyFirstThread t3 = new MyFirstThread(); Thread thread1 = new Thread(new ThreadStart(t1.run)); Thread thread2 = new Thread(new ThreadStart(t2.run)); Thread thread3 = new Thread(new ThreadStart(t3.run)); Console.WriteLine("Let's go!"); thread1.Start(); thread2.Start(); thread3.Start(); Console.WriteLine("Done"); } }
It's impossible to tell the order the statements will appear in.
Assume you have a file called QuizGrades.csv with the following content: Student1,100,90,80,90,80 Student2,70,80,85,85,80 Student3,100,100,100,95,100 Student4,70,70,80,70,80 Student5,90,90,90,90,100 Which of the following code snips correctly reads each line from the file correctly assigning it to a variable called line. You can assume the previous question correctly opened the file, and you have a variable myScan which allows you to access the file.
Java while(myScan.hasNextLine()) { String line=myScan.nextLine(); } C# while(! myScan.EndOfStream) { string line=myScan.ReadLine(); }
Assume you have a file called QuizGrades.csv with the following content: Student1,100,90,80,90,80 Student2,70,80,85,85,80 Student3,100,100,100,95,100 Student4,70,70,80,70,80 Student5,90,90,90,90,100 Which of the following lines is the correct way to open a text file such as the above for reading.
Java File myFile = new File("QuizGrades.csv"); Scanner myScan = new Scanner(myFile); C# StreamReader myScan= new StreamReader("QuizGrades.csv");
The following recursive method takes in an array of characters, and finds the highest letter alphabetically in the array. i.e. if passed the following characters: x a b p s, it should return x because x is the last of those alphabetically. Choose the correct base condition that completes the code correctly from the choices below. public static char last_letter_used(char[] charArray, int position) { //Base condition goes here else { if(charArray[position]>last_letter_used(charArray,position+1)) { return charArray[position]; } else { return(last_letter_used(charArray,position+1)); } } }
Java if(position==charArray.length-1) { return charArray[position]; } C# if(position==charArray.Length-1) { return charArray[position]; }
Which of the following will successfully write the word Output to the file a.txt in the current working directory?
Java import java.io.*; class Main { public static void main(String[] args) { try { File myFile = new File("a.txt"); PrintWriter sr = new PrintWriter(myFile); sr.println("Output"); sr.close(); } catch(IOException e) { System.out.println(e.getMessage()); } } } C# using System; using System.IO; class MainClass { public static void Main (string[] args) { try { StreamWriter sr = new StreamWriter("a.txt"); sr.WriteLine("Output"); sr.Close(); } catch(IOException e) { Console.WriteLine(e.Message); } } }
Given the following code: public static void check_age(int age) { if(age<0) { throw new Exception("Age cannot be below 0"); } else if(age>140) { throw new Exception("That seems too high."); } } What is the correct way to call this method such that your code doesn't crash if an invalid age is entered?
Java try { check_age(age); } catch(Exception e) { System.out.println(e.getMessage()); } C# try { check_age(age); } catch(Exception e) { Console.WriteLine(e.Message); }
How do you create a new instance of a Graphics context in Java and a Graphics class in C#?
Java C# GraphicsContext gc= canvas1.getGraphicsContext2D(); C# base.OnPaint(e); Graphics g = e.Graphics;
What is the output of the following code: using System; class MainClass { public static void do_stuff() { int[] myNums = new int[5]; myNums[5]=1; } public static void Main (string[] args) { try { do_stuff(); } catch(Exception e) { Console.WriteLine(e.Message); } } }
Java: Index 5 out of bounds for length 5 C#: Index was outside the bounds of the array.
What is the output of the following code? using System; using System.Threading; class MyFirstThread { static int next_tid=1; int tid; public MyFirstThread() { tid=next_tid++; } public void run() { Console.WriteLine("I'm thread "+tid); } } class MainClass { public static void Main (string[] args) { MyFirstThread t1 = new MyFirstThread(); MyFirstThread t2 = new MyFirstThread(); MyFirstThread t3 = new MyFirstThread(); Console.WriteLine("Let's go!"); Thread thread1 = new Thread(new ThreadStart(t1.run)); Thread thread2 = new Thread(new ThreadStart(t2.run)); Thread thread3 = new Thread(new ThreadStart(t3.run)); Console.WriteLine("Done"); } }
Let's go! Done
Which line or lines of code below will cause compile errors? using System; class Parent { public int x; } class Child : Parent { public void doStuff() { Console.WriteLine("I'm a child"); } } class MainClass { public static void Main (string[] args) { Parent p1 = new Parent(); Child c1 = new Child(); Parent p2 = new Child(); p1.doStuff(); //Line 1 c1.doStuff(); //Line 2 p2.doStuff(); //Line 3 ((Child)p2).doStuff(); //Line 4 } }
Line 1 Line 3
A code segment calculates the average of values stored in integers v1, v2, and v3 and stores the result in avg, which is of type double. What kind of error is caused with this statement? Double avg = v1 + v2 + v3 / (double) 3; A. Logic B. Overflow C. Runtime D. Syntax
Logic
In the worst case, what is the number of comparisons needed to search a singly-linked list of length N for a given element? 1 LogN N N/2
N
Will the following code compile? using System; interface IA { void do_stuff1(); void do_stuff2(); } class C : IA { public int do_stuff1() { return 1; } public void do_stuff2() { int b=1; } } class MainClass { public static void Main (string[] args) { C myC=new C(); } }
No class C does not implement do_stuff1() appropriately.
Will the following code compile? using System; interface IA { void do_stuff1(); void do_stuff2(); } class C : IA { public int do_stuff1() { return 1; } public void do_stuff2() { int b=1; } } class MainClass { public static void Main (string[] args) { C myC=new C(); } } A. No class C does not implement do_stuff1() appropriately. B. No, interface IA cannot have 2 virtual methods. C. No, class C cannot be instantiated because it implements an interface. D. Yes
No class C does not implement do_stuff1() appropriately.
Will the following code compile? using System; abstract class A { public abstract int do_stuff1(); public abstract int do_stuff2(); } class B : A { public override int do_stuff1() { return 4; } } class MainClass { public static void Main (string[] args) { B myB = new B(); } }
No, class B has no concrete method do_stuff2(), but it should have one.
Searching for a value in a Binary Search Tree with N nodes, will take approximately how much time? A. O(1) B. O(logN) C. O(N) D. O(N^2)
O(logN)
All methods in an interface are: A Private and Abstract B Public and Static C Public and Abstract D Public, Static and Abstract
Public and Abstract
Which of the following is the appropriate GUI (Graphical User Interface) component used to select one from multiple alternatives? A. Radio Button B. Scroll Bar C. Text Area D. Progress Bar
Radio Button
What is the output of the following statements: //Java: String s="Hi"; for(int i=0;i<3;i++) { System.out.print("S"+s); } //C#: string s="Hi"; for(int i=0;i<3;i++) { Console.Write("S"+s); }
SHiSHiSHi
What is the output of the following statements: //Java: String s="Hi"; for(int i=0;i<3;i++) { System.out.print("S"+s); } //C#: string s="Hi"; for(int i=0;i<3;i++) { Console.Write("S"+s); } A. Hi B. HiHiHi C. SHiSHiSHi D. SHiSHi
SHiSHiSHi
What is the output of the following code: using System; class MainClass { public static void Main (string[] args) { int[] myArray = new int[5]; try { for(int i=0;i<=5;i++) { myArray[i]=i; } Console.WriteLine(myArray[3]); } catch(Exception e) { Console.WriteLine("Something went wrong"); } } }
Something went wrong
What is the output of the following code? using System; using System.Collections.Generic; using System.Threading; class Widget { public string name; } class Inventory { public static List<Widget> factoryInventory = new List<Widget>(); } class Factory : Inventory { public void run() { for(int i=0;i<100;i++) { Widget newWidget = new Widget(); newWidget.name="Widget"+i; factoryInventory.Add(newWidget); } } } class MainClass { public static void Main (string[] args) { Inventory myInventory=new Inventory(); Thread[] factories = new Thread[100]; for(int i=0;i<100;i++) { Factory newFactory = new Factory(); factories[i]=new Thread(new ThreadStart(newFactory.run)); factories[i].Start(); } Console.WriteLine(Inventory.factoryInventory.Count); } }
The output will be different each time you run it.
In GUI coordinate system, which of the following positions refers to the coordinates (0,0)? A. The bottom left corner of the GUI box B. The top left corner of the GUI box C. The top right corner of the GUI box D. The bottom right corner of the GUI box
The top left corner of the GUI box
Which of the following methods are invalid? public static void do_stuff_1() { return; } public static int do_stuff_2() { return 2; } public static char do_stuff_3() { return 'c'; } public static bool do_stuff_4() { return false; } A. do_stuff_1() B. do_stuff_2() C. do_stuff_3() D. do_stuff_4()r E. They are all valid
They are all valid
If you wanted to find if a particular number was present in an array of one million integers, which of the following approaches will not work? A. Use a simple loop in a single thread, that looks in each of the cells. B. Use a multithreaded approach, where you have 10 threads each of which looks in 100,000 cells. C. Using a multithreaded approach, where you have 100 threads each of which looks at 10,000 cells. D. They would all work.
They would all work
Given the following code: public static int do_stuff(int x) { if(x==0) { return 1; } else { return 1 + do_stuff(x-2); } } What is returned from this code if called as follows: do_stuff(3);
This code crashes with a stack overflow
(True or False) A method with a return type of void may still have a return statement in it's code.
True
(True or False) All programs have at least one thread?
True
(True or False) An exception is a notification that something interrupts the normal program execution. Exceptions provide a programming paradigm for detecting and reacting to unexpected events.
True
(True or False) In a doubly-linked lists each node contains its value and two pointers: One which points to the next node One which points to the previous node
True
(True or False) In dynamic binding or late binding, the type of object is determined at run-time.
True
(True or False) Pressing a GUI button normally causes an event to occur.
True
(True or False) Recursion represents a powerful programming technique in which a method makes a call to itself from within its own method body.
True
(True or False) The code within the finally block is always executed, no matter how the program flow leaves the try block. This guarantees that the finally block will be executed even if an exception is thrown.
True
(True or False) The stack trace contains detailed information about the exception including where exactly it occurred in the program. The stack trace is very useful for programmers when they try to understand the problem causing the exception.
True
(True or False)A stack is a data structure that follows the principle of Last In First Out. Whereas a queue is a data structure that follows the principle of First in First Out?
True
The following code will compile and output 8? class Stuff { public static int x=7; public static void do_stuff() { x++; Console.WriteLine(x); } } class MainClass { public static void Main (string[] args) { Stuff.do_stuff(); } }
True
The following is a valid (i.e. will compile) abstract class definition: abstract class A { public int do_stuff1() { return 3; } public int do_stuff2() { return 4; } }
True
Will the following code compile? using System; abstract class A { public virtual int do_stuff1() { return 3; } public abstract int do_stuff2(); } class B : A { public override int do_stuff1() { return 4; } public override int do_stuff2() { return 7; } } class MainClass { public static void Main (string[] args) { B myB = new B(); myB.do_stuff1(); myB.do_stuff2(); } }
Yes
Will the following code compile? using System; interface IA { void do_stuff1(); } abstract class B { public abstract void do_stuff2(); } class C : B,IA { public void do_stuff1() { int a=1; } public override void do_stuff2() { int b=1; } } class MainClass { public static void Main (string[] args) { C myC=new C(); } }
Yes
Will the following code compile? using System; interface IA { void do_stuff1(); } interface IB { void do_stuff2(); } class C : IA,IB { public void do_stuff1() { int a=1; } public void do_stuff2() { int b=1; } } class MainClass { public static void Main (string[] args) { C myC=new C(); } }
Yes
What method will contain the body of the thread?
You can call it anything you want, but you reference it in ThreadStart( )
What is the output of the following code? using System; class Counter { private int seconds=0; public void addOne() { seconds++; } public void subtractOne() { seconds--; } public int currentCount() { return seconds; } } class MainClass { public static int doStuff(int x, Counter a) { x++; a.addOne(); return x+a.currentCount(); } public static void Main (string[] args) { int x=0; int y=0; Counter a = new Counter(); a.addOne(); y=doStuff(x,a); Console.WriteLine("a "+a.currentCount()+" x "+x+" y "+y); } }
a 2 x 0 y 3
What is the output of the following code? class Stuff { public int number=1; } class MainClass { public static void do_things(int y) { y+=3; } public static void do_other_things(Stuff y) { y.number+=3; } public static void Main (string[] args) { int a=3; Stuff myStuff = new Stuff(); do_things(a); do_other_things(myStuff); Console.WriteLine("a:"+a+" myStuff.number:"+myStuff.number); } }
a:3 myStuff.number:4
Given the following code, which of the below definitions for a child class ChocolateBar is valid: class CandyBar { private double cost; private string manufacturer; private string name; public CandyBar(double c, string m, string n) { cost=c; manufacturer=m; name=n; } public double getcost() { return cost; } }
class ChocolateBar : CandyBar { private string chocolatetype; public ChocolateBar(double c, string m, string n) : base(c,m,n) { chocolatetype="Milk"; } }
What does the following code output? char[] letters=new char[5]; letters[0]='a'; letters[1]='b'; letters[2]='c'; letters[3]='d'; letters[4]='e'; String x=""; for(int i=4;i>=2;i--) { x+=letters[i]; } Console.WriteLine(x);
edc
The keyword used to inherit a class or abstract class is A. extend (Java) or || (C#) B. inherit (Java) or || (C#) C. implements (Java) or : (C#) D. extends (Java) or : (C#)
extends (Java) or : (C#)
For what values respectively of the variables gender and age would the expression gender == 1 && age >= 65 become true? A. gender=1, age=50 B. gender=2, age=70 C. gender=1, age=65 D. gender=1, age=60
gender=1, age=65
Which of the following are valid variable declarations: (Select ALL that are correct) int a=7; long b=-2; char c="Y"; float d=17.2f; double e=9; Java: boolean f=0; C#: bool f=0; Java: boolean g=true; C#: bool g=true;
int a=7; long b=-2; float d=17.2f; double e=9; Java: boolean g=true; C#: bool g=true;
Given the following code: public static int question(int m) { if(m==0) { return 1; } else { return m*question(m-2); } } Which of the following calls will cause infinite recursion? A. int x=question(10); B. int x=question(11); C. int x=question(0); D. int x=question(-2);
int x=question(11); int x=question(-2); B and D will cause infinite recursion.
The relationship between a parent class and a child class is referred to as a(n) ________ relationship. A. instance-of B. has-a C. is-a D. alias
is-a
According to the following UML, if a new object of B is created in main as follows: B myB = new B(); Which of the following statements is NOT valid in main?
myB.do_stuff3();
Why does the following code not compile? public class XYZ { private int myNum; public XYZ() { myNum=0; } public XYZ (int n1) { myNum = n1; } } public class ABC : XYZ { private int num2; public ABC() { myNum=0; num2=0; } public ABC (int n1) { myNum = n1; num2 = n1*2; } } class MainClass { public static void Main (string[] args) { ABC myABC= new ABC(); } }
myNum is defined as private in XYZ and as such is inaccessable in ABC
What is the output of the following code? class Stuff { public int number=1; } class MainClass { public static void Main (string[] args) { Stuff myStuff = new Stuff(); myStuff.number+=3; Console.WriteLine("myStuff.number:"+myStuff.number); myStuff = new Stuff(); Console.WriteLine("myStuff.number:"+myStuff.number); } }
myStuff.number:4 myStuff.number:1
The following is the code to play a guessing game. It will keep prompting until the user guesses the correct answer (50). While the user is guessing it'll count how many attempts it took the user to guess correctly. When the user correctly guesses the number, it outputs the number of guesses it took. What is the correct recursive statement that is missing from guess_num() method? using System; class MainClass { public static int guess_num(int answer,int tries) { Console.WriteLine("Guess a number"); string rawguess=Console.ReadLine(); int guess=Int32.Parse(rawguess); if(guess==answer) { Console.WriteLine("Correct"); return tries; } else { //What goes here? } } public static void Main (string[] args) { int guesses=guess_num(50,1); Console.WriteLine("It took you "+guesses+" guesses"); } }
return guess_num(answer,tries+1);
Assume you have a file called a.txt with the following content : jane,100tim,80janet,40 What is the output of the following code: using System; using System.Collections.Generic; using System.IO; class Score { public string name; public int theScore; public Score(string name, int theScore) { this.name=name; this.theScore=theScore; } } class MainClass { public static void Main (string[] args) { List<Score> scoreCard = new List<Score>(); try { StreamReader sf = new StreamReader("a.txt"); while(! sf.EndOfStream) { string line=sf.ReadLine(); string[] parts=line.Split(","); Score newScore = new Score(parts[0],Int32.Parse(parts[1])); scoreCard.Add(newScore); } } catch(IOException e) { Console.WriteLine(e.Message); } Console.WriteLine(scoreCard[1].name); } }
tim
What is the output of the following code? class MainClass { public static int dostuff(int y) { return y+=5; } public static void Main (string[] args) { int x=5; for(int i=0;i<2;i++) { x=dostuff(x); } Console.WriteLine("x:"+x); } }
x:15
What is the output of the following code? class MainClass { public static int dostuff(int y) { return y+=5; } public static void Main (string[] args) { int x=5; for(int i=0;i<2;i++) { x=dostuff(x); } Console.WriteLine("x:"+x); } } A. x:15 B. x:20 C. x:5 D. x:10
x:15