Write a Java Program That Has a Class Called Number System


Number System


write a java program that has a class called number system,write a java program that has a class called number system make functions for tobinary tooctal tohexadecimal

import java.util.Scanner;

class Numbersystem{

void toBinary(int n){

System.out.println(Integer.toBinaryString(n));

}

void toOctal(int n){

System.out.println(Integer.toOctalString(n));

}

void toHexadecimal(int n){

System.out.println(Integer.toHexString(n));

}

}

class Q7{

public static void main(String args[]){

Numbersystem s=new Numbersystem();

int n;

Scanner sc=new Scanner(System.in);

System.out.println("\nEnter decimal value: ");

n=sc.nextInt();

if(n<0 || n>9)

{

System.out.println("Please enter valid decimal number!!");

}

else

{

System.out.println("\n-------------------------------------------");

System.out.println("                   ANS                     ");

System.out.println("-------------------------------------------");

System.out.println("Decimal to Binary:");

s.toBinary(n);

System.out.println("Decimal to Octal:");

s.toOctal(n);

System.out.println("Decimal to Hexadecimal:");

s.toHexadecimal(n);

System.out.println("-------------------------------------------");

System.out.println("-------------------------------------------");

}

}

}

Polygon Relative In Computer Graphics

Bresenham Algorithm for Endpoints (-1, 7) to (5, 9)

Comment your views on this Article :)


Thank you for visiting my blog :)

No comments

Comment your views on this article

Powered by Blogger.