Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Apr 28th, 2008, 10:58 AM   #1
A.K.Al Shamsi
Programmer
 
A.K.Al Shamsi's Avatar
 
Join Date: Mar 2008
Posts: 35
Rep Power: 0 A.K.Al Shamsi is on a distinguished road
Exclamation Snytax error

good evening (it is 7:53 pm in the place where i live in)

i was writing programme for project and then i snytax error for integers and string and java suggested to import java.lang.String and int i used ( ; ) and it was working prefectly, this was yesterday.... today morning i had snytax error this package, so where is the problem?

the error says (';' expected) but the semi-colon is there... so where is the error?
A.K.Al Shamsi is offline   Reply With Quote
Old Apr 28th, 2008, 11:06 AM   #2
Freaky Chris
Hobbyist Programmer
 
Freaky Chris's Avatar
 
Join Date: Dec 2007
Location: England
Posts: 169
Rep Power: 1 Freaky Chris is on a distinguished road
Send a message via MSN to Freaky Chris
Re: Snytax error

Post the code, you may find that you missed a ';' on the previous line or the statement you have on one line is not quite correct and so it expects a ';' to mark then end of a statement.

But post you're sections of code where you having prblems with a few lines either side.

Chris
__________________
Who said i couldn't program
sarcasm = raw_input('Type in a sarcastic remark: ')
print sarcasm
Freaky Chris is offline   Reply With Quote
Old Apr 28th, 2008, 12:58 PM   #3
A.K.Al Shamsi
Programmer
 
A.K.Al Shamsi's Avatar
 
Join Date: Mar 2008
Posts: 35
Rep Power: 0 A.K.Al Shamsi is on a distinguished road
Re: Snytax error

 import javax.swing.*;
import java.lang.String and int; 

public class ConvertTest{
    
