'.class' expected

import java.lang.String;
class StringDemo
public static void main(String args[])
  //create 3 strings
  String s1="This is Dog";
  String s2= new String(" I LIke It");
    char arr[]={"l","a","k","s","h","m","i"};
    String s3= new String(arr[]);
   //display the strings
  System.out.println("s1="+s1);
   System.out.println("s1="+s2);
   System.out.println("s1="+s3);
   //find no'of characters in s1
   System.out.println(" Length ofs1="+s1.length());
  //join s1 with s2
   System.out.println("s1 joined with s2="+s1.concat(s2));
  //join 3 strings using +
   System.out.println(s1+"at="+s3);
  //test s1 starts with this or not
  boolean x=s1.startsWith("This");
  if(x==true)
  System.out.println("starts with thiss1=");
  else
   System.out.println(" notstart ");
//extract substrings from s2 and s3
String p=s2.substring(0,5);
  String  q=s3.substring((0));
   System.out.println(p+q);
//convert the case of s1
s1.toUpperCase();
  System.out.println("Lower of s1="+s1);
s1. toLowerCase();
Hi, when i compile this program it gives an error like
StringDemo.java:10: '.class' expected
    String s3= new String(arr[]);
                               ^
StringDemo.java:10: ')' expected
    String s3= new String(arr[]);what's my mistake pls helpme
ThanQu in advance

import java.lang.String;
class StringDemo
public static void main(String args[])
//create 3 strings
String s1="This is Dog";
String s2= new String(" I LIke It");
char arr[]={"l","a","k","s","h","m","i"};
String s3= new String(arr[]);This should be:
String s3 = new String(arr);
if(x==true)Although the above will work, you should not do this as a matter of style (it is redundant). Should be:
if (x) {
}

