Hi all, this simple code to check number that I wrote with java code.
public boolean isNumeric(String st){
try{
double d = Double.parseDouble(st);
}catch(NumberFormatException e){
return false;
}
return true;
}
Please enjoy and sharing your ideas!
Monday, September 29, 2014
How to check dot(.) in java code
Hi everyone, today I want to show you how to check dot(.) by using java code. The purpose of this code, we want to allow dot one time when we trigger it. example like calculator ...
Please enjoy with my code and then pls you help to comment me to improve our knowledge each other. Thanks Advance!
public boolean checkDot(String st){
char ch[] = st.toCharArray();
for(int i=0;i<ch.length;i++)
if(ch[i] =='.')
return true;
return false;
}
This code, I allow to pass arguments as String. But you can modify it by your needs. Thanks!
Please enjoy with my code and then pls you help to comment me to improve our knowledge each other. Thanks Advance!
public boolean checkDot(String st){
char ch[] = st.toCharArray();
for(int i=0;i<ch.length;i++)
if(ch[i] =='.')
return true;
return false;
}
This code, I allow to pass arguments as String. But you can modify it by your needs. Thanks!
Thursday, September 11, 2014
How to list directories, subdirectories and files using java
Hi everyone, I welcome to my post. Today I want to show you some codes using java language to list directories, subdirectories, and files. You can see my as below:
package com.saretsothea.files.classwork;
import java.io.File;
import java.util.Scanner;
/**
*
* @author Sout Saret
*/
public class ListFiles{
public static void main(String [] args){
Scanner sc = new Scanner(System.in);
String folder;
System.out.print("Please the path of folder:");
folder =sc.nextLine();
System.out.println("List all directories, subdirectries and files:");
File f = new File(folder);
System.out.println(f.getName());
listFile(folder);
}
public static void listFile(String folder){
try{
File f = new File(folder);
File[] listOfFiles = f.listFiles();
for(int i = 0; i < listOfFiles.length; i++) {
if (listOfFiles[i].isFile()) {
System.out.println("--" + listOfFiles[i].getName());
} else if (listOfFiles[i].isDirectory()) {
System.out.println("-"+listOfFiles[i].getName());
listFile(listOfFiles[i].getAbsolutePath());
}
}
}catch(NullPointerException e){}
}
}
Thanks for reading!!!!!!!!!!!!!!
package com.saretsothea.files.classwork;
import java.io.File;
import java.util.Scanner;
/**
*
* @author Sout Saret
*/
public class ListFiles{
public static void main(String [] args){
Scanner sc = new Scanner(System.in);
String folder;
System.out.print("Please the path of folder:");
folder =sc.nextLine();
System.out.println("List all directories, subdirectries and files:");
File f = new File(folder);
System.out.println(f.getName());
listFile(folder);
}
public static void listFile(String folder){
try{
File f = new File(folder);
File[] listOfFiles = f.listFiles();
for(int i = 0; i < listOfFiles.length; i++) {
if (listOfFiles[i].isFile()) {
System.out.println("--" + listOfFiles[i].getName());
} else if (listOfFiles[i].isDirectory()) {
System.out.println("-"+listOfFiles[i].getName());
listFile(listOfFiles[i].getAbsolutePath());
}
}
}catch(NullPointerException e){}
}
}
Thanks for reading!!!!!!!!!!!!!!
Subscribe to:
Comments (Atom)