|
import java.util.Scanner;
public class test
{
public static final int SENTINEL = -1;
public static void main(String[] args) {
Scanner kb = new Scanner(System.in);
int score = 0;
int sum = 0;
System.out.println("Enter numbers here");
while (score >= 0) {
if (score <= -1) {
score = kb.nextInt();
sum += score;
score = 0;
}
System.out.println(sum);
}
}
}
|
|
|
|
|
If there are any deadlock cases in production environment, then, how can we identify it?
|
|
|
|
|
Code analysis, unit testing, full testing etc. Try Google (again) to find research papers on the subject.
|
|
|
|
|
Quote: A deadlock occurs when two or more threads in the JVM form a cyclic dependency with each other.
Quote: Click to Tweet
So, How to Diagnose and Troubleshoot Java Deadlocks?
There are various options available to troubleshoot deadlock situations.
1. The naïve way: Kill the process and cross your fingers
You could kill the application server process and hope that when the application server starts again, the problem will go away. However, restarting the application server is a temporary fix that will not resolve the root-cause. Deadlocks could get triggered again when the application server comes back up.
2. The laborious way: Take thread dumps in your cluster of JVMs
You could take thread dumps. To trigger a thread dump, send a SIGQUIT signal to the JVM. (On UNIX, that would be a “kill -3” command and on Windows, that would be a “Ctrl-Break” in the console).
Typically, you would need to capture a series of thread dumps (example: 6 thread dumps spaced 20 seconds apart) to infer any thread patterns – just a static thread dump snapshot may not suffice
modified 5-Dec-18 6:43am.
|
|
|
|
|
hi..I need generate a Random array for make a bank account number. the users can have several account number. I defined account number in a class with name "user". how can i define this in this class and how can I use that in main class? 
|
|
|
|
|
Why a random value? Bank account numbers need to be unique so you should use a sequencing system so each generated number is greater than the previous.
|
|
|
|
|
this is just a class project..so I need get a Random number..random array..how can I?
|
|
|
|
|
|
i want generate some Random numbers..then put them in a array..this array is the bank account numbers for each user..now how can I define this in new class?
|
|
|
|
|
Decide how long the array needs to be and then generate a random value for each element in the array.
|
|
|
|
|
The array is Unknown.. may 1, may 2, may10!!!
|
|
|
|
|
Sorry, I have no idea what that is supposed to mean. Try showing the actual Java code that you are trying to use.
|
|
|
|
|
Is
javascript is overcoming by web assembly language ??
|
|
|
|
|
This forum is for technical issues with Java. Javascript is something totally different, and Google will most likely be the best source for your query.
|
|
|
|
|
|
hey I have code to write code in java and I need help can someone write this code for me ?
Write a program that will allow a user to play Aristotle's Puzzle. You must use a class Tile.java that represents each tile, the class must have two variables:
-boolean placed
-int value
You must use 2 arrays of Tiles:
the board
the available Tiles for placement
|
|
|
|
|
Short answer: No.
Longer answer: Your homework is given to test your knowledge, not to test your ability to get someone else to do your work. Think about the problem, write some notes about the properties that you need to create, the methods required to move the objects around etc. You may find that it is not as difficult as you think.
|
|
|
|
|
I don’t gonna do it I’m willing to pay someone to do it for me 
|
|
|
|
|
This is still the wrong place.
|
|
|
|
|
.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
import java.util.*;
import java.io.*;
class Codechef
{
public static void main(String[] args) throws Exception
{
BufferedReader a=new BufferedReader(new InputStreamReader(System.in));
int tc=Integer.parseInt(a.readLine());
Solution s = new Solution();
for(int i=0;i<tc;i++)
s.solve();
}
}
class Solution
{
boolean check(String str,List<String> list)
{
if(list.indexOf(str)!=-1)
return true;
return false;
}
void sum(List<Double> list)
{
Double temp = 0.0;
for (double i: list)
temp += i;
int result=temp.intValue();
System.out.println(result);
}
void solve() throws Exception
{
BufferedReader b=new BufferedReader(new InputStreamReader(System.in));
int n=Integer.parseInt(b.readLine());
String str;
double temp;
int result;
List<String> wordlist = new ArrayList<String>();
List<Double> timelist = new ArrayList<Double>();
for(int k=0;k<n;k++)
{
str = b.readLine();
if(check(str,wordlist))
{
int i= wordlist.indexOf(str);
temp = timelist.get(i);
temp = temp/2;
timelist.add(temp);
}
else
{
temp = 2;
for(int i=1;i<str.length();i++)
{
if(str.charAt(i)=='d' || str.charAt(i)=='f')
if(str.charAt(i-1)!='d' && str.charAt(i-1)!='f')
temp+=2;
else
temp+=4;
if(str.charAt(i)=='j' || str.charAt(i)=='k')
if(str.charAt(i-1)!='j' && str.charAt(i-1)!='k')
temp+=2;
else
temp+=4;
}
wordlist.add(str);
timelist.add(temp);
}
}
sum(timelist);
}
}
|
|
|
|
|
The error means that the string that was entered contains characters that cannot be converted to an integer. Check what is being input.
|
|
|
|
|
This error occurs when you input an argument to a function that has to convert the types of the data, such as in your case, from String to integer. To actually understand the problem do this simple thing, remove the throws Exception from the signature of the methods,
void solve() throws Exception This will lead you to the function that is most likely to throw the NumberFormatException (which is derived from Exception ), and it will lead you to the function call,
int n=Integer.parseInt(b.readLine()); The problem here is that the number that you are trying to input is not a valid number. I would rewrite the code in this way,
try {
int n = Integer.parseInt(b.readLine());
} catch (NumberFormatException exception) {
System.out.println("The input is invalid for this program to continue.");
} catch (Exception error) {
System.out.println("Unhandled error has occurred, information provided: " + error.getMessage());
} Remember, there is nothing that you can do to overcome this error, other than politely asking the user to enter the correct format of the number. This exception tells you that the number cannot be converted to that type—Integer. This means, that the number you are trying to input is correct, yet the NumberFormatException happens, the reason is that your number might be bigger than the MAX_VALUE for Integer type. Try using Long.parseLong() , or another type for the data that is overflowing.
Just for thought, read this as well, java - Integer.parseInt number format exception? - Stack Overflow
Number (Java Platform SE 7 )
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
hello,
If we call gc() method in our program on writing System.gc() and define finalize() in the same class . finalize() method exists in Object class so if i write the following code then i don't extend the Object class using extends keyword . So how the finalize() method is overridden in our class?? Or without using extends keyword how it it possible that the finalize() method is overridden??
public class fin {
public void finalize()
{
System.out.println("finalize called");
}
public static void main(String[] args) {
fin f1=new fin();
fin f2=new fin();
f1=null;
f2=null;
System.gc();
}
}
|
|
|
|
|
You should never call System.gc in your application. What exactly are you trying to achieve with this code?
|
|
|
|