Similar Messages

  • Java '.class' expected, simple but im not seeing it

    I'm working on a project right now and need to list 3 parellel arrays. This is what my compiler error looks like.
    '.class' expected ')' expected
    It's really bugging be, so here are the two methods.
    This is the code that my info is being sent to. This method is in a class named ListPets
    public void listPets(String[] name, double[] price, int[] quanity)
              for(int i = 0; i<name.length; i++)
                   output+="\n"+name[i]+"       "+price[i]+"          "+quanity;
    this is what is being sent to it
    This code is in a class called MainGui
    I also have this little bit at the top.
    ListPets panList = new ListPets();
         public void actionPerformed(ActionEvent ae)
         panList.listPets(petname[], petprice[], petquanity[]);
    }I feel like im over looking somthing, but i cant find it. Any help on this would be nice, thanks,

    panList.listPets(petname[], petprice[] , petquanity[]);You are trying to call a method in the line of code above. So you should only include the variable names, like thispanList.listPets(petname, petprice, petquanity);Some feedback on your design: It looks like you have (at least) 3 arrays whose contents relate to each other. That is, petname[2] is a pet type's name, petprice[2] is the same pet type's price and petquantity[2] is the same pet type's quantity. In Java, you should not use "parallel arrays" to associate the contents of arrays. Instead, you should have a class - that's the whole idea of object oriented programming.

  • When calling method error .class expected

    First the method I'm calling.
    public void ExeSqlStmt(String sqlStmt, String columnNames[], String connectString, String userName, String password,int numColumns)
    This compiles clean. The code that calls the method is giving me fits with expecting .class, expecting ), can not resolve symble and unexpected type.
    The offending line is near the bottom of the code.
    Thanks,
    -Rob
    package jdba;
    * Execute the sql statement
    // java imports
    import java.util.Vector;
    import java.awt.event.*;
    import java.awt.Toolkit;
    import java.awt.Container;
    import java.awt.BorderLayout;
    import java.awt.Color;
    import javax.swing.JScrollPane;
    import javax.swing.ScrollPaneConstants;
    import javax.swing.JTable;
    import javax.swing.JPanel;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    // sql imports
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;
    import java.sql.PreparedStatement;
    import java.sql.Connection;
    import java.sql.DriverManager;
    public class SqlUtil extends JPanel
      Connection conn;  // database connection object
      Statement stmt;   // statement object
      ResultSet rslt;   // result set object
      // create someplace to put dat
      Vector data;     //    = new Vector();
      Vector columns;  //    = new Vector();
      Vector colHeads; //    = new Vector();     
      public SqlUtil()
        // setup panel
        JPanel sqlPanel = new JPanel(false);
        sqlPanel.setLayout(new BorderLayout());
        setBackground(Color.white);
        setForeground(Color.black);
      public void ExeSqlStmt(String sqlStmt, String columnNames[], String connectString, String userName, String password,int numColumns)
        data     = new Vector();
        columns  = new Vector();
        colHeads = new Vector();
        try
          // connect to database
          DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
          Connection conn = DriverManager.getConnection(connectString, userName, password);
          // select data into object
          stmt = conn.createStatement();
          rslt = stmt.executeQuery(sqlStmt);
          while (rslt.next())
            columns = new Vector();
            for ( int i=0; i<numColumns; i++ )
              colHeads.addElement(columnNames); // column heads
    columns.addElement(rslt.getObject(i+1)); // get the Object at i+1
    } // end for
    data.addElement(columns);
    // create the table
    JTable table = new JTable(data,colHeads);
    // add table to scroll pane
    int v = ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;
    int h = ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;
    JScrollPane jsp = new JScrollPane(table,v,h);
    // Add scroll pane to content pane
    add(jsp, BorderLayout.CENTER);
    // close the result set and close the statement
    rslt.close();
    stmt.close();
    } catch (SQLException ex)
    String msg = "SQL error: "+ex.toString();
    } catch (Exception ex)
    String msg = "Error: "+ex.toString();
    } // end constructor
    } // end SqlUtil class
    // then we have the code that is calling and getting the errors
    package jdba;
    // java imports
    import java.util.Vector;
    import java.awt.event.*;
    import java.awt.Toolkit;
    import java.awt.Container;
    import java.awt.BorderLayout;
    import java.awt.Color;
    import javax.swing.JScrollPane;
    import javax.swing.ScrollPaneConstants;
    import javax.swing.JTable;
    import javax.swing.JPanel;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    // sql imports
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;
    import java.sql.PreparedStatement;
    import java.sql.Connection;
    import java.sql.DriverManager;
    // rollback contention
    public class RollbackContention extends JPanel
    Connection conn; // database connection object
    Statement stmt; // statement object
    ResultSet rslt; // result set object
    //private vars
    private String userName = "[cut]";
    private String password = "[cut]";
    private String sid = "rob";
    private String port = "1521";
    private String server = "[cut]";
    private String connectString = "jdbc:oracle:thin:@"+server+":"+port+":"+sid;
    private int numCols = 3;
    private String sqlStmt = null;
    private String prompt = null;
    private String colNames[] = {"name","waits","gets"};
    // constructor
    public RollbackContention()
    SqlUtil exeStmt = new SqlUtil();
    sqlStmt = "select name, waits, gets";
    sqlStmt = sqlStmt + " from v$rollstat, v$rollname";
    sqlStmt = sqlStmt + " where v$rollstat.usn = v$rollname.usn";
    // here is the offending line.
    exeStmt.exeSqlStmt(sqlStmt, colNames[], connectString, userName, password, 3);
    // loop through and display the rollback segments

    In your call your referencing the array as colNames[] - it should be colNames (no []'s )
    exeStmt.exeSqlStmt(sqlStmt, colNames, connectString, userName, password, 3);

  • Syntax error on keyword "void"; "interface", "class" expected

    When migrating my application for Visual-Age to Web-Sphere 5.1
    The following error occurred:
    Syntax error on keyword "void"; "interface", "class" expected
    for the code:
    * ejbLoad method comment
    * @exception javax.ejb.EJBException The exception description.
    public void ejbLoad() throws javax.ejb.EJBException{
         _initLinks();
    }Thanking you in an advance

    I had missed a closing breacket '}'

  • .class expected error

    I am consistently recieving an error message that says ".class expected" on the "Easter date = new Easter (int year);" line every time i try to compile my tester class. Can anyone help me figure out the problem? Here is my tester/driver class:
    * Tester Class
    * Ben Mathews
    * September 13th, 2009
    public class EasterTester
    public static void main (String [ ] arg)
    Easter date = new Easter (int year );
    date.calculate ();
    }// end main
    }// end Easter

    When you post code, click on "CODE" to generate code tags and paste your code between the tags. Then it will look like this, which will help you get help. /*
    Tester Class
    Ben Mathews
    September 13th, 2009
    public class EasterTester
         public static void main (String [ ] arg)
              Easter date = new Easter (int year );
              date.calculate ();
         }// end main
    }// end Easter When you define a constructor (or a method) with a parameter, you have to tell the compiler what type that parameter is, for example //a constructor example
    public Easter(int year) But, when you use a constructor (or method) with a parameter, you just put in the value or variable, for example int year = 1999;
    Easter date = new Easter (year);

  • '.class' expected Error when trying to pass an Array

    In the below method I am trying to return an array. The compiler gives me one error: '.class' expected. I am not sure if I am writing the 'return' statement correctly and not really sure of another way to code it. Below is a portion of the code and I can post all of it if need be but the other methods seem to be fine.
    import java.util.Scanner;
    public class LibraryUserAccount
    Scanner input=new Scanner(System.in);
    private final int MAX_BOOKS_ALLOWED;
    private int checkedOutBookCounter;
    private long accountNumber;
    private String socialSecurityNumber, name, address;
    private final long isbnNumbers[];
    //constructor
    public LibraryUserAccount(long accountNumber, int maxBooksAllowed)
         this.accountNumber = 0;
         MAX_BOOKS_ALLOWED = maxBooksAllowed;
    //returns the array isbnNumbers[]
    public long getCheckedOutBooksISBNNumbers()
         return isbnNumbers[];
    The error displayed as:
    LibraryUserAccount.java:111: '.class' expected
         return isbnNumbers[];
    ^
    1 error
    Thanks in advance for the help.

    Rewriting the method as:
    public long[] getCheckedOutBooksISBNNumbers()
    return isbnNumbers;
    ... has fixed that particular compiler error. Thanks jverd. I appreciate the help.
    On a separate note I am having trouble with initializing the array. What I am trying to do is initialize an array of a size equal to a value passed to the class. Example being:
    //variables
    private final int MAX_BOOKS_ALLOWED;
    private long accountNumber;
    private final long[] isbnNumbers;
    //constructor method
    public LibraryUserAccount(long accountNumber, int maxBooksAllowed)
    this.accountNumber = 0;
    MAX_BOOKS_ALLOWED = maxBooksAllowed;
    long[] isbnNumbers = new long[MAX_BOOKS_ALLOWED];
    My goal is to set the size of isbnNumbers[] to the value of MAX_BOOKS_ALLOWED. I've tried a couple of different ways to initialize the array (the latest listed above) but the compiler doesn't like what I have done. Thanks again.

  • .class expected? Double inside a for

    I'm trying to assign a random number to a double inside a for loop, but my compiler doesn't seem to like it. It's saying '.class expected' and 'not a statement', I was wondering if anyone would be so kind as to take a look at my code and give me some direction in what I'm doing wrong? I'm very new to java so I apologise if I'm a little slow on catching on. :)
    import java.util.Scanner;
    class Classroom {
      public static void main(String args[]) {
        Scanner gavroche = new Scanner(System.in);
    /*Gather Information*/
    System.out.print("What is your name? ");
    String name = gavroche.next();
    System.out.print("What grade are you in? ( 1-7 ) ");
    int grade = gavroche.nextInt();
    System.out.print("What type of test do you want to do? ( +, -, x, / ) ");
    String type = gavroche.next();
    /*Grade 1 test*/
    if (grade == 1) {
    /*Addition test*/
    if (type.equals("+"))
         System.out.println("Hello " + name + "!");
         for (int number = 0; number < 10; number++)
         double var1 = (int)(1+Math.random()*10);
         double var2 = (int)(1+Math.random()*10);
         System.out.println("What is " + var1 + " + " + var2 + "?");
         int answer = gavroche.nextInt();
         if (answer == var1+var2)
              System.out.println("Correct!");
         else if(answer != var1+var2)
              System.out.println("Wrong!");
    }Thank you!
    Edited by: grimsqueaker on Oct 25, 2007 7:02 PM

    grimsqueaker wrote:
    Braces where? It compiles fine without the two double var1 and var2.Yeah maybe. But the logic is all wrong.
    Try this formatting for starters
    import java.util.Scanner;
    public class Classroom {
      public static void main(String args[]) {
        Scanner gavroche = new Scanner(System.in);
        /*Gather Information*/
        System.out.print("What is your name? ");
        String name = gavroche.next();
        System.out.print("What grade are you in? ( 1-7 ) ");
        int grade = gavroche.nextInt();
        System.out.print("What type of test do you want to do? ( +, -, x, / ) ");
        String type = gavroche.next();
        /*Grade 1 test*/
        if (grade == 1) {
          /*Addition test*/
          if (type.equals("+")){
               System.out.println("Hello " + name + "!");
               for (int number = 0; number < 10; number++){
                 double var1 = (int)(1+Math.random()*10);
                 double var2 = (int)(1+Math.random()*10);
                 System.out.println("What is " + var1 + " + " + var2 + "?");
                 int answer = gavroche.nextInt();
                 if (answer == var1+var2){
                      System.out.println("Correct!");
                 }else if(answer != var1+var2){
                      System.out.println("Wrong!");
    }

  • .class expected error when compiling

    Ive been getting this frustrating error when compiling. My program is essentially supposed to add the values in two matrixes and return a new matrix using the added values
    Heres my code:
       public Matrix add(Matrix comp)
            int[][] temp = new int[this.numRows()][this.numCols()];
            for (int a = 0; a < comp.numRows(); a++) {
                for (int b = 0; b < comp.numCols(); b++) {
                    temp[a] = this.myCells[a][b] + comp.getVal(a, b);
    Matrix addedMatrix = new Matrix(temp[][]);
    return addedMatrix;
    heres the constructor for Matrix object:
      public Matrix(int[][] mat)
            int[][] myCells = new int[mat.length][mat[0].length];
            for (int i = 0; i < mat.length; i++) {
                for (int j = 0; j < mat[0].length; j++) {
                    myCells[i][j] = mat[i][j];
        }getVal, numRows, and numCols are all helper methods that just return values.
    The error is '.class' expected in the line which says Matrix addedMatrix = new Matrix(temp[][]); I checked for extra brackets but there dont seem to be any.
    Any help would be appreciated. Thanks.

    I think you just needMatrix addedMatrix = new Matrix(temp);

  • Compiling Error... Found: Class Expected: Value

    Hello, I am writing a GUI with a "join file" feature.
    So far, I load my files (multiple files enabled):
    private void loadFile()
                 JFileChooser fc = new JFileChooser();
                  fc.setMultiSelectionEnabled(true);
                int returnVal = fc.showOpenDialog(MyFrame.this);
                   if (returnVal == JFileChooser.APPROVE_OPTION)
                       File[] files = fc.getSelectedFiles();
           }I join them by adding them into a vector (not sure if there's a better way?):
    public void joinFiles(File[] files)
                   Vector v = new Vector();
                   for (int i = 0; i<files.length; i++)
                       String fileName = new String(files.toString());
                   String line;
                        try
                             BufferedReader in = new BufferedReader(new FileReader(fileName));
                             if ( !in.ready() ) throw new IOException();
                                  while ( (line = in.readLine() ) != null)
                   v.add(line);
                        in.close();
                        catch (IOException e)
                        System.out.println(e);
    Then, as I have a GUI, I have menu item actions set up as follows:
    public void actionPerformed(ActionEvent e){
              if(e.getSource() == load){
                   loadFile();
              if(e.getSource() == join){
                   joinFiles(File[] files);
              }This generates the error:
    fileManipulator.java:93: '.class' expected
    joinFiles(File[] files);
    ^
    fileManipulator.java:93: ')' expected
    joinFiles(File[] files);
    ^
    fileManipulator.java:93: unexpected type
    required: value
    found : class
    joinFiles(File[] files);
    ^
    Help me please!!

    public class FileStuff {
        File [] fileArray;  //Declare as instance variable.
    private void loadFile()
        JFileChooser fc = new JFileChooser();
        fc.setMultiSelectionEnabled(true);
        int returnVal = fc.showOpenDialog(MyFrame.this);
        if (returnVal == JFileChooser.APPROVE_OPTION)
            //files IS NOT ACCESSIBLE OUTSIDE THIS "if" statement.
            File[] files = fc.getSelectedFiles();      // DELETE THIS
            fileArray = fc.getSelectedFiles();    // ADD THIS !!!!!!!
    public void joinFiles(File [] files)
    {  .. no change ..}
    public void actionPerformed(ActionEvent e)
    {  .. no change to "loadFile" part ..;
       if (e.getSource() = join)
          joinFiles(fileArray);
    }

  • '.class' expected compiler error

    Here is my code:
    import java.util.*;
    public class LetCount
      public static final int NUMCHARS = 27; //You define
    // int addr(char ch) returns the equivalent integer address for the letter
    // given in ch, 'A' returns 1, 'Z' returns 26 and all other letters return
    // their corresponding position as well.
      public static int addr(char ch)
        return (int) ch - (int) 'A' + 1;
    // Required method definitions for (1) analyzing each character to update
    // the appropriate count; (2) determining most frequent letter;
    // (3) determining least frequent letter; and (4) printing final results
    // should be defined here.
      public static char getCharValue(int index)
        char character;
        int intValueOfA = Character.getNumericValue('A');
        for (index = 1; index <= NUMCHARS; index++)
          int intValueOfChar = intValueOfA + index-1;
          character = (char) intValueOfChar;
        return character;
      public static void countLetters(int count[], String line)
        for (int lineIndex = 0; lineIndex < line.length(); lineIndex++)
          char letter = line.charAt(lineIndex);
          int arrayIndex = addr(letter);
          count[arrayIndex] = count[arrayIndex] + 1;
      public static char findMostFrequent (int [] count)
         int biggestCount = 0;
         int biggestCountIndex = 0;
        for (int arrayIndex = 1; arrayIndex <= NUMCHARS; arrayIndex++)
          if (count[arrayIndex] > biggestCount)
            biggestCount = count[arrayIndex];
            biggestCountIndex = arrayIndex;
        return getCharValue(biggestCountIndex);
      public static char findLeastFrequent(int [] count)
         int smallestCount = 0;
         int smallestCountIndex = 0;
         for (int arrayIndex = 1; arrayIndex <= NUMCHARS; arrayIndex++)
           if (count[arrayIndex] < smallestCount)
             smallestCount = count[arrayIndex];
             smallestCountIndex = arrayIndex;
         return getCharValue(smallestCountIndex);
      public static void printResults(int [] count)
         for (int arrayIndex = 1; arrayIndex <= NUMCHARS; arrayIndex++)
          System.out.println(getCharValue(arrayIndex) + " occurred " + count[arrayIndex] + " times.");
         System.out.println();
         System.out.println("Most frequent letter = " + findMostFrequent(count[]));
         System.out.println("Least frequent letter = " + findLeastFrequent(count[]));
      public static void main(String[] args)
        Scanner keyboard = new Scanner(System.in);  // for reading input
        int[] count = new int [NUMCHARS]; // count of characters
        String line;      // holds input line   
        // Other declarations as needed
        //initializes all elements of count[] array to 0
        for(int i=0; i<NUMCHARS; i++)
          count=0;
    // Method calls and other statements to complete problem solution go here
    while (keyboard.hasNext())
    line = keyboard.nextLine();
    System.out.println(line);
    countLetters(count[], line);
    printResults();
    }The error from the compiler occurs at the following lines:System.out.println("Most frequent letter = " + findMostFrequent(count[]));System.out.println("Least frequent letter = " + findLeastFrequent(count[]));countLetters(count[], line);Please help!  How do I change these lines so that the "'.class' expected" error is solved?                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    Thanks! Now I just have a run time error:
    Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: -32
         at LetCount.countLetters(LetCount.java:51)
         at LetCount.main(LetCount.java:118)
    Lines 51 and 118 are these respectively:
    count[arrayIndex] = count[arrayIndex] + 1;In the countLetters method
    countLetters(count, line); At the bottom of main

  • Interface or class expected

    hi
    public class TopLevelClass
         public void nonStaticMethod_1()
              System.out.println("nonstaticMethod_1 in AccessInTopLevelClass");
         private static class MemberClass_1{
         private static int i;
         private int j=10;
         public static void StaticMethod_1_1()
              System.out.println("nonstaticMethod_1_1 in StaticMemberClass_1");
         interface StaticMemberInterface1_1
    public void display();
    protected static class StaticMemberClass_1_1
    implements StaticMemberInterface1_1
         private int k=99;
         public void display()
    System.out.println("Hi ,i am in StaticMemberClass_1_1");
    // interface StaticMemberInterface_1 extends StaticMemberClass_1.StaticMemberInterface_1
    public void nonstaticmethod_1_1_1()
         int jj=j;
         int ii=i;
         // nonStaticMethod_1();//not ok
         StaticMethod_1_1();
    public static void main(String arg[])
         int ii=1;
         //int kk=k;
         StaticMethod_1_1();
    when i complie this program i have one errors
    class or interface expected i don,t understand it can any body help me to remove this error and what is the cause of this error

    amit4444 wrote:
    so u mean i have to write psvm in toplevel class .*is their any other way to remove this exception*By programming in Cobol.

  • Class Expected error - HELP

    Hi I've been workin on a project, and it seems something is wrong with this code... i honestly cannot figure it out...
    here it is :
    Uses the following methods:
    public static boolean areEquivalent (String word1, String word2)
    This method reutrns true or false depending on whether the two input arguments hae equal numbers of A's, B's, and C's (in any order.) You may assume that each string contains only these lowercase characters, in any order or quantity. For example, areEquivalent("abcbca","ccbbaa... ) would return true, because each input string contains 2 as, 2 bs, and 2cs.
    this is the code i have so far:
    public static boolean areEquivalent(String word1, String word2)
    int count = 0;
    String line;
    for ( int i = 0; i<char.length; i++)
    saasd
    if count = as + word 2
    true
    else count = bs + word 2
    true
    else count = cs + word 2
    true
    else as==bs==cs
    return true
    }

    Hi,
    May I know what is your actual code?
    And what error did you get?
    thanks
    daniel

  • Creating a triangle using polygon class problem, URGENT??

    Hi i am creating a triangle using polygon class which will eventually be used in a game where by a user clicks on the screen and triangles appear.
    class MainWindow extends Frame
         private Polygon[] m_polyTriangleArr;
                       MainWindow()
                              m_nTrianglesToDraw = 0;
             m_nTrianglesDrawn = 0;
                             m_polyTriangleArr = new Polygon[15];
                             addMouseListener(new MouseCatcher() );
            setVisible(true);
                         class MouseCatcher extends MouseAdapter
                             public void mousePressed(MouseEvent evt)
                  Point ptMouse = new Point();
                  ptMouse = evt.getPoint();
                if(m_nTrianglesDrawn < m_nTrianglesToDraw)
                                int npoints = 3;
                        m_polyTriangleArr[m_nTrianglesDrawn]
                      = new Polygon( ptMouse[].x, ptMouse[].y, npoints);
    }When i compile my code i get the following error message:
    Class Expected
    ')' expectedThe two error messages are refering to the section new Polygon(....)
    line. Please help

    Cannot find symbol constructor Polygon(int, int, int)
    Can some one tell me where this needs to go and what i should generally
    look like pleaseI don't think it is a good idea to try and add the constructor that the compiler
    can't find. Instead you should use the constructor that already exists
    in the Polygon class: ie the one that looks like Polygon(int[], int[], int).
    But this requires you to pass two int arrays and not two ints as you
    are doing at the moment. As you have seen, evt.getPoint() only supplies
    you with a single pair of ints: the x- and y-coordinates of where the mouse
    button was pressed.
    And this is the root of the problem. To draw a triangle you need three
    points. From these three points you can build up two arrays: one containing
    the x-coordinates and one containing the y-coordinates. It is these two
    arrays that will be used as the first two arguments to the Polygon constructor.
    So your task is to figure out how you can respond to mouse presses
    correctly, and only try and add a new triangle when you have all three of its
    vertices.
    [Edit] This assumes that you expect the user to specify all three vertices of the
    triangle. If this isn't the case, say what you do expect.

  • Problem with constructors and using public classes

    Hi, I'm totally new to Java and I'm having a lot of problems with my program :(
    I have to create constructor which creates bool's array of adequate size to create a sieve of Eratosthenes (for 2 ->n).
    Then it has to create public method boolean prime(m) which returs true if the given number is prime and false if it's not prime.
    And then I have to create class with main function which chooses from the given arguments the maximum and creates for it the sieve
    (using the class which was created before) and returns if the arguments are prime or not.
    This is what I've written but of course it's messy and it doesn't work. Can anyone help with that?
    //part with a constructor
    public class ESieve {
      ESieve(int n) {
    boolean[] isPrime = new boolean[n+1];
    for (int i=2; i<=n; i++)
    isPrime=true;
    for(int i=2;i*i<n;i++){
    if(isPrime[i]){
    for(int j=i;i*j<=n;j++){
    isPrime[i*j]=false;}}}
    public static boolean Prime(int m)
    for(int i=0; i<=m; i++)
    if (isPrime[i]<2) return false;
    try
    m=Integer.parseInt(args[i]);
    catch (NumberFormatException ex)
    System.out.println(args[i] + " is not an integer");
    continue;
    if (isPrime[i]=true)
    System.out.println (isPrime[i] + " is prime");
    else
    System.out.println (isPrime[i] + " is not prime");
    //main
    public class ESieveTest{
    public static void main (String args[])
    public static int max(int[] args) {
    int maximum = args[0];
    for (int i=1; i<args.length; i++) {
    if (args[i] > maximum) {
    maximum = args[i];
    return maximum;
    new ESieve(maximum);
    for(int i=0; i<args.length; i++)
    Prime(i);}

    I've made changes and now my code looks like this:
    public class ESieve {
      ESieve(int n) {
       sieve(n);
    public static boolean sieve(int n)
         boolean[] s = new boolean[n+1];
         for (int i=2; i<=n; i++)
    s=true;
    for(int i=2;i*i<n;i++){
    if(s[i]){
    for(int j=i;i*j<=n;j++){
    s[i*j]=false;}}}
    return s[n];}
    public static boolean prime(int m)
    if (m<2) return false;
    boolean x = sieve(m);
    if (x=true)
    System.out.println (m + " is prime");
    else
    System.out.println (m + " is not prime");
    return x;}
    //main
    public class ESieveTest{
    public static int max(int[] args) {
    int maximum = args[0];
    for (int i=1; i<args.length; i++) {
    if (args[i] > maximum) {
    maximum = args[i];
    return maximum;
    public static void main (String[] args)
    int n; int i, j;
    for(i=0;i<=args.length;i++)
    n=Integer.parseInt(args[i]);
    int maximum=max(args[]);
    ESieve S = new ESieve(maximum);
    for(i=0; i<args.length; i++)
    S.prime(i);}
    It shows an error for main:
    {quote} ESieveTest.java:21: '.class' expected
    int maximum=max(args[]); {quote}
    Any suggestions how to fix it?                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Packed project Library Labview Class Issues

    I packed  my whole Labview project as a packed proj library during   teststand Deployment 
    I am using classes in my  labview project 
    unfortunalely by one of sub seq calls got the following error !
    "Type mismatch. The LabVIEW Class does not match the class expected by the VI.
    Cannot pass a base LabVIEW Class to call a method initially defined in a derived LabVIEW Class."

    The error message is quite clear:
    You are using inheritance where you do have methods which are not part of the parent class (as dynamic dispatch).
    During the call, you pass an object of the parent class and try to call the (unknown) method of the child.
    Why this is happening can only explain your code....
    Norbert
    CEO: What exactly is stopping us from doing this?
    Expert: Geometry
    Marketing Manager: Just ignore it.

Maybe you are looking for

  • Problems with msi p35 neo 2

    Default problems with msi p35 neo 2     pc works fine when using windows and the net and emails     only when using 3d mark or games do i ever get problems     just help in getting the hole story 6 months ago got a msi neo2 install all my old compone

  • Wish List - New Feature - Mark Songs for Deletion on iPhone

    It'd be very handy if you could mark a song for deletion on the iphone and then when you next sync your iphone, the marked songs will get removed. You could also have an option in itunes to say whether you want the songs to be deleted from comp too.

  • Downloaded music to iPod and it also went into Videos

    I just bought my iPod(5th gen.). I downloaded music to the iPod and not only did the files go to the music, but they also went into the Videos. Does anyone know how to remove the files from the video section, or have any advice? I would really apprec

  • Re: Best Way to Backup iTunes Library

    Hello friends : My iTunes music library is getting rather large and I feel it's time to "properly" back it up to an external hard drive. I understand that you can back up your iTunes music folder to an external hard drive by the simple old "click and

  • Can't open more firefox windows.

    Just installed the newest v of Firefox. Now I cannot open more than one firefox window, either through keyboard shortcut, right click, or manually through FF. Help :(