Practice lab 1

docx

School

University of Technology Sydney *

*We aren’t endorsed by this school

Course

48023

Subject

Computer Science

Date

Oct 30, 2023

Type

docx

Pages

2

Uploaded by Anyoumus

Report
A This lesson has ended. You will not be able to save edits or submit. & Description Fixing simple errors 1 In this exercise we have given you some code that is intentionally flawed. Your job is to fix the code, so that it will compile and run without any errors. @ + < Simplekrrort java @ public class SimpleErrorl { public static void main(String[] args) { System.out.println("Welcome to Java!") 0% Hints » Expand » Expand » Expand /home/SimpleError java Tabs (Auto) Changes will not be saved. Reload @ > Expand Console A~ » Run a + < Multiply.java X% A This lesson has ended. You will not be able to save edits or submit. & Description Changing values 1 For this task you have been given code that asks the user to enter two whole numbers, and stores these in variables a and b. The code creates a third variable ¢, and prints this out. Your task is to set the value of ¢ to be the multiple of a and b. N Al changes that you make should 1 dimport java.util.Scanner; public class Multiply { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print("Enter the first number: "); int a = sc.nextInt(); System.out.print("Enter the second number: int b = sc.nextInt(); int ¢ = 03 //Add your code below here c=axb; //Add your code above here System.out.println(c); ") be after line 14 and before line 18. } Do not make any changes. elsewhere. } /home/Multiplyjava Tabs (Auto) Changes will not be saved. Reload @ Console Terminal S » Run > D% A This lesson has ended. You will not be able to save edits or submit & Description Changing values 2 This time, you have some code that reads in a single value from the user, stores it in a variable called a, then prints out the value of that variable. Your task is to add some code that doubles the value of a after it's read in, but before it's printed out. Y A changes that you make should be after line 11 and before line 15. Do not make any changes elsewhere. a + < Doubler java 1 import java.util.Scanner; public class Doubler { public static void main(String[] args) { Scanner sc = new Scanner (System.in); System.out.print("Enter a number: "); int a = sc.nextInt(); //Add your code here a=2%xa; System.out.println(a); /home/Doubler java Tabs (Auto) Console Terminal A~ Changes will not be saved. Reload @ » Run
A This lesson has ended. You will not be able to save edits or submit. & Description Moving values around Please complete this task in pairs, with one driver and one navigator For this task you have some code which declares and initialises two variables a and b, then prints out their values. Add some code that swaps the values of the two variables. In other words, whatever value is initially stored in a should be stored in b, and whatever value is initially stored in b should be stored in a. a + 1 import java.util.Scanner; < Swap java public class Swap { public static void main(String[] args) { Scanner sc = new Scanner (System.in); System.out.print("Enter the first number: int a = sc.nextInt(); System.out.print("Enter the second number: "); int b = sc.nextInt(); System.out.println("Before swapping, V Vv Vv Add your code here vV vV v int ¢ = a; a=b; b = c; // A A A Add your code here A A A System.out.println("After swapping, a=" + a + " b /home/Swap,java Tabs (Auto) Console N ta+ b= e b) + b) oo H Changes will not be saved. Reload @ » Run A This lesson has ended. You will not be able to save edits or submit. & Description Fixing simple errors 2 Bl Prease complete this taskin pairs, with one driver and one navigator The following code is meant to read in two decimals (e.g. 1.34, 100.35) and print out their sum. However, the programmer wasn't paying too much attention when writing the code and have left 3 mistakes. Find them and fix them! If you are not sure where to start, try running the code first, and see what error messages the compiler gives —vou_Read them carefully they a + £ Mistake java 1 import java.util.Scanner; public class Mistake { public static void main(String[] args) { Scanner sc = new Scanner (System.in); double a = sc.nextDouble(); double b = sc.nextDouble(); System.out.println(a + b); /home/Mistake java Tabs (Auto) Console o Changes will not be saved. Reload @ » Run
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help

Browse Popular Homework Q&A

Q: Fish Kills High concentrations of ammonia (NH3), nitrite ion, and nitrate ion in water can kill…
Q: For what value of c will the system of equations below have no solution? 301 cx-2y=6 3x+4y=4 Nes
Q: A group of geology students traveled to a field camp in the Andes mountains in South America for a…
Q: 5. Consider a simple random walk on the set {0, 1, 2, ..., N} in which each step is to the right…
Q: OA⊥OC and OB⊥OD. Which of the non right angles formed are congruent? Justify your answer.
Q: International Journal of Statistical Distributions (Vol. 1, 2015) study of a variable life insurance…
Q: Which evidence from biological testing would show healthy soil? O A very high concentration of…
Q: The Atlantic slave trade was first and foremost about money. What were some of the important…
Q: Question 1 Which of the following is NOT a criteria used to determine whether a substance is a…
Q: Write the equation of the line fully simplified slope-intercept form. 12 11 10 6, 2 -12-11-10-9 -8…
Q: Calculate the density of HCN a highly poisonous gas at 250 degrees celsius and 2.00 atm pressure.
Q: A regional manager wants to know if there is a difference between the mean amounts of time that…
Q: Chapter 17 Homework PR 17-4A Measures of liquidity, solvency, and profitability The comparative…
Q: Rocks are made up of solid minerals glued together by natural processes.
Q: The amount Q of water emptied by a pipe varies directly as the square of the diameter d. A pipe 2…
Q: 2.10.1. Melissa takes a loan of R950 000 to buy a house. The interest is 14,25% p.a. compounded…
Q: Suppose I hire 50 workers in my factory to produce two things: books and pens. I engage 35 workers…
Q: Let H be the set of all matrices of the form a 1 b b a for a, b E R.
Q: For each of the following, find the value of 'X' H 1. 2. 5 6 12 10 X 20-25
Q: A group of paramedics does not believe that the mean numbers of calls received in one shift are the…
Q: f(x, y) = xy², R = [0, 6] × [−1, 1]
Q: 20. What do you mean by optimal solution?