import java.util.Scanner;
public class Project
{
public static void main(String[] args)
{
Scanner input=new Scanner(System.in);
String x;
System.out.println("[1]-Binary Number System");
System.out.println("[2]-Octal Number System");
System.out.println("[3]-Hexadecimal Number System");
System.out.println("[4]-Exit");
System.out.println("Enter Option: ");
x = input.next();
if(x==1)
{
System.out.println("[1]-Binary to Decimal");
System.out.println("[2]-Binary to Octal");
System.out.println("[3]-Binary to Hexadecimal");
System.out.println("[4]-Exit");
}
int y=input.nextInt();
if (y==1)
{
System.out.print("Enter the Binary Number: ");
String str = input.next();
long num = Long.parseLong(str);
long rem;
while(num > 0)
{
rem = num % 10;
num = num / 10;
if(rem != 0 && rem != 1)
{
System.out.println("This is not a binary number.");
System.out.println("Please try once again.");
System.exit(0);
}
}
int i= Integer.parseInt(str,2);
System.out.println("In Decimal:="+ i);
}
if (y==2)
{
System.out.println("Enter a Binary Number:");
String oct=input.next();
long rem;
int num = Integer.parseInt(oct,2);
System.out.println("In Octal:=" + Integer.toString(num,8));
}
if (y==3)
{
System.out.println("Enter the Binary Number:");
String hex = input.next();
long num = Long.parseLong(hex);
long rem;
while(num > 0)
{
rem = num % 10;
num = num / 10;
if(rem != 0 && rem != 1)
{
System.out.println("This is not a binary number.");
System.out.println("Please try once again.");
System.exit(0);
}
}
int i= Integer.parseInt(hex,2);
String hexString = Integer.toHexString(i);
System.out.println("In Hexa decimal:=" + hexString);
}
if(x==2)
{
System.out.println("[1]-Octal to Decimal");
System.out.println("[2]-Octal to Binary");
System.out.println("[3]-Octal to Hexadecimal");
System.out.println("[4]-Exit");
}
int z = input.nextInt();
if(z == 1)
{
System.out.println("Enter Octal value:");
String oct=input.next();
int dec=convertToDecimal(oct);
if (dec != -1)
System.out.println("Octal: " + oct + " is in decimal " + dec);
static int convertToDecimal(String octo);//THIS IS WHERE MY PROBLEM IS..ILLEGAL START OF Expression!!PLEASE HELP ME ON FINDING OUT THIS DAMN ERRROR..THANK YOU
{
int number = 0;
for(int i = 0; i < octo.length(); i++)
{
char digit = octo.charAt(i);
digit -= '0';
if(digit < 0 || digit > 7)
{
System.out.println("This is not a Octal Number:");
return -1;
}
number *= 8;
number += digit;
}
return number;
}
}
if(x==3)
{
System.out.println("[1]-Hexadecimal to Decimal");
System.out.println("[2]-Hexdaecimal to Binary");
System.out.println("[3]-Hexadecimal to Octal");
System.out.println("[4]-Exit");
}
int v = input.nextInt();
if(v==1)
{
System.out.println("Enter the Hexadecimal Number:");
String hx=input.next();
int i=Integer.parseInt(hx,16);
System.out.println("In Decimal:=" + i);
}
else
System.out.println("Exit");
}
}
//I HAVE An error,, ILLEGAL START OF Expression IN (STATIC INT CONVERTTODECIMAL(STRING OCTO)
I REALLY HAVING A HARD TIME FINDING THE ERROR..REALLY GLAD TO HEAR YOUR HELP!!!THANK YOU!!!!
Illegal Start Of ExpressionSomeone help to find out my error..THX
Page 1 of 1
2 Replies - 777 Views - Last Post: 09 October 2010 - 10:39 AM
Replies To: Illegal Start Of Expression
#2
Re: Illegal Start Of Expression
Posted 09 October 2010 - 09:31 AM
Pretty simple solution, all you need to do is close this if statement. You forgot the closing '}'. Hope this helped!
if(z == 1)
{
System.out.println("Enter Octal value:");
String oct=input.next();
int dec=convertToDecimal(oct);
if (dec != -1)
System.out.println("Octal: " + oct + " is in decimal " + dec);
#3
Re: Illegal Start Of Expression
Posted 09 October 2010 - 10:39 AM
1. Use"[ code]" "[/code]" tags. It makes it much easer to read your code.
2. Don't do the, I am so excited thing "Ie... Don't type in all caps"
3.
remove the semicolon.
2. Don't do the, I am so excited thing "Ie... Don't type in all caps"
3.
static int convertToDecimal(String octo);//THIS IS WHERE MY PROBLEM IS..ILLEGAL START OF
remove the semicolon.
This post has been edited by b0ng01: 09 October 2010 - 10:40 AM
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote



|