Before starting the exercises below, make sure you have completed and submitted Practical 1 on moodle.

computer science

Description

Note: Before starting the exercises below, make sure you have completed and submitted Practical 1 on moodle.


Create a “assignment1” folder for the purposes of this practical. For each of the below questions, you are expected to write a Java program (in files called Q1.java – Q9.java), compile and run it from the command line/terminal. Remember indentation and commenting is required!


Write a program that displays the result of:


 


Write a program that displays the result of 


1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9

Write a program that reads a Celsius degree in double from the console, then converts it to Fahrenheit and displays the result. The formula for the conversion is as follows: 

fahrenheit = (9 / 5) * celsius + 32 


Hint: In Java, 9 / 5 is 1, but 9.0 / 5 is 1.8.  

Write a program that reads an integer between 0 and 1000 and adds all the digits in the integer. For example, if an integer is 932, the sum of all its digits is 14.


Write a program that displays the following table (Notice the alignment of the columns, no calculations needed):

a b pow(a, b) 

1 2

2 3 8


3 4 81        

4    5    1024        

5    6    15625



Submission Instructions


Create a zip file containing all of this week’s solutions.


In Windows you can select the “assignment1” folder, right click and choose send to > Compressed (zipped) archive. 


In Mac OS X, you can select the “assignment1” folder, right click and choose Archive. 


Name your zip file in the format of “assignment1 – name – studentnumber.zip”, replacing name and studentnumber with your own name and student number. e.g. “assignment1 – Joe Bloggs – 12123456”.  Upload your zip file using the Assignment 1 submission form available on Moodle.


Instruction Files

Related Questions in computer science category