Biyernes, Enero 13, 2012

Basic Act : 5 string convert to int

package javaapplication67;


import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class Main {




public static void main(String[] FileNotFoundException) throws FileNotFoundException {
File file = new File("yahoo/yahoo.in");
Scanner scanner = new Scanner (file);


while(scanner.hasNext()){


String sentence = scanner.nextLine();
String tcatch= "";
int sum = 0 ;


for (int index = 0; index < sentence.length(); index++) {




if(Character.isDigit(sentence.charAt(index))){
tcatch += sentence.charAt(index);


System.out.println(tcatch);}


}
for (int index = 0; index < tcatch.length(); index++) {
sum+= Character.digit(tcatch.charAt(index) , 10);






}
System.out.println(sum); 
}
}
}

Walang komento:

Mag-post ng isang Komento