Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Java question 1. name and briefly describe three possible error scenarios that c

ID: 3803385 • Letter: J

Question

Java question

1. name and briefly describe three possible error scenarios that could exist when a program writes , or attempts to write , data to a file.

2.

Rewrite the following if statement, using a switch statement.
selection - scanner.nextlnto:

if (selection - - 0)

System.out.println(“Magenta“):

else if (selection - - 1)

System.out.println(“Cyan“):

else if (selection - - 2)

System.out.println(“Red"):

else

System.out.println(“Invalid selection“)

3.

What will be the value of sum after the following nested loop is executed?
sum = 0;
j = 0;

do {

j++;

for(int i =5; j ; i--);

}
} while (i < 5);

j =5;
while (i !- j)

sum + = j;
j--;

}

i++

}

A) 50
B) 55
C) 60
D) 65

4.

What will be the output from the following code?
class Q2Main {
public static void main( String[] args) {
QuestionTwo q2;
q2 - new QuestionTwo()
q2.init():
q2.incremento();
q2.incremento();
System.out.println( q2.getCounto());

}

}

class QuestionTwo {
private int count:
public void initl () {
count - 1;

}

public void increment(
count - count + 1;

}

public int getCountO
return count;

}

}

A) 1
B) 2
C)3
D) 4
E) 5

5.

What is the problem with the following code?
for (int i = 10; i > 0; i++)

{

int x = 0;
int y = O;
int a = 1;
int b =1;
x = y;
a = b;

}

A)The for loop never gets executed.
B) The program flow forms an endless loop.
C) The i variable is never initialized.
D) No problem exists in the code.

Explanation / Answer

1. name and briefly describe three possible error scenarios that could exist when a program writes , or attempts to write , data to a file.
a) File does not exists
b) File is corrupted
c) Invalid file format
d) Unable to open a file


2) selecttion = scanner.nextInt();
switch(selection){
case 1 :

System.out.println(“Magenta“):
break;

case 2 :
System.out.println(“Cyan“):
break;

case 3 :
System.out.println(“Red“):
break;
default :

System.out.println(“Invalid Selection“):
break;

}

3) Write correct code, Code is Incomplete with lot of sysntax errors [if you could do that I will give u answer in comments]
4) A) 1
5)
B) The program flow forms an endless loop.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote