import java.io.*;
public class Sumloop {
public static void main(String[] args)
throws IOException
{
int s=0;
String output="";
BufferedReader stadin =
new BufferedReader(
new InputStreamReader(System.
in));
System.
out.println("請輸入a的值");
String input =stadin.readLine();
for(
int i =1;i<=Integer.
parseInt(input);i++)
{
output+=input;
int a=Integer.
parseInt(output);
s+=a;
}
System.
out.println(s);
}
}
另解:
import java.io.*;
public class Sumloop {
public static void main(String[] args)
throws IOException
{
int s=0;
int n;
int t=0;
BufferedReader stadin =
new BufferedReader(
new InputStreamReader(System.
in));
String input = stadin.readLine();
n=Integer.
parseInt(input);
for(
int i=1;i<=n;i++){
t=t*10+n;
s=s+t;
System.
out.println(t);
}
System.
out.println(s);
}
}
*