    public static void main(String args[]){
        
        Convert test = new Convert ();

in importing java.lang i got snytax error ( expected ; )
A.K.Al Shamsi is offline   Reply With Quote
Old Apr 28th, 2008, 1:00 PM   #4
Freaky Chris
Hobbyist Programmer
 
Freaky Chris's Avatar
 
Join Date: Dec 2007
Location: England
Posts: 169
Rep Power: 1 Freaky Chris is on a distinguished road
Send a message via MSN to Freaky Chris
Re: Snytax error

it expects a ';' after String, so you would have to place int on a dif import statement. Although am i not right in saying that Java automatically imports the whole java.lang package anyway. Its the only which it does.

Chris
__________________
Who said i couldn't program
sarcasm = raw_input('Type in a sarcastic remark: ')
print sarcasm
Freaky Chris is offline   Reply With Quote
Old Apr 28th, 2008, 1:33 PM   #5
titaniumdecoy
Expert Programmer
 
titaniumdecoy's Avatar
 
Join Date: Nov 2005
Posts: 837
Rep Power: 3 titaniumdecoy is on a distinguished road
Send a message via AIM to titaniumdecoy
Re: Snytax error

As Freaky Chris noted, java.lang.* (which includes String) is automatically imported by the JVM. You do not need to import basic types such as int as they are built into the language.
titaniumdecoy is offline   Reply With Quote
Old Apr 28th, 2008, 1:37 PM   #6
A.K.Al Shamsi
Programmer
 
A.K.Al Shamsi's Avatar
 
Join Date: Mar 2008
Posts: 35
Rep Power: 0 A.K.Al Shamsi is on a distinguished road
Re: Snytax error

but i won't import it if i didn't find error which was about importing the package
A.K.Al Shamsi is offline   Reply With Quote
Old Apr 28th, 2008, 1:38 PM   #7
Freaky Chris
Hobbyist Programmer
 
Freaky Chris's Avatar
 
Join Date: Dec 2007
Location: England
Posts: 169
Rep Power: 1 Freaky Chris is on a distinguished road
Send a message via MSN to Freaky Chris
Re: Snytax error

What exactly is the error you get when you don't import the package?
__________________
Who said i couldn't program
sarcasm = raw_input('Type in a sarcastic remark: ')
print sarcasm
Freaky Chris is offline   Reply With Quote
Old Apr 28th, 2008, 6:59 PM   #8
A.K.Al Shamsi
Programmer
 
A.K.Al Shamsi's Avatar
 
Join Date: Mar 2008
Posts: 35
Rep Power: 0 A.K.Al Shamsi is on a distinguished road
Re: Snytax error

the programme asking for semi-colon but it is there
A.K.Al Shamsi is offline   Reply With Quote
Old Apr 29th, 2008, 1:42 AM   #9
Freaky Chris
Hobbyist Programmer
 
Freaky Chris's Avatar
 
Join Date: Dec 2007
Location: England
Posts: 169
Rep Power: 1 Freaky Chris is on a distinguished road
Send a message via MSN to Freaky Chris
Re: Snytax error

No i mean, what error do you get without trying to put the import java.lang.String and int statement in. AS in what was the error that made you try to include these?
__________________
Who said i couldn't program
sarcasm = raw_input('Type in a sarcastic remark: ')
print sarcasm
Freaky Chris is offline   Reply With Quote
Old Apr 29th, 2008, 7:46 AM   #10
A.K.Al Shamsi
Programmer
 
A.K.Al Shamsi's Avatar
 
Join Date: Mar 2008
Posts: 35
Rep Power: 0 A.K.Al Shamsi is on a distinguished road
Re: Snytax error

i asked to help from one of my classmate and here is the code

this for the clas which has the operations
 public class Convert{     // Convert class starts
    
    public Integer minute(Integer hr){ // define a varible and pass parameter
        Integer min = hr * 60; // declare minutes with shortcut and the 
        // operation of converting hour to minutes
        return min; // return type of minute 
    }// end of minute
    
    
     public double hour(double min){ // define a varible and  pass parameter min
       double hr = min / 60; // declare minutes with shortcut  and the operation 
       //of converting minutes to hours
        return hr;// return type of hour
    }// end of hour
     
     
          public double hr(double day){// define a varible hour with shortcut 
         // because there is another varible called hour so it should be changed 
         //and pass parameter
        double hr = day * 24  ;//declare hour with shortcut and the operation
        //of converting day to hours
        return hr;// return type of hour
     }// end of hour
          
     
     public double day(double hour){// define a varible and pass parameter
        double day = hour / 24  ;//declare day and the operation 
        //of converting hours to day
        return day;// return type of day
     }// end of day
     
       
         
     public Integer week(Integer yr){// define a varibel week and pass 
        //parameter
       Integer wek = yr*52  ;// decalre week with shortcut and the operation of 
        //converting weeks to years
        return wek;// return type of week
     }//end of week
             
             
      public Integer Day(Integer week ){//define a varible day and pass 
        //parameter
      Integer  Dy = week *7 ;// declare day with shortcut and the operation of 
      //converting week to days
        return Dy; //return type of day
      }// end of day
      
      
      public double week ( double day){
      double week = day / 7;
      return day;
      }
      
              
      
        public double year(double week){// define a varible year and pass 
        //parameter
        double yer = week/52  ;// declare year with shortcut and the operation 
        //of converting year to week 
        return yer;//return type of year
     }// end of year1
        
             
        
        public double yer(double month ){// define a varible year with a  and 
            //pass parameter. because year is declared before year so the name 
            //should be different
        double   yar = month/12;// declate year with shortcut and the operation 
        //of converting months to year
        return yar;// retrun type of year
     }// end of year2
        
        
}// end of the class


and this for main method
 //import java.lang.String and int; 
// import the package to avoid any snytax error
import javax.swing.*;
// import this package for graphical user interface

public class ConvertTest{// the class starts
    
    public static void main(String args[]){// the main mothed starts for executing the programme
        
        Convert test = new Convert ();// creating an object to call for convert class
        
        while(true){// while true starts for looping
        String menu="Enter your Option:\n " ;
        // the menu starts and converting ways of minute, hour, day, year, month, week and year
        String Option1= "1- Convert from Minute to Hour                  2- Convert from Hour to Minute \n";
        String Option2= " 3- Convert from Day to Hour                        4- Convert from Hour to Day \n";
        String Option3= " 5- Convert from Days to Week                    6- Convert from Week to Days \n";
        String Option4= " 7- Convert from Year to Weeks                   8- Convert from Weeks to Year \n";
        String Option5= " 9- Convert from Months to Year                  0- Exit";
        String choose= JOptionPane.showInputDialog(menu + Option1 + Option2+ Option3+ Option4+Option5);
        // to dispaly the menu in input dialog so the user can enter any number from above
        int num = Integer.parseInt(choose);} // to convert string to number
        
while(true){ // while starts
           String Option1 = JOptionPane.showInputDialog("Enter Number to Convert from Minute to Hour"); // dialog box to enter a number
try{// try statement starts
	int y = Integer.parseInt(Option1);//converting from string to number
        
	if (y == 1){// if statement starts and checking of the method
Integer minutes=test.minute(y);//calling the formula  from convert class
JOptionPane.showMessageDialog(null,"Minutes ="+minutes+ " Hours");// display the answer in dialog box
        }//if ends

else{// else starts
break;// the programme stops
}}// end of else  and try
catch (Exception e){// catch starts 
	JOptionPane.showMessageDialog(null,"Enter a number");// display an error
}}//end of catch and while



while(true){//while starts
           String Option2 = JOptionPane.showInputDialog("Enter Number toConvert from Hour to Minute"); // dialog box to enter a number
            try{// try statement starts
                int x = Integer.parseInt(Option2);//converting from string to number
	if (x == 2){// if statement starts and checking of the method
 double Hour=test.hour(x);//calling the formula  from convert class
JOptionPane.showMessageDialog(null,"Hours = "+Hour+ " Minutes");// display the answer in dialog box
        }//if ends

else{ // else starts

break;// the programme stops
}} // end of else  and try
catch (Exception e){// catch starts
	JOptionPane.showMessageDialog(null,"Enter a number with this forumal 0.0");// display an error
}}//end of catch and while


while(true){// while starts
          String  Option3 = JOptionPane.showInputDialog("Enter Number to Convert from Day to Hour"); // dialog box to enter a number
try{// try statement starts
int d = Integer.parseInt(Option3);//converting from string to number
	if (d == 3){// if statement starts and checking of the method
        double Day=test.hr(d);//calling the formula  from convert class
        JOptionPane.showMessageDialog(null,"Day = "+Day+ " Hours");// display the answer in dialog box
        }//if ends

else{// else starts
break;// the programme stops
}}// end of else  and try
catch (Exception e){// catch starts
	JOptionPane.showMessageDialog(null,"Enter a number");// display an error
}}//end of catch and while


while(true){// while starts
            String Option4 = JOptionPane.showInputDialog("Enter Number to Convert from Hour to Day");// dialog box to enter a number
            try{// try statement starts
            int h = Integer.parseInt(Option4);//converting from string to number
	if (h == 4){// if statement starts and checking of the method
        double Hour=test.day(h);//calling the formula  from convert class
        JOptionPane.showMessageDialog(null,"Hours =  "+ Hour + " Day"); // display the answer in dialog box
        }//if ends

else{// else starts
break;// the programme stops
}}// end of else  and try
catch (Exception e){// catch starts
	JOptionPane.showMessageDialog(null,"Enter a number");// display an error
}}//end of catch and while


while(true){// while starts
            String Option5 = JOptionPane.showInputDialog("Enter Number to Convert from Days to Week");// dialog box to enter a number
try{// try statement starts
int x = Integer.parseInt(Option5);//converting from string to number
	if (x == 5){// if statement starts and checking of the method
        double week=test.Day(x); //calling the formula  from convert class
        JOptionPane.showMessageDialog(null,"Days = "+week+ "Week");// display the answer in dialog box
        }//if ends

else{// else starts
break;// the programme stops
}}// end of else  and try
catch (Exception e){// catch starts
	JOptionPane.showMessageDialog(null,"Enter a number");// display an error
}}//end of catch and while


while(true){// while starts
           String Option6 = JOptionPane.showInputDialog("Enter Number to Convert from Week to Days");// dialog box to enter a number
try{// try statement starts
 int x = Integer.parseInt(Option6);//converting from string to number
	if (x == 6){// if statement starts and checking of the method
        double week=test.week(x); //calling the formula  from convert class
        JOptionPane.showMessageDialog(null,"Weeks "+  week+ " Days");// display the answer in dialog box
        }//if ends
else{// else starts
break;// the programme stops
}}// end of else  and try
catch (Exception e){// catch starts
	JOptionPane.showMessageDialog(null,"Enter a number");// display an error
}}//end of catch and while


while(true){// while starts
            String Option7 = JOptionPane.showInputDialog("Enter Number to Convert from Year to Weeks");// dialog box to enter a number
try{// try statement starts
int x = Integer.parseInt(Option7);//converting from string to number
	if (x == 7){// if statement starts and checking of the method
                
       double  year=test.week(x);//calling the formula  from convert class
        JOptionPane.showMessageDialog(null,"Weeks"+ " " +"years");// display the answer in dialog box
        } //if ends
else{// else starts
break;// the programme stops
}}// end of else  and try
catch (Exception e){// catch starts
	JOptionPane.showMessageDialog(null,"Enter a number");// display an error
}}//end of catch and while


while(true){// while starts
            String Option8 = JOptionPane.showInputDialog("Enter Number to Convert from Weeks to Year");// dialog box to enter a number
try{// try statement starts
int x = Integer.parseInt(Option8);//converting from string to number
	if (x == 8){// if statement starts and checking of the method           
       double Hour=test.year(x);//calling the formula  from convert class
        JOptionPane.showMessageDialog(null,"Years"+ " "+" Weeks");// display the answer in dialog box
        } //if ends
else{// else starts
break;// the programme stops
}}// end of else  and try
catch (Exception e){// catch starts
	JOptionPane.showMessageDialog(null,"Enter a number");// display an error
}}//end of catch and while

while(true){// the while loop starts
            String Option9 = JOptionPane.showInputDialog("Enter Number to Convert from Months to Year");// input number to get the answer
try{// the validation of try starts
int x = Integer.parseInt(Option9);//convert string into a number
	if (x == 9){// if statement starts to check the value
        double month=test.yer(x);// calling the formula from the class
        JOptionPane.showMessageDialog(null,"Months"+" " +"Year");
        }
else{// doing another thing
break;// the programme stops
}// end else
}//end try
catch (Exception e){// the exception starts
	JOptionPane.showMessageDialog(null,"Enter a Number with this format 0.0");// display a message when the format is wrong
}//end exception
}//end of the while loop
  
        String Option0=JOptionPane.showInputDialog("Enter Number to Exit from The Programme");
        int z=Integer.parseInt(Option0);
            if (z == 0){// 0 is the number of exiting for the programme
                   break; 
            }// to stop the programme from running
        
    }// end main method
 } //end class


the last error disspeared but i have error in last brea which is this :

  String Option0=JOptionPane.showInputDialog("Enter Number to Exit from The Programme");
        int z=Integer.parseInt(Option0);
            if (z == 0){// 0 is the number of exiting for the programme
                   break; 
            }// to stop the programme from running
the error says"breaks outside switch or loop"

do you have any idea about this error and how could it be solved??
A.K.Al Shamsi is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Basic Socket Programming Error in Linux.. Pls help boraciner C++ 18 Sep 12th, 2007 1:17 AM
C# corruption!!! Kilo C++ 32 May 21st, 2006 8:44 PM
Masm rsnd Assembly 4 May 20th, 2006 9:05 PM
libraries matko C 1 Jan 22nd, 2006 2:12 PM
String error in if statement Blighttdm C 12 Nov 18th, 2005 6:34 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 3:25 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC