# Illegal Start Of Expression

Page 1 of 1

## 2 Replies - 1421 Views - Last Post: 09 October 2010 - 10:39 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=194203&amp;s=73a8c3c25a489ea4e75174c70371b305&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 psycy08

Reputation: 0
• Posts: 8
• Joined: 09-October 10

# Illegal Start Of Expression

Posted 09 October 2010 - 09:27 AM

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("[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("[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.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.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("[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("[2]-Hexdaecimal to Binary");
System.out.println("[4]-Exit");
}
int v = input.nextInt();

if(v==1)
{
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!!!!

Is This A Good Question/Topic? 0

## Replies To: Illegal Start Of Expression

### #2 Brewer

• Awesome

Reputation: 182
• Posts: 1,044
• Joined: 14-June 10

## 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 b0ng01

Reputation: 38
• Posts: 169
• Joined: 16-July 10

## 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.
```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