Illegal Start Of Expression

Someone help to find out my error..THX

Page 1 of 1

2 Replies - 988 Views - Last Post: 09 October 2010 - 10:39 AM Rate Topic: -----

#1 psycy08  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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("[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!!!!

Is This A Good Question/Topic? 0
  • +

Replies To: Illegal Start Of Expression

#2 Brewer  Icon User is offline

  • Awesome
  • member icon

Reputation: 179
  • View blog
  • 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);

Was This Post Helpful? 0
  • +
  • -

#3 b0ng01  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 38
  • View blog
  • 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

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1