Task 4: Integer and Floating Point Division
Open Division.java and write code to solve the following problem:
1. prompts for and reads in an integer (on the same line)
2. Outputs:
i) the value of the number divided by 100 as a floating point value
ii) the remainder when the number is divided by 100
iii) the number of times 100 divides the integer
iv) outputs the digits of the integer in reverse order; i.e., each digit must be extracted
arithmetically.
You may assume the number is less than 10000.
Here are some examples of how your program should behave (user input is in bold):
Example 1
Enter an integer: 1534
15.34
34
15
4351
Example 2
Enter an integer: 403
4.03
34
304
Example 3
Enter an integer: 4
0.04
404
Hint: 1534 % 10 has a value of 4 and 1534 / 10 has a value of 153.
import java.util.Scanner;
public class Division {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
// declare any variables here
// Output the values here.
}
}
Outputs of Example 2 and 3 are wrong as they do not follow your given output guidelines.
import java.util.Scanner;
public class Division {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter an Integer: ");
int n = sc.nextInt();
System.out.println((float)n/100);
System.out.println(n%100);
System.out.println(n/100);
System.out.println(reverseInt(n));
sc.close();
}
public static int reverseInt(int n) {
int rev = 0;
while(n > 0) {
rev = rev*10 + n%10;
n = n/10;
}
return rev;
}
}
Output:
1-
Enter an Integer: 1534
15.34
34
15
4351
2-
Enter an Integer: 403
4.03
3
4
304
3-
Enter an Integer: 3
0.03
3
0
3
Task 4: Integer and Floating Point Division Open Division.java and write code to solve the following...
Write a while loop that prints userNum divided by 2 (integer division) until reaching 1. Follow each number by a space. Example output for userNum = 40: 20 10 5 2 1 Note: These activities may test code with different test values. This activity will perform four tests, with userNum = 40, then with userNum = 2, then with userNum = 0, then with userNum = -1. See "How to Use zyBooks". Also note: If the submitted code has an...
1. Write a program that prompts the user to enter three integers and display the integers in non-decreasing order. You can assume that all numbers are valid. For example: Input Result 140 -5 10 Enter a number: Enter a number: Enter a number: -5, 10, 140 import java.util.Scanner; public class Lab01 { public static void main(String[] args) { Scanner input = new Scanner(System.in); } } ---------------------------------------------------------------------------------------------------------------------------- 2. Write a program that repeatedly prompts the user for integer values from...
HINT
1)-Write a method to accept n integer number between 0 and 100 and return the average. 2)-Write a method to convert an the letter grade as follow. integer number between 0 and 100 to latter grade A to F and return. 100-90->A 89-80->B 79-70->C 69-60->D 00-59->F 3)-Write a method to compute GPA for following letter grade and return the GPA value. A =>4.0 B ->3.0 C->20 D->1.0 Hint for option 1 1 import java.util.Scanner 2 public class ProjPart2 3...
Java Code please read comments and add the code to required lines....LINE 1 to LINE 5 ********************************************************************** * Program Summary: This program demonstrates these basic Java concepts: * - Creating an array based on user input * - Accessing and displaying elements of the array * * The program should declare an array to hold 10 integers. * The program should then ask the user for an integer. * The program should populate the array by assigning the user-input integer...
Create a DataEntryException class whose getMessage() method returns information about invalid integer data. Write a program named GetIDAndAge that continually prompts the user for an ID number and an age until a terminal 0 is entered for both. If the ID and age are both valid, display the message ID and Age OK. Throw a DataEntryException if the ID is not in the range of valid ID numbers (0 through 999), or if the age is not in the range...
Write a Java program to convert octal (integer) numbers into their decimal number equivalents (exactly the opposite of what you have done in Assignment 4). Make sure that you create a new Project and Java class file for this assignment. Your file should be named “Main.java”. You can read about octal-to-decimal number conversions on wikepedia Assignment 4 is at the bottom Objective Your program should prompt the user to enter a number of no greater than 8 digits. If the...
Write and submit the source code for the following program. The program will use an integer array of size 10 to store the prices of smartphones. It will then determine and print the prices of the most expensive and cheapest phones. Use the following variables: int[] prices = new int[10]; // Array of smartphone prices Assignment Ask the user for the price of each smartphone (using a for loop) Sort the list of smartphones (once) from low to high price...
All information about the question (Task 1 and task 2)
are down below
Programming Assignments
Task 1 –
Page 39. in Programming A Comprehensive
Introduction
Update your program from Assignment 2, Task
#2
Allow the user to input their weight for the earth weight to
moon weight conversion problem. Add an ifstatement
that prompts the user if she inputs 0 or a negative number for her
earth weight.
#13. Mars’ gravity is about 17 percent less
that of the earth’s....
Here is the assignment: Fibonacci or Prime number iterator: Design a menu driven program that performs the user’s choice of the following functions the program exits should also be a user’s choice. Menu Item 1: Fibonacci number iterator, here you are to define an iterator class named FibonacciIterator for iterating Fibonacci numbers. The constructor takes an argument that specifies the limit of the maximum Fibonacci number. For example, prompt the user for size, use the size to call FibonacciIterator(“user input”)...
Step 4: Add code that discards any extra entries at the propmt that asks if you want to enter another score. Notes from professor: For Step 4, add a loop that will validate the response for the prompt question: "Enter another test score? (y/n): " This loop must only accept the single letters of ‘y’ or ‘n’ (upper case is okay). I suggest that you put this loop inside the loop that already determines if the program should collect...