Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need Help for doing flowchart for the following program: import java.util.Scanner; public class Convert { Scanner scan; int num; void getVal() { scan = new

Need Help for doing flowchart for the following program:

import java.util.Scanner;

public class Convert {

Scanner scan;

int num;

void getVal() {

scan = new Scanner(System.in);

int low, high,i,j,flag=3;

while(true)

{

System.out.println("Enter the low number:");

low = scan.nextInt();

System.out.println("Enter the high number:");

high = scan.nextInt();

if(flag==1)

{

System.out.println("****Resetting low and high ****");

}

System.out.println("Decimal\tBinary\tOctal\tHexadecimal");

for (i=low;i<=high;i++){

System.out.print(i);

num = i;

binary_convert();

oct_convert();

hex_convert();

}

System.out.println("Press 1 if you want to enter another Low and High else press 0 to exit: ");

flag=scan.nextInt();

if(flag==0)

break;

}

}

void hex_convert() {

String hexa = Integer.toHexString(num);

int i=0;

do {

char letter = hexa.charAt(i);

if(letter>='a'&&letter<='z')

letter=(char)((int)letter-(int)'a'+(int)'A');

System.out.print(letter);

i++;

} while (i < hexa.length());

System.out.println("");

}

void oct_convert() {

String oct = Integer.toOctalString(num);

for (int i = 0; i < oct.length(); i++) {

// Get letters with charAt method.

char letter = oct.charAt(i);

System.out.print(letter);

}

System.out.print("\t");

}

void binary_convert() {

System.out.print("\t");

String bin = Integer.toBinaryString(num);

int i=0;

while (i < bin.length()) {

// Get letters with charAt method.

char letter = bin.charAt(i);

System.out.print(letter);

i++;

}

System.out.print("\t");

}

public static void main(String args[]) {

Convert obj = new Convert();

obj.getVal();

}

}

Output:-

Enter the From Value:-

1

Enter the To Value:-

10

1 1 1 1

2 10 2 2

3 11 3 3

4 100 4 4

5 101 5 5

6 110 6 6

7 111 7 7

8 1000 10 8

9 1001 11 9

10 1010 12 A

Enter the From Value:-

10

Enter the To Value:-

15

10 1010 12 A

11 1011 13 B

12 1100 14 C

13 1101 15 D

14 1110 16 E

15 1111 17

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database And Transaction Processing

Authors: Philip M. Lewis, Arthur Bernstein, Michael Kifer

1st Edition

0201708728, 978-0201708721

More Books

Students also viewed these Databases questions