import java.util.Scanner;
public class d98{
public static void main(String args[])
{
Scanner ss = new Scanner(System.in);
while(ss.hasNext())
{
String str[]=ss.nextLine().split("[ ]+");
int alw=0;
for(int i=0;i<str.length;i++)
{
Boolean tf=true;
for(int j=0;j<str[i].length();j++)
if(str[i].charAt(j)<'0' || str[i].charAt(j)>'9')
{
tf=false;
}
if(tf==true)
alw+=Integer.parseInt(str[i]);
}
System.out.println(alw);
}
}
}
應該是沒考慮到空字串 ""
import java.util.Scanner;
public class D098{
public static void main(String args[])
{
Scanner ss = new Scanner(System.in);
while(ss.hasNext())
{
String str[]=ss.nextLine().split("[ ]");
System.out.print(str[0]+" "+str[1]);
int alw=0;
for(int i=0;i<str.length;i++)
{
if(!(str[i].equals(""))){
Boolean tf=true;
for(int j=0;j<str[i].length();j++)
if(str[i].charAt(j)<'0' || str[i].charAt(j)>'9')
{
tf=false;
}
if(tf==true)
alw+=Integer.parseInt(str[i]);
}
}
System.out.println(alw);
}
}
}
應該是沒考慮到空字串 ""
import java.util.Scanner;
public class D098{
public static void main(String args[])
{
Scanner ss = new Scanner(System.in);
while(ss.hasNext())
{
String str[]=ss.nextLine().split("[ ]");
System.out.print(str[0]+" "+str[1]); <多打的...
int alw=0;
for(int i=0;i
{
if(!(str[i].equals(""))){
Boolean tf=true;
for(int j=0;j
if(str[i].charAt(j)<'0' || str[i].charAt(j)>'9')
{
tf=false;
}
if(tf==true)
alw+=Integer.parseInt(str[i]);
}
}
System.out.println(alw);
}
}
}
把綠色那行刪掉即可
測試後忘記把他刪除....= ="