Java: How to accept args inputs with spaces in-between [closed] - java

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 1 year ago.
Improve this question
If I were to run my code using java example hello 3 the output would be hello 3
However, if I want to run java example hello world 3 the output would be hello world not hello world 3
How would I fix this?
public static void main(String[] args){
String t = args[1];
int s = Integer.parseInt(args[0]);
System.out.println(t)
System.out.println(s)

Taken from this answer: https://stackoverflow.com/a/17619865/6590339
You can use quotes when you want an argument to have a space in it:
$java example "hello 3"

Related

How to print words containing unicode? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 1 year ago.
This post was edited and submitted for review 1 year ago and failed to reopen the post:
Original close reason(s) were not resolved
Improve this question
I need to print Swedish words that contain unicode using Java
how can I do it?
for example
Text with Unicode:- \u228sk\u228da
Output: åskåda
Both of the following would work:
class Main {
public static void main(String args[]) {
System.out.println("åskåda");
System.out.println("\u00e5sk\u00e5da");
}
}
Note that you need to use the hex values and must take care of specifying the encoding when reading data (from disk or network)

Need to extract a specific number from a string with several numbers using Selenium [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
I need to get 293 as an int from the string "1 to 20 of 293 total". I'm unable to do it using .replaceAll method. Please help
try this :
String s = "1 to 20 of 88 total";
String k [] = s.split("1 to 20 of");
String t [] = k[1].split("total");
System.out.println(Integer.valueOf(t[0].replaceAll("\\s+","")));

Error with String[] and writeObject [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
In writeObject of FileOutputStream we declare one String Array that time error are occurs.
My Code is
writeObject(String[] str {"1"});
To begin with, 1 is not a String .
Also, your syntax is not correct to pass the array , try this way :
yourObjectOutputStream.writeObject(new String[] {"1"});
Or if you prefer
String[] str = new String[] {"1"};
yourObjectOutputStream.writeObject(str);

How do I reverse a number in java [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 13 days ago.
Improve this question
Can anyone explain to me how to reverse a number start with zero in java. I trying to reverse a number 025 but output is only 52. But output should be 520
explanation much appreciated.
You are mixing types. "025" is not a number, it's a String. In a number you simply cannot distinguish between 25, 025, 0025, 00025, ... Implement your assignment as a String operation.
public String reverseString(String s) {
// put your code here
}
You may find very useful the Oracle tutorial on Strings here: https://docs.oracle.com/javase/tutorial/java/data/strings.html

How to power to negative number? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I'm trying to power something to negative number but it always gives me NaN or Infinity.
How to make eg. 1.25^(-5) ?
The following code:
public class HelloWorld{
public static void main(String []args){
System.out.println(Math.pow(1.25, -5));
}
}
prints:
0.32768
Here is a working code snippet
You can use the Math.pow() method
Math.pow(1.25, -5)

Categories

Resources