Question

In: Computer Science

1) Ask the user for a dividend and a divisor both of "int" type. 2) Computes...

1) Ask the user for a dividend and a divisor both of "int" type.

2) Computes the remainder of the division. The quotient (answer) must be of the "int" type.

Do NOT use the method " % " provided in Java in your code. Remember that it gives wrong answers when some of the inputs are negative.

Solutions

Expert Solution

import java.util.Scanner;

public class ModuleOp {
   public static void main(String[] args) {
       Scanner sc = new Scanner(System.in);
       // reading dividend from user
       System.out.println("Enter dividend ");
       int dividend = sc.nextInt();
       // reading divisor from user
       System.out.println("Enter divisor ");
       int divisor = sc.nextInt();
       // printing the reminder using % operator
       System.out.println("Reminder : " + (dividend / divisor));
       sc.close();
   }
}


Related Solutions

Create a Java method that does the following: 1) Ask the user for a dividend and...
Create a Java method that does the following: 1) Ask the user for a dividend and a divisor both of "int" type. 2) Computes the remainder of the division. The quotient (answer) must be of the "int" type. Do NOT use the method " % " provided in Java in your code. Remember that it gives wrong answers when some of the inputs are negative. Please see the videos for the explanation.
7. Ask the user to type in a number and compare this number with 8. The...
7. Ask the user to type in a number and compare this number with 8. The user could try twice. If the first user input was 8 then print out “Correct!” and terminate the program, otherwise ask user to type in a number for the second time. If the second input was 8 then print out “Correct”, otherwise print “Game over!” Finish the assembly code segment for the above requirement. .data message: .asciiz "Please enter a random number:" right_str: .asciiz...
in java Write a while loop to ask the user to type number of hours(double) they...
in java Write a while loop to ask the user to type number of hours(double) they work per day. Calculate and print the salary for each valid input. If number of hours is greater than or equal to 0 and less than 5, then:  salary = numberofhours * 5, loop continues, the user can type another number If number of hours is greater or equal to 5, and less than 10, then: salary = numberofours * 8, loop continues, the user...
Write a while loop to ask the user to type number of hours(double) they work per...
Write a while loop to ask the user to type number of hours(double) they work per day. Calculate and print the salary for each valid input. If number of hours is greater than 0 and less than 5, then:  salary = numberofhours * 12, loop continues, the user can type another number If number of hours is greater or equal to 5, and less than 12, then: salary = numberofours * 14, loop continues, the user can type another number If...
Is it possible to minimize both the type 1 error and the type 2 error at...
Is it possible to minimize both the type 1 error and the type 2 error at the same time? Why or why not?
1. Write a program that will ask the user to enter a character and then classify...
1. Write a program that will ask the user to enter a character and then classify the character as one of the following using only IF-ELSE and logical operators. (50 points - 10pts for syntax, 10pts for commenting and 30pts for successful execution) • Integer • Lower Case Vowel • Upper Case Vowel • Lower Case Consonant • Upper Case Consonant • Special Character
Write java program that will ask for the user for 2 input lines and print out...
Write java program that will ask for the user for 2 input lines and print out all words that occur 1 or more times on both lines (case sensitive). Write this without arrays and method. Here is a sample run: <Output> Enter two lines to process. The quick brown fox jumps over a lazy dog The fox hound outruns the lazy dog The words that occur on both lines are: The fox lazy dog
1) Consider the following Java method. Which term best describes what this method computes? static int...
1) Consider the following Java method. Which term best describes what this method computes? static int doSomething(int[] a) {     int b = a[0];     for (int c : a) if (b > c) b = c;     return b; } a. average b. maximum c. minimum d. sum e. transpose 2) Consider the following Java program, what starts on line 2? 1 public class HelloWorld { 2     // My first program! 3     public static void main(String[] args) { 4        ...
In Java: int[] A = new int[2]; A[0] = 0; A[1] = 2; f(A[0],A[A[0]]); void f(int...
In Java: int[] A = new int[2]; A[0] = 0; A[1] = 2; f(A[0],A[A[0]]); void f(int x, int y) { x = 1; y = 3; } For each of the following parameter-passing methods, saw what the final values in the array A would be, after the call to f. (There may be more than one correct answer.) a. By value. b. By reference. c. By value-result.
In MatLab 1. Ask the user to enter a 1 x 5 vector of numbers. Determine...
In MatLab 1. Ask the user to enter a 1 x 5 vector of numbers. Determine the size of the user entry. 2. Ask the user to enter a 1 x 5 vector of numbers. Determine the size of the user entry. If the user enters a 5 x 1 vector, use a warning statement to inform the user of their error, and set the new input value to be the transpose of the user input value. If the user...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT