.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!");
}
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.
-
Java.rmi.UnmarshalException: skeleton class not found but required for clie
Hello everyone,
I am new to RMI and getting a strange exception. I am using Java 1.5.0_07 both on client and server. They are running on the same machine, the rmi registry is started inside the server application.
I am wondering why java complains about skeletons, I thought they are automatically created when using java 5.0?
Please have a look at the stacktrace below.
Thank you for your help.
Best Regards
Patric
java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
java.rmi.UnmarshalException: error unmarshalling call header; nested exception is:
java.rmi.UnmarshalException: skeleton class not found but required for client version
sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:325)
sun.rmi.transport.Transport$1.run(Transport.java:153)
java.security.AccessController.doPrivileged(Native Method)
sun.rmi.transport.Transport.serviceCall(Transport.java:149)
sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:466)
sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:707)
java.lang.Thread.run(Thread.java:595)
sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:247)
sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:223)
sun.rmi.server.UnicastRef.invoke(UnicastRef.java:343)
sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
java.rmi.Naming.lookup(Naming.java:84)
org.apache.jsp.index_jsp._jspService(index_jsp.java:58)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)The full class path information that I can gather is as follows (some of the library path locations could be suspect...):
Class path: /edge/node3/hotfix::/edge/node3/current/lib/JMdsApi.jar:/edge/node3/current/lib/MemoryProfilingAgent.jar:/edge/node3/current/lib/T2common-2.6.0-SNAPSHOT.3200.jar:/edge/node3/current/lib/T2scripting-jython.jar:/edge/node3/current/lib/activation.jar:/edge/node3/current/lib/alib.jar:/edge/node3/current/lib/alibom.jar:/edge/node3/current/lib/ant.jar:/edge/node3/current/lib/authapi.jar:/edge/node3/current/lib/bbdlapi.jar:/edge/node3/current/lib/bcpg-jdk15-136.jar:/edge/node3/current/lib/bcprov-jdk15-136.jar:/edge/node3/current/lib/c3p0-0.9.1.2.jar:/edge/node3/current/lib/castor-1.1-codegen-anttask.jar:/edge/node3/current/lib/castor-1.1-codegen.jar:/edge/node3/current/lib/castor-1.1-xml.jar:/edge/node3/current/lib/castor-1.1.jar:/edge/node3/current/lib/colt-1.2.0.jar:/edge/node3/current/lib/common-annotations.jar:/edge/node3/current/lib/commons-beanutils.jar:/edge/node3/current/lib/commons-codec-1.3.jar:/edge/node3/current/lib/commons-collections-3.2.1.jar:/edge/node3/current/lib/commons-jexl-1.1.jar:/edge/node3/current/lib/commons-lang-2.3.jar:/edge/node3/current/lib/commons-logging-1.1.1.jar:/edge/node3/current/lib/commons-net-1.4.1.jar:/edge/node3/current/lib/dsn.jar:/edge/node3/current/lib/eagleapi.jar:/edge/node3/current/lib/ezmorph-1.0.3.jar:/edge/node3/current/lib/f2-loader-1.8.jar:/edge/node3/current/lib/fasttrade-boviewer-1.0.1.jar:/edge/node3/current/lib/hsqldb.jar:/edge/node3/current/lib/icu4j-3.4.4.jar:/edge/node3/current/lib/ivy.jar:/edge/node3/current/lib/janino.jar:/edge/node3/current/lib/janus-sdk-1.7.0.0.jar:/edge/node3/current/lib/jasypt-1.4.1.jar:/edge/node3/current/lib/javolution.jar:/edge/node3/current/lib/jcalendar-1.3.2.jar:/edge/node3/current/lib/jcl-over-slf4j-1.5.6.jar:/edge/node3/current/lib/jcommon-1.0.9.jar:/edge/node3/current/lib/jconn2.jar:/edge/node3/current/lib/jconn3-6.05-b26214.jar:/edge/node3/current/lib/jdom.jar:/edge/node3/current/lib/jfreechart-1.0.5.jar:/edge/node3/current/lib/jgroups-all.jar:/edge/node3/current/lib/jline.jar:/edge/node3/current/lib/jmkv123p1.jar:/edge/node3/current/lib/jna.jar:/edge/node3/current/lib/joda-time-1.5.2.jar:/edge/node3/current/lib/jscience.jar:/edge/node3/current/lib/json-lib-2.2.1-jdk15.jar:/edge/node3/current/lib/jul-to-slf4j-1.5.6.jar:/edge/node3/current/lib/junit.jar:/edge/node3/current/lib/jython.jar:/edge/node3/current/lib/log4j-1.2.15.jar:/edge/node3/current/lib/log4j-over-slf4j-1.5.6.jar:/edge/node3/current/lib/loggablePreparedStatement-1.6.jar:/edge/node3/current/lib/looks-2.1.4.jar:/edge/node3/current/lib/mailapi.jar:/edge/node3/current/lib/model-12021.jar:/edge/node3/current/lib/mysql-connector-java-5.1.7-bin.jar:/edge/node3/current/lib/opencsv-1.8.jar:/edge/node3/current/lib/rfa.jar:/edge/node3/current/lib/rspcore.jar:/edge/node3/current/lib/slf4j-api-1.5.6.jar:/edge/node3/current/lib/slf4j-log4j12-1.5.6.jar:/edge/node3/current/lib/smtp.jar:/edge/node3/current/lib/smtphandler-0.6.jar:/edge/node3/current/lib/spring-2.5.2.jar:/edge/node3/current/lib/statsvn.jar:/edge/node3/current/lib/swingx-0.9.3.jar:/edge/node3/current/lib/t2-12021.jar:/edge/node3/current/lib/testng-5.9-jdk15.jar:/edge/node3/current/lib/tibmsg.jar:/edge/node3/current/lib/tibrvj.jar:/edge/node3/current/lib/trove.jar:/edge/node3/current/lib/velocity-tools.jar:/edge/node3/current/lib/velocity.jar:/edge/node3/current/lib/xalan.jar:/edge/node3/current/lib/xerces.jar:/edge/node3/current/lib/patng/activeio-core-3.0.0-incubator.jar:/edge/node3/current/lib/patng/activemq-core-4.1.1.jar:/edge/node3/current/lib/patng/avalon-framework-4.1.3.jar:/edge/node3/current/lib/patng/backport-util-concurrent-2.2.jar:/edge/node3/current/lib/patng/binding-1.4.0.jar:/edge/node3/current/lib/patng/cglib-nodep-2.1_3.jar:/edge/node3/current/lib/patng/common-1.30.jar:/edge/node3/current/lib/patng/commons-cli-1.0.jar:/edge/node3/current/lib/patng/commons-configuration-1.2.jar:/edge/node3/current/lib/patng/commons-discovery-0.2.jar:/edge/node3/current/lib/patng/commons-math-1.1.jar:/edge/node3/current/lib/patng/concurrent-1.3.4.jar:/edge/node3/current/lib/patng/geronimo-j2ee-management_1.0_spec-1.0.jar:/edge/node3/current/lib/patng/geronimo-jms_1.1_spec-1.0.jar:/edge/node3/current/lib/patng/logkit-1.0.1.jar:/edge/node3/current/lib/patng/mina-core-1.0.1.jar:/edge/node3/current/lib/patng/mina-filter-ssl-1.0.1.jar:/edge/node3/current/lib/patng/mina-java5-1.0.1.jar:/edge/node3/current/lib/patng/mx4j-remote-3.0.1.jar:/edge/node3/current/lib/patng/mx4j-tools-3.0.1.jar:/edge/node3/current/lib/patng/org.apache.felix.framework-1.0.0.jar:/edge/node3/current/lib/patng/org.osgi.core-1.0.0.jar:/edge/node3/current/lib/patng/pat-dt-common-1.18.jar:/edge/node3/current/lib/patng/pat-sdt-1.18.jar:/edge/node3/current/lib/patng/patNg-api-1.27.1.jar:/edge/node3/current/lib/patng/patNg-server-aoc-1.21.jar:/edge/node3/current/lib/patng/patNg-server-common-1.21.jar:/edge/node3/current/lib/patng/patNg-server-session-manager-1.21.jar:/edge/node3/current/lib/patng/patNg-utils-1.27.1.jar:/edge/node3/current/lib/patng/qpid-broker-2.2.2.0.jar:/edge/node3/current/lib/patng/qpid-client-2.2.2.0.jar:/edge/node3/current/lib/patng/qpid-common-2.2.2.0.jar:/edge/node3/current/lib/patng/qpid-mina-core-2.2.2.0.jar:/edge/node3/current/lib/patng/rsee-2.11.jar:/edge/node3/current/lib/patng/servlet-api-2.3.jar:/edge/node3/current/lib/patng/silk-1.3.jar:/edge/node3/current/lib/patng/slf4j-api-1.4.0.jar:/edge/node3/current/lib/patng/slf4j-log4j12-1.4.0.jar:/edge/node3/current/lib/patng/validation-1.2.0.jar
Boot class path: /apps/jdk/1.6.0_13/linux/jre/lib/resources.jar:/apps/jdk/1.6.0_13/linux/jre/lib/rt.jar:/apps/jdk/1.6.0_13/linux/jre/lib/sunrsasign.jar:/apps/jdk/1.6.0_13/linux/jre/lib/jsse.jar:/apps/jdk/1.6.0_13/linux/jre/lib/jce.jar:/apps/jdk/1.6.0_13/linux/jre/lib/charsets.jar:/apps/jdk/1.6.0_13/linux/jre/classes:/tmp/yjp200811122006.jar
Library path: /apps/jdk/1.6.0_13/linux/jre/lib/i386/server:/apps/jdk/1.6.0_13/linux/jre/lib/i386:/apps/jdk/1.6.0_13/linux/jre/../lib/i386::/edge/node3/current/lib:/home/eqdev/eqedgeuat/yourkit_7_5_11/yjp-7.5.11/bin/linux-x86-32:/edge/node3/current/lib:/home/eqdev/eqedgeuat/yourkit_7_5_11/yjp-7.5.11/bin/linux-x86-32:/usr/java/packages/lib/i386:/lib:/usr/lib -
When i placed a AccessKey to Submit Button (Eg: AccessKey="S"), and pressed Shift + Alt + S, the focus is going to Submit button and as well as Submit operation is also performed. Is this the expected behaviour in FireFox for AccessKeys
What were you expecting when using an accesskey?
I use that also on this forum to submit my posts:
<pre><nowiki><input accesskey="s" class="btn btn-important" value="Post Reply" type="submit">
</nowiki></pre> -
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 segmentsIn your call your referencing the array as colNames[] - it should be colNames (no []'s )
exeStmt.exeSqlStmt(sqlStmt, colNames, connectString, userName, password, 3); -
Can i load a class in subdirectoy inside a jar file using applet tag?
hi every one.. thank you for reading ... i am really in dire need for the solution..
my problem is that i have a jar file contianing a package which inturn contains my applet class...
i am trying to access this applet class using a applet tag in html file. this html file is in same directory as the jar file. i am having no problems in windows but when i am doing this in linux apache server i was getting class not found exception. (already checked the file permissions). and when i am successful when using simple package directory instead of jar file . so gist of my quesition is "can i load a class in subdirectoy inside a jar file using applet tag in a html file"?When you tested in Windows were you using Internet Explorer? On Linux you will be using a different browser, usually Mozilla of some version, or Firefox. Note that the HTML tags for applets will be different between the browsers if you are using the object tag. Principally the classid value for the object tag will differ between Firefox and Internet Explorer.
-
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 advanceI had missed a closing breacket '}'
-
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 EasterWhen 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 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 -
Double sided printing for canon
how to print double sided printing for canon mp287?
I am having the same problem. I just got a cannon MG2520 and I've been trying to print double sided...however it's not a grayed out option. This is extremely infuriating because I need to print about 50 slides off every few days for class. I've tried everything people have offered so far. There is no "duplex managing" or something to that effect when I go through systems and preferences. I read somewhere else to change format for to the specific printer and use "letter" instead of "US letter." However, US letter isn't even an option for me. I tried to go through preview and it just kept making the slides go the wrong way and wouldn't let me print multiple slides to one pages. As of now I have to manually go through, hit handouts (6 slides per page) and then count what number slides those are in order to print it right....this is extremely frustrating!! Any other suggestions would be greatly appreciated!
-
Reporting Services - How to open a second table inside report, for each number of client (each apears in first table)?
Exemple:
Table1
Cliente name:
John
Client number:
12345
Survay number of negative answers:
3
Table2
Questions and answers that were negative:
Question: How much time where you waiting
Avaluation: 3 (from 1 to 10)
Answer: They only called me 1 mouth later
Can you please help me?Hi,
Based on the description, I understand that you want to add subreport in the main report. When previewing the main report, the subreport can be shown in detail. Please see the screenshots on my test:
In Reporting Services, we can create parameters and pass them from main report to subreport in order to control the data dynamically.
References:
Subreports (Report Builder and SSRS)
Add a Subreport and Parameters (Report Builder and SSRS)
If I have any misunderstanding, please feel free to contact me.
Regards,
Heidi Duan
Heidi Duan
TechNet Community Support -
Apple apps store do double charged me for only one application purchased and i can't find an email of apple customer service.
<Email Edited By Host>These are user-to-user forums - I've asked the hosts to remove your email address from your post.
Tou can contact iTunes support here : http://www.apple.com/support/itunes/contact/ - click on Contact iTunes Store Support on the right-hand side of the page
Maybe you are looking for
-
Webi report display splits a column
Hi fairly new to Webi so I hope this doesn't sound too basic. I have a Webi report that is 30 odd columns wide (this is currently BOXI R2 on Windows 2003); it's displayed in Landscape mode and splits several columns down the middle. How can you defin
-
Hi All, I hve a different Requirement, i'm creating a rfc which execute the sql which is given by the client side n these r long single dynamic sql. MY work is to write a (dynamic)code which split this sql in different small sql acc to their join c
-
Can't find subFieldPoint.vi in Labview2013
I have updated my computer to LabVIEW2013 and I need to move a FieldPoint application over to Windows 7. My old vi says the subFieldPoint vi are no good. OK, so where are the new ones? I updated Field Point as well. Solved! Go to Solution.
-
(Persistance API) bo exception thrown from em.persist
Hi, I am testing for various error conditions , and trying to write an entity which has column defined as unique, and there is already an instance with that value in table. Although the entity does not get persisted(because of the unique constraint)
-
Server Admin won't display services after 10.4.7 update
Did combo updater from Server 10.4.4 to 10.4.7. Everything seems to be working – filesharing, Web, FTP. But Server Admin connects but then just sits there spinning. Won't show active services, etc. Workgroup Manager will let me administer accounts bu