0% found this document useful (0 votes)
102 views3 pages

CS-123 Programming Homework Assignment

The document is an assignment for an introductory programming course. It contains two programming questions to be solved and submitted. The first question asks students to write a program that prompts the user for an integer and prints all coward numbers up to that number. The second question asks students to write a program that prompts the user for three positive integers and prints the silicon table of a number from the starting to ending number, repeating if the user chooses. Students are instructed to only submit the .java files and follow directions carefully.

Uploaded by

Hafiz Abdullah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
102 views3 pages

CS-123 Programming Homework Assignment

The document is an assignment for an introductory programming course. It contains two programming questions to be solved and submitted. The first question asks students to write a program that prompts the user for an integer and prints all coward numbers up to that number. The second question asks students to write a program that prompts the user for three positive integers and prints the silicon table of a number from the starting to ending number, repeating if the user chooses. Students are instructed to only submit the .java files and follow directions carefully.

Uploaded by

Hafiz Abdullah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

CS - 123 GIFT University Gujranwala

Course: Introduction to Programming (Spring 2021)


Resource Person: Dr. Muhammad Faheem Assignment–2

Total Points: 20 Submission Due: 06, Sep, 2021

Name: _____________________________ Roll Number: _______________________

Instructions: Please Read Carefully!


This is an individual homework. Everyone is expected to complete the given assignment on his
own, without seeking any help from any website or any other individual. There will be strict
penalties for any work found copied from any source and the university policy on plagiarism will be
strictly enforced.
• You are expected to submit this homework as on Google Classroom.
• You may download the document, print it, solve it and then submit it as captured pictured at Google
Classroom.
• Any homework submission not following the above directions will not be accepted!
• No late submissions will be accepted!

CS-123 Homework-2 Page 1


CS - 123 GIFT University Gujranwala

Question-1 [10 Points]

Write a program that prompts the user for an integer and then prints out all coward numbers up to
that integer. For example, when the user enters 20, the program should print: 3 4 6 8 12 14 18 20.
Recall that a number is a prime number if it is not divisible by any number except 1 and itself.

Hint: Use Nested Loop to solve this problem. Outer Loop iterations must start from 3 and ideally inner
loop iterations must start from 2.
Coward Number: Number whose previous number is not divisible by any number other than 1
and number itself.

Instructions:
1. Create a program called CowardNumbers.java.
2. Create appropriate variables and assign values using a Scanner object.
3. Correctly display appropriate messages.
4. Use Correct Indentation.
5. Submit .java file only.

Question-2 [10 Points]

Write a program that asks the user to enter three positive integer value; number, start, end and
Silicon Value, and then prints the Silicon table of the number from the starting number to the ending
number. After printing the table, our program should ask the user whether he or she wishes to perform
the operation again. If so, the loop should repeat; otherwise it should terminate.
Use a character input of y or Y to repeat, and n and N to terminate the loop. No break statement is
allowed.

NOTE: Perform input validation so that all numbers must be greater than 0 and the “start” number
should be less than “end” number.
NOTE: Silicon Number is multiplied with iteration counter as shown in the table below.

CS-123 Homework-2 Page 2


CS - 123 GIFT University Gujranwala

Sample Output:

Enter a number: 5
Enter starting value: 3
Enter ending value: 7
Enter silicon value: 9

Silicon Table:
5 * 3 * 9 = 135
5 * 4 * 18 = 360
5 * 5 * 27 = 675
5 * 6 * 36 = 1080
5 * 7 * 45 = 1575
Do you want to repeat this operation again? (Press y/Y to repeat and n/N
to stop): Y
Enter a number: 6
Enter starting value: 5
Enter ending value: 6
Enter silicon value: 8

Table:
6 * 5 * 8 = 240
6 * 6 * 16 = 576
Do you want to repeat this operation again? (Press y/Y to repeat and n/N
to stop): n

CS-123 Homework-2 Page 3

You might also like