Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

How to put Method in my code? so i can choose which to operate

$
0
0
How i can put method so i can choose which one of the three i can operate.

import java.lang.*;
import java.io.*;
import java.util.*;

	class Mp{

		public static void DecimalToBinary(String args[]) throws IOException{
			BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
			System.out.println("Enter the Decimal Value: ");
			String bin = bf.readLine();
			int i = Integer.parseInt(bin);  
			String str = Integer.toBinaryString(i);
			System.out.println("The Binary Value is: " + str);	
	}
	
		public static void DecimalToOctal(String args[]) throws IOException{
			BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
			System.out.println("Enter the Decimal Value: ");
			String octa = bf.readLine();
			int i = Integer.parseInt(octa);
			String str = Integer.toString(i,8);
			System.out.println("The Octal Value is: " + str);
	}
	
		public static void DecimalToHexa(String args[]){
			Scanner in = new Scanner(System.in);
			System.out.println("Enter the Decimal Value: ");
			int i = in.nextInt();
			String str = Integer.toHexString(i);
			System.out.println("The Hexa Value is: " + str);
	}
		
		public static void main(String args[]){
			System.out.println("Select an Option: ");
			System.out.println("1 - DecimalToBinary");
			System.out.println("2 - DecimalToOctal");
			System.out.println("3 - DecimalToHexa");


	}
}


Viewing all articles
Browse latest Browse all 51036

Trending Articles