🔒 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
  • 534
    Views
  • 3
    Participants
Last reply from:
LadyShizune

Trending Topics

Online now

Members online
362
Guests online
3,424
Total visitors
3,786

Forum statistics

Threads
2,331,971
Posts
29,261,465
Members
1,147,943
Latest member
Jrob30
Back
Top