Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
Is there any way that I can input image at runtime using java? Like we ask user to input Integer and use the function input.nextInt().
Also I want to put restriction that input image is only of jpeg type ?
public static Boolean isJPEG(File filename) throws IOException {
DataInputStream ins = new DataInputStream(new BufferedInputStream(new FileInputStream(filename)));
try {
if (ins.readInt() == 0xffd8ffe0) {
return true;
} else {
return false;
}
} finally {
ins.close();
}
}
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 months ago.
Improve this question
private Boolean validatePass() {
String val = pass.getEditText().getText().toString().trim();
String passwordVal = "^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!#$%^&*-]).{8,}$";
if (val.isEmpty()) {
pass.setError("*Required");
return false;
} else if (!val.matches(passwordVal)) {
pass.setError("Invalid Password");
return false;
} else {
pass.setError(null);
return true;
}
}
I used this code for password Validation, what's wrong with this?
As per what your regex code is it should satisfy for all the symbols mentioned there #,?,!,#,$,%,^,&,*,- it will fail if you use symbols other than these like _,+,~,`
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
can anybody help me to stopp this infity loop?
This loop shoud stopp if an input is a String.
All digits should be added to a list.
Thank you!
public static void main(String[] args) {
addDigitsToList();
}
public static void addDigitsToList() {
ArrayList<Integer> list = new ArrayList<Integer>();
int input = 0;
while (true) {
try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
input = Integer.parseInt(reader.readLine());
list.add(input);
} catch (NumberFormatException | IOException e) {
for (Integer integer : list) {
System.out.println(integer);
}
}
}
}
If you want to stop the infinity loop than use the keyword
break;
on which condition you want to stop it. You told us to stop when the input is a string than you should update your code-
Right after the for loop add this :
break;
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
if I have
String a = "abc,,,";
what should I do to get
result[0].equals("abc");
result[1].equals(",,,");
The most elementary way is this:
final int pos = a.indexOf(',');
if( pos == -1 ) { // character not found, handle this case somehow }
String [] result = new String [2];
result[0]=a.substring(0, pos);
result[1]=a.substring(pos);
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
Following is the source string. And I need to extract the values from this string.
String str = "sid=2096349073&name=Sam_Michaels";
For example, I should get the token value as "2096349073" and next token should be "Sam_Michaels"
You don't need StringTokenizer. This will work same
public class NewClass {
public static void main(String[] args) {
String str = "sid=2096349073&name=Sam_Michaels";
String id=str.substring(1+str.indexOf("="),str.indexOf("&"));
String name=str.substring(1+str.lastIndexOf("="));
System.out.println("Id is : "+id);
System.out.println("name is : "+name);
}
}
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have a program that reads a file in order to sort the file alphabetically. So the output of the program is displayed in an ascending order (From A-Z if applies). However, I want my program to just output the first 100 words by ignoring the rest of it. Is there a Unix command that allows me to carry out this function? or do I have to implement a code/algorithm within my program in order to accomplish it?
It should be something like:
Scanner sc2 = null;
try {
sc2 = new Scanner(new File("file.txt"));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
int numberword=100;
int count=0;
while (sc2.hasNextLine() && count<numberword) {
Scanner s2 = new Scanner(sc2.nextLine());
boolean b;
while (b = s2.hasNext() && count<numberword) {
String s = s2.next();
count++;
System.out.println(s);
}
}