🔒 Closed Help programming

Status
Not open for further replies.
// Jvdroid-main: DecimalToBinary

//Superclass
import java.util.*;

public class DecimalToBinary
{
private int bin = 0;
private int oct = 0;
private int hex = 0;
private int text = 0;
public void main()
{
Scanner input = new Scanner(System.in);

System.out.print("Enter a number: ");
this.text = input.nextInt();


if (text <= 0)
{
System.out.println("INVALID!");
}else {
System.out.print("This is the binary representation:");
System.out.print(Integer.toBinaryString (text)+" \n");
System.out.print("This is the octal representation:");
System.out.print(Integer.toOctalString (text)+"\n");
System.out.print("This is the hexadecimal representation:");
System.out.print(Integer.toHexString (text)+"\n");

}
}
public int bin(){
return this.bin;
}
public int oct(){
return this.oct;
}
public int hex(){
return this.hex;
}
}

//subclass

public class DecimalToBinaryImplementation
{
public static void main (String[] args)
{
System.out.println("\tDECIMAL to BINARY");
DecimalToBinary dtb = new DecimalToBinary();
dtb.main();


}
}
 
boss eto ang code....bale issue mo is dalawa ang public class which tends na malilito kung sino ang totoo sa kanila(parang among us) so eto final code:


import java.util.*;

public class DecimalToBinary
{
private int bin = 0;
private int oct = 0;
private int hex = 0;
private int text = 0;
public void main()
{
Scanner input = new Scanner(System.in);

System.out.print("Enter a number: ");
this.text = input.nextInt();

if (text <= 0)
{
System.out.println("INVALID!");
}else {
System.out.print("This is the binary representation:");
System.out.print(Integer.toBinaryString (text)+" \n");
System.out.print("This is the octal representation:");
System.out.print(Integer.toOctalString (text)+"\n");
System.out.print("This is the hexadecimal representation:");
System.out.print(Integer.toHexString (text)+"\n");

}
}
public int bin(){
return this.bin;
}
public int oct(){
return this.oct;
}
public int hex(){
return this.hex;
}

//subclass


public static void main (String[] args)
{
System.out.println("\tDECIMAL to BINARY");
DecimalToBinary dtb = new DecimalToBinary();
dtb.main();


}
}
 
Status
Not open for further replies.

About this Thread

  • 3
    Replies
  • 497
    Views
  • 3
    Participants
Last reply from:
LadyShizune

Online now

Members online
971
Guests online
2,316
Total visitors
3,287

Forum statistics

Threads
2,276,141
Posts
28,967,846
Members
1,231,131
Latest member
Yrrojan
Back
Top