Starting from:

$35

CSE110- Lab 9 Solved

Objective

So far in these labs, we have learned how to write programs that involve conditionals and iterations. Towards the very beginning of the semester, we looked at variables and how they store values we need for calculations. This week, we will look at a special kind of variable – one that lets us store and access several values under the same name. These types of variables are called arrays. In today’s lab, we will learn more about arrays and then write a few programs using arrays.

Task 1

Write a java program that would input three numbers from the user and print sum, then the first number, then the 2nd number followed by 3rd number. If user enters 10, 20, 30. Then output should be 60, 10, 20, and 30.

Task 2

Write a java program that reads 10 numbers from the user. The program then reads a number between 0 to 9, and shows the number at the corresponding index number. For instance, if the array is a and the user enters 3, your program should print the value a[3].

 

Task 3

Write a java program that reads 10 numbers from the user, and then prints them in the reverse order.

 

Task 4

Write a java program that reads 10 numbers from the user and prints the first odd number in the list.

Task 5

Write a java program that reads 10 numbers from the user and prints the first even number in the list.

Task 6

Write a java program that reads 10 numbers from the user and prints the last odd number in the list.

Task 7

Write a java program that reads 10 numbers from the user and prints the last even number in the list.

Task 8

Write a java program that reads 10 numbers from the user, and then prints only the even numbers in reverse order.

Task 9

Write a java program that reads 10 numbers from the user. Then read another number from the user, and print “yes” if this number exists among the first 10. Print “no” otherwise.

Task 10

Write a java program that reads 10 numbers from the user. After reading each number, print all the numbers that have been entered so far.

After user enters 11, print 11

After user enters 22, print 11, 22



After user enters 99, print 11, 22 ….. 99

Task 11

Write a java program that reads 10 numbers from the user, but does not allow the user to enter duplicates. This means that if a number has been entered already, the program will not accept it as input again and instead ask the user to enter a different number.

 

Task 12

Write a java program that reads 10 numbers from the user, and then prints only the even numbers and their positions in reverse order.

Sample Input:

11  13  12  16  61  40

Sample Output:

40   5

16   3

12   2

 

Task 13

Write a java program that reads 10 numbers from the user, and then separately prints the sum of all the even numbers, odd numbers and numbers divisible by 5.

Sample Input:

11  13  12  10  51  40

Sample Output:

62

75

50

Objective

So far in these labs, we have learned how to write programs that involve conditionals and iterations. Towards the very beginning of the semester, we looked at variables and how they store values we need for calculations. This week, we will look at a special kind of variable – one that lets us store and access several values under the same name. These types of variables are called arrays. In today’s lab, we will learn more about arrays and then write a few programs using arrays.

 

Task 1

Write a java program that would input three numbers from the user and print sum, then the first number, then the 2nd number followed by 3rd number. If user enters 10, 20, 30. Then output should be 60, 10, 20, and 30.

Task 2

Write a java program that reads 10 numbers from the user. The program then reads a number between 0 to 9, and shows the number at the corresponding index number. For instance, if the array is a and the user enters 3, your program should print the value a[3].

Task 3

Write a java program that reads 10 numbers from the user, and then prints them in the reverse order.

Task 4

Write a java program that reads 10 numbers from the user and prints the first odd number in the list.

 

Task 5

Write a java program that reads 10 numbers from the user and prints the first even number in the list.

Task 6

Write a java program that reads 10 numbers from the user and prints the last odd number in the list.

 

Task 7

Write a java program that reads 10 numbers from the user and prints the last even number in the list.

Task 8

Write a java program that reads 10 numbers from the user, and then prints only the even numbers in reverse order.

Task 9

Write a java program that reads 10 numbers from the user. Then read another number from the user, and print “yes” if this number exists among the first 10. Print “no” otherwise.

Task 10

Write a java program that reads 10 numbers from the user. After reading each number, print all the numbers that have been entered so far.

After user enters 11, print 11

After user enters 22, print 11, 22



After user enters 99, print 11, 22 ….. 99 

Task 11

Write a java program that reads 10 numbers from the user, but does not allow the user to enter duplicates. This means that if a number has been entered already, the program will not accept it as input again and instead ask the user to enter a different number.

Task 12

Write a java program that reads 10 numbers from the user, and then prints only the even numbers and their positions in reverse order.

Sample Input:

11  13  12  16  61  40

Sample Output:

40   5

16   3

12   2

Task 13

Write a java program that reads 10 numbers from the user, and then separately prints the sum of all the even numbers, odd numbers and numbers divisible by 5.

Sample Input:

11  13  12  10  51  40

Sample Output:

62

75

50

More products