Problem 2: Write a java program that contains: a) The method public static int numberOccurrences(int a, int b) which returns an integer designating the number of appearance of the digit b in the number a. (b must between 0 and 9). b) Write a test program (main) that asks the user to enter an integer number and a digit then invokes (calls) numberOccurrences method.
Problem 2: Write a java program that contains: a) The method public static int numberOccurrences(int a, int b) which returns an integer designating the number of appearance of the digit b in the number a. (b must between 0 and 9). b) Write a test program (main) that asks the user to enter an integer number and a digit then invokes (calls) numberOccurrences method.
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question

Transcribed Image Text:Problem 2: Write a java program that contains:
a) The method public static int numberOccurrences(int a, int b) which returns an integer
designating the number of appearance of the digit b in the number a. (b must between
0 and 9).
b) Write a test program (main) that asks the user to enter an integer number and a digit
then invokes (calls) numberOccurrences method.
Sample run 1:
Enter a number: 11941.
Enter a digit: 1
The number of appearance of 1 in 11941 is 3
Sample run 1:
Enter a number: 257
Enter a digit: 5

Transcribed Image Text:signm
Pilawjian D
points
Class comme
a class comm
Problem 1: A number n is considered to be triangular if we can find a sum of numbers in the range from 1 to n
that is equal to this n. So 10 is triangular because there is a sum resulting in 10: 1+2+3+4=10 and 4 <10,
whereas 5 is not triangular because no sum from 1 to 5 can give 5 (1+2=3 less than 5 and 1+2+3 = 6 greater
than 5).
a- Define a method called is Triangular that verifies if a certain number passed as parameter is triangular or
not. The method header will be as follows:
public static Boolean isTriangular(int num)
b- Implement another method called displayTriangularNumbers that accepts an integer m as parameter and
displays the first 10 triangular numbers starting from m. The method header will be as follows:
public static void display TriangularNumbers (int m)
c- Write a test program that asks the user to enter an integer a and invokes the method
displayTriangularNumbers passing a as argument to the method.
Sample run 1:
Enter an integer: 15
The first 10 triangular numbers starting from 15 are:
15 21 28 36 45 55 66 78 91 105
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 4 steps with 4 images

Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you

Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON

Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education