Question
Write JAVS program that prompts the user to enter a positive integer which is greater than one and displays all its smallest factors in decreasing
Write JAVS program that prompts the user to enter a positive integer which is greater than one and displays all its smallest factors in decreasing order. For example, if the integer is 140, the smallest factors are displayed as 7, 5, 2, 2. Use the StackOfIntegers class to store the factors (e.g., 2, 2, 5, 7) and retrieve and display them in reverse order. After that, write a program that displays all the prime numbers less than the number which is used in the prime factors (e.g: 140) in decreasing order.
Use the StackOfIntegers class to store the prime numbers (e.g., 2, 3, 5, ...) and retrieve and display them in reverse order. Here is the sample runs: To use the prime factors you must enter a positive integer which is greater than one: 140 7 5 2 2 Printing prime numbers under 140: 139 137 131 127 113 109 107 103 101 97 89 83 79 73 71 67 61 59 53 47 43 41 37 31 29 23 19 17 13 11 7 5 3 2
(Use the GregorianCalendar class) Java API has the Date class and GregorianCalendar class in the java.util package, which you can use to obtain the current date with specific details like current year, current month, current day of a date and so on. Write a program to perform these tasks: 1- Display the current year, month, and day. 2- Display the current date by using the toString() method from the Date class. 3- Display the current time which is used to display the number of milliseconds by using getTime() method from the Date class. We will use it in the step 17. 4- Display the current year by using get(GregorianCalendar.YEAR) method from the GregorianCalendar class. 5- Display the current year by using get(GregorianCalendar.MONTH) method from the GregorianCalendar class. Note: this method which is used for month starts from 0 to 11 (0 indicates January). You must take care about this issue for adding 1 in order to display 1 for January. 6- Display the current Day by using get(GregorianCalendar.DAY_OF_MONTH) method from the GregorianCalendar class.7- Display the current Week by using get(GregorianCalendar.DAY_OF_WEEK) method from the GregorianCalendar class. 8- Display the current DAY OF WEEK IN MONTH by using get(GregorianCalendar.DAY_OF_WEEK_IN_MONTH) method from the GregorianCalendar class. 9- Display the current Day of Year by using get(GregorianCalendar.DAY_OF_YEAR) 10- Display the current Hour by using get(GregorianCalendar.HOUR) 11- Display the current Hour of day by using get(GregorianCalendar.HOUR_OF_DAY) 12- Display the current MINUTE by using get(GregorianCalendar.MINUTE) 13- Display the current Second by using get(GregorianCalendar.SECOND) 14- Display the current Millisecond by using get(GregorianCalendar.MILLISECOND) 15- Display the current Week of month by using get(GregorianCalendar.WEEK_OF_MONTH) 16- Display the current Week of year by using get(GregorianCalendar.WEEK_OF_YEAR) 17- Finally, use setTime() method which sets your current time (Step 3) and display your date and time using the toString() method after adding these milliseconds (In for loop): 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000, 10000000000, and 100000000000.
Here is the sample run:
Current Date: Mon Jan 07 11:05:17 AST 2019
Current time (the number of milliseconds): 1546848317397
Current Year: 2019
Current Month: 1
Current Day: 7
Current Week: 2
Current DAY OF WEEK IN MONTH: 1
Current Day of Year: 7
Current Hour: 11
Current Hour of day: 11
Current MINUTE: 5
Current Second: 17
Current Millisecond: 470
Current Week of month: 2
Current Week of year: 2
The time after adding 1 millisecond(s) : Mon Jan 07 11:05:17 AST 2019
The time after adding 10 millisecond(s) : Mon Jan 07 11:05:17 AST 2019
The time after adding 100 millisecond(s) : Mon Jan 07 11:05:17 AST 2019
The time after adding 1000 millisecond(s) : Mon Jan 07 11:05:18 AST 2019
The time after adding 10000 millisecond(s) : Mon Jan 07 11:05:27 AST 2019
The time after adding 100000 millisecond(s) : Mon Jan 07 11:06:57 AST 2019
The time after adding 1000000 millisecond(s) : Mon Jan 07 11:21:57 AST 2019
The time after adding 10000000 millisecond(s) : Mon Jan 07 13:51:57 AST 2019
The time after adding 100000000 millisecond(s) : Tue Jan 08 14:51:57 AST 2019
The time after adding 1000000000 millisecond(s) : Sat Jan 19 00:51:57 AST 2019
The time after adding 10000000000 millisecond(s) : Fri May 03 04:51:57 AST 2019
The time after adding 100000000000 millisecond(s) : Wed Mar 09 20:51:57 AST 2022
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started