java codes

profileete08
Assignment2.docx

Pg. 04

خطأ! استخدم علامة التبويب "الصفحة الرئيسية" لتطبيق Heading 1 على النص الذي ترغب في أن يظهر هنا.

Assignment #

Deadline: Thursday 09/04/2020 @ 23:59

[Total Mark for this Assignment is 5]

Computer Programming I

CS140

https://www.seu.edu.sa/sites/ar/SitePages/images/logo.png

College of Computing and Informatics

Question One

1.5 Marks

Learning Outcome(s): LO4

Develop a program based on specification using programming language elements including syntax, data types, conditional statement, control structures, procedures and arrays.

Write a Java program that:

· Asks the user to enter three numbers of type int.

· Print “The user name”: if the second number is greater than the first number and the third number is greater than the second number.

· Print “The user ID”: if the sum of the three integer numbers is even number. Otherwise print: “Try another numbers”.

Important notes:

1. You should have to copy and paste the Java as your answer for this question. DON’T take screen shot for your Java Code. It must be editable.

2. Take a screen shot for your output and paste it as a part of your answer by using your own name and ID.

The following are examples of the output:

Question Two

1.5 Marks

Learning Outcome(s): LO4

Develop a program based on specification using programming language elements including syntax, data types, conditional statement, control structures, procedures and arrays.

Write a program that does the following:

· Asks the user to insert a text line.

· Print each letter in a separate line. For each letter, you should print both capital and small letter.

· If there is a space, print any symbol such as (*, -, @).

Important notes:

3. You should have to copy and paste the Java as your answer for this question. DON’T take screen shot for your Java Code. It must be editable.

4. Take a screen shot for your output and paste it as a part of your answer by using your own full name as an input.

Program typical runs:

Question Three

1 Mark

Learning Outcome(s): LO4

Develop a program based on specification using programming language elements including syntax, data types, conditional statement, control structures, procedures and arrays.

Identify the type of errors in the given code snippet, give the reason for the error correct the errors in the table.

Statement

Type of error (runtime or compiler)

Reason

Corrected statement

i = 5;

while (i<0)

{

System.out.println(i);

i- -;

}

n = 6;

while (n>0);

{

System.out.println(n);

n- -;

}

for (i=0;i!=9;i=i+2)

for(i=0; i>=5;i- -)

Question Four

1 Mark

Learning Outcome(s): LO1

Explain the basic principles of programming, concept of language. Universal constructs of programming languages.

Write down the JAVA statements to do the following in both Arrays and Array Lists.

a) Declare a collection of 10 integers in Arrays and Array Lists.

Use your name for the array and Array list name.

b) Output the value of the tenth element of the array and array list. c) Set the value of the fifth element of the array and array list to 35. d) Set the value of the ninth element of the array and array list to the sum of the sixth and 8th elements of the array and arraylist.