This is the program I'm trying to run. I have tried on two different systems and I get the exact same error message on both. I get the error message whenever I enter a price with a decimal e.g 4.2.
Code for the program:
package grocerylist;
import java.util.Scanner;
public class GroceryList {
public static void main(String[] args) {
float [] prices = new float [5];
Scanner in = new Scanner (System.in);
System.out.println("Enter 5 prices: ");
prices[0] = in.nextFloat();
prices[1] = in.nextFloat();
prices[2] = in.nextFloat();
prices[3] = in.nextFloat();
prices[4] = in.nextFloat();
float total = prices[0] + prices[1] + prices[2] + prices[3] + prices[4];
System.out.println("The total of the 5 items are: "+total);
}
}
The error message is on line 12 and goes like this:
Exception in thread "main" java.util.InputMismatchException
at java.util.Scanner.throwFor(Scanner.java:864)
at java.util.Scanner.next(Scanner.java:1485)
at java.util.Scanner.nextFloat(Scanner.java:2345)
at grocerylist.GroceryList.main(GroceryList.java:21)
C:\Users[username]\AppData\Local\NetBeans\Cache\8.2\executor-snippets\debug.xml:83: Java returned: 1
The solution was simpler than what I first imagined. #DualCoreMax had the right mindset for the solution. Which was, when the user is typing in prices the user needs to use the comma sign to diffrenciate between the integer number and decimal number.
I seriously thought I had a way more major problem on my hands here, glad is is just a matter of my own stupidity. Thank you to everyone who came to help me, a first year student.
Related
ive been working on generating details and for almost no reason some of the deserts just dont get any details.
NativeArray<Detail> details = new NativeArray<Detail>(chunk.GetBiome().details, Allocator.Persistent);
Debug.Log(chunk.GetBiome().id + "'s details length = " + details.Length);
right here i pass in the details array to my job.
And this is what it logs
public GetMeshData(ChunkData chunkData, NativeArray<Vector3> vertices, NativeArray<Vector2> uvs, NativeArray<int> triangles, NativeArray<float> noiseMap, NativeArray<Color> colorMap, NativeArray<TerrainColor> terrainColors,
NativeArray<Detail> details, NativeList<DetailPlacement> detailPlacements, float detailsChance)
{
this.chunkData = chunkData;
this.meshData = new MeshData(vertices, uvs, triangles, detailPlacements);
this.noiseMap = noiseMap;
this.colorMap = colorMap;
this.terrainColors = terrainColors;
this.details = details;
this.detailsChance = detailsChance;
}
This is the constructor for the job where my details array is passed.
MeshData temporaryMeshData = MeshGeneration.GenerateMesh(chunkData, noiseMap, meshData.triangles, meshData.vertices, meshData.uvs, details, meshData.detailPlacements, detailsChance);
These are now used in this method.
Now here’s the weird part. When I log details.length in the method.
public static MeshData GenerateMesh(ChunkData chunkData, NativeArray<float> heightmap, NativeArray<int> triangles,
NativeArray<Vector3> vertices, NativeArray<Vector2> uvs, NativeArray<Detail> details, NativeList<DetailPlacement> detailPlacements, float detailChance)
{
Debug.Log("detail length sent into mesh method = " + details.Length);
It’s now empty
This problem shows up in and off this was just an example of a time where the problem occurred happens with one of 3 deserts usually.
Update: i tried to make it so all job structs were being processed at the time by making it so that there will only be a job struct for each thread and when one finished it would grab the next one from the ones waiting. This had no effect.
I am using Eclipse to run my java programs but there is a problem with Eclipse's console that the input and output appears in the same console. For example
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int t = scan.nextInt();
while(t-- > 0) {
int n = scan.nextInt();
System.out.println(n);
}
scan.close();
}
For this code let the input be
2
3
4
then the output that i gets looks like
2
3
43
4
Is there any way to get separate input and output and get the distinction in eclipse.
One could re-assign System.in and/or System.out as discussed here.
Of course, this is not Eclipse-specific solution but a Java one.
I would be working with files in first place.
I want to get all audit entries from an Alfresco audit application.
Following the Alfresco Audit REST API documentation, I wrote this query:
curl -u admin:admin "http://localhost:8080/alfresco/service/api/audit/query/audit-custom?fromId=1&toId=100000&fromTime=2017-02-19T18:46:09.212+09:00&toTime=2017-02-20T18:46:09.212+09:00&user=admin&forward=true&limit=0&verbose=true"
(Note the fromTime={2017-02-19T18:46:09.212+09:00}&toTime={2017-02-20T18:46:09.212+09:00} part)
PROBLEM: This returns the exact same 90 results as the request without the fromTime and toTime parameters. By the way, I installed Alfresco on 2017-02-21 so the query above should actually return zero results.
Same problem with { and } characters around the dates
Same problem with simpler dates like fromTime={2017-02-19}&toTime={2017-02-20}
Same problem without the extra parameters
How to use correctly the fromTime and toTime parameters?
It is not obvious in the documentation, but fromTime and longTime must be entered as long values.
Here is the relevant Alfresco source code:
public static final String PARAM_FROM_TIME = "fromTime";
protected Long getParamFromTime(WebScriptRequest req)
{
String paramStr = req.getParameter(PARAM_FROM_TIME);
try
{
return Long.parseLong(paramStr);
}
catch (NumberFormatException e)
{
return DEFAULT_TO_TIME;
}
}
As you can see, format problems are quietly dropped, and default values used instead, which is what is happening with the requests included in the question above.
With long values, a valid request could be:
curl -u admin:admin "http://localhost:8080/alfresco/service/api/audit/query/audit-custom?fromTime=1485152993728&toTime=1485239393728&verbose=true"
(Note the fromTime=1485152993728&toTime=1485239393728 part)
Here is a convenient Java snippet to convert dates to long values when performing tests:
import java.util.concurrent.TimeUnit;
public class Main {
public static void main(String[] args) {
long now = System.currentTimeMillis();
long lastMonth = now - TimeUnit.DAYS.toMillis(30);
long lastMonthPlusOne = now - TimeUnit.DAYS.toMillis(29);
System.out.println("Now:" + now);
System.out.println("Last month:" + lastMonth);
System.out.println("Last month plus one day:" + lastMonthPlusOne);
}
}
I am trying to write a simple Java program that reads from JBossMQ's jms_messages table using JDBC. I am using JBoss 4.0.4.GA.
I can get the as far as getting a SpyMessage, but how can I get the actual message content (which is an Object in the particular case I'm looking at).
I have a result set "rs" from this statement:
SELECT messageid, messageblob FROM jms_messages WHERE DESTINATION LIKE 'TOPIC.MyTopic%' limit 3"
and then I do this (based on JBoss code):
long messageid = rs.getLong(1);
SpyMessage message = null;
byte[] st = rs.getBytes(2);
ByteArrayInputStream baip = new ByteArrayInputStream(st);
ObjectInputStream ois = new ObjectInputStream(baip);
message = SpyMessage.readMessage(ois);
message.header.messageId = messageid;
String jmstype = message.getJMSType();
String jms_message_id = message.getJMSMessageID();
System.out.println("jmstype=" +jmstype);
System.out.println("jms_message_id=" +jms_message_id);
String propertyName;
Enumeration e = message.getPropertyNames();
while (e.hasMoreElements())
{
propertyName = (String)e.nextElement();
System.out.println("property name = " +propertyName);
}
but I get no properties printed and I don't know how to get my actual object from the SpyMessage (actually a SpyObjectMessage). I'd be grateful for any pointers.
I've tried asking this question on the JBoss forum without reply, so I'm hoping for better luck here.
Thanks.
Sorry - the answer was so obvious I'm not really sure what I was thinking when I posted the question - simply:
Object objMessage = ((SpyObjectMessage)message).getObject();
I'm using GWT on the client side. I store String objects in an ArrayList instance, and when I add the value "AT&T", it only seems to be storing "AT". I suspect this is the result of the ArrayList truncating the text due to the ampersand, but I have yet to write a smaller proof-of-concept to be sure. Has anyone else encountered this problem?
GWT 2.1.1
Tomcat 7.0.5
Firefox 5.0.1
So this test succeeds:
ArrayList<String> test = new ArrayList<String>();
test.add( "testing&123");
Window.alert( test.get(0) + " - " + test.get(0).contains("&") );
My code effectively does this:
String test = "AT&T";
MyApp.getInstance().getDataStore().add( test );
Window.alert( test + " - " + MyApp.getInstance().getDataStore().getItems().get(0) );
public void DataStore.add( String item ) {
itemsList.add( item );
}
public ArrayList<String> getItems() {
return itemList;
}
The output is "AT&T - AT". So if the ArrayList is not the problem, is it the method calls?
Well, it turns out it was an interaction between my History Manager and the DataStore class. A very strange situation that no one could have helped me with given the limited amount of information I had provided.