Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

solve this question with (java) language solve this question with (java) languag

ID: 3755443 • Letter: S

Question

solve this question with (java) language

solve this question with (java) language

Exercise:1 Create a new project and name it week4-3 Write a program that read a decimal number between (0-7) and convert in to a binary of three digit and print these digit. » Use an appropriate data type and arithmetic operation, and write an explained comment. Note Conversion steps are: -Divide the number by 2 Get the integer quotient for the next iteration .Get the remainder for the binary digit. - Repeat the steps as the number of binary digit

Explanation / Answer

DigitToBinary.java

import java.util.Scanner;

public class DigitToBinary {

public static void main(String[] args) {

Scanner scan = new Scanner(System.in);

System.out.println("Enter the digit:");

int n = scan.nextInt();

System.out.println("Binary Value: "+convertToBinary(n));

}

public static String convertToBinary(int n){

int x;

if(n > 0){

x = n % 2;

return (convertToBinary(n / 2) + "" +x);

}

return "";

}

}

Output:

Enter the digit:
6
Binary Value: 110

RectangleAreaCalc.java

import java.util.Scanner;

public class RectangleAreaCalc {

public static void main(String[] args) {

Scanner scan = new Scanner(System.in);

System.out.println("Enter the rectangle length:");

double length = scan.nextDouble();

System.out.println("Enter the rectangle width:");

double width = scan.nextDouble();

double area = length * width;

System.out.println("Rectangle Area: "+area);

}

}

Output:

Enter the rectangle length:

5
Enter the rectangle width:
6
Rectangle Area: 30.0