Scanner input = new Scanner(System.in);
for (int i = 1 ; i <= 3 ; i++) {
int sum = 0;
for (int j = 1 ; j <= 4 ; j++) {
System.out.println("请输入"+i+"班第"+j+"位同学的成绩");
int n = input.nextInt();
sum += n;
}
double avg = sum/4;
System.out.println(i+"班的平均分为"+avg);
}
for (int i = 1 ; i <= 3 ; i++) {
int sum = 0;
for (int j = 1 ; j <= 4 ; j++) {
System.out.println("请输入"+i+"班第"+j+"位同学的成绩");
int n = input.nextInt();
sum += n;
}
double avg = sum/4;
System.out.println(i+"班的平均分为"+avg);
}
2015-06-16
public class HelloWorld{
public static void main(String[] args) {
String learn="我爱慕课网";
String website="www.imooc.com";
System.out.println(""+learn);
System.out.println(""+website);
}
}
public static void main(String[] args) {
String learn="我爱慕课网";
String website="www.imooc.com";
System.out.println(""+learn);
System.out.println(""+website);
}
}
2015-06-16
我的等腰三角形,晒一下 int a = 7;
for (int i = 1 ; i <= a ; i++ )
{
for (int k = 1; k <= a - i ; k++)
{
System.out.print(" ");
}
for (int j = 1 ; j <= 2 * i - 1 ; j++ )
{
System.out.print("*");
}
System.out.println();
}
for (int i = 1 ; i <= a ; i++ )
{
for (int k = 1; k <= a - i ; k++)
{
System.out.print(" ");
}
for (int j = 1 ; j <= 2 * i - 1 ; j++ )
{
System.out.print("*");
}
System.out.println();
}
2015-06-15
只用While也行的,还是不太清楚 用不用do,有什么区别
int sum2 = 0 ;
int num2 = 2 ;
while( num2 <= 50){
sum2 = sum2 + num2 ;
num2= num2 + 2 ;
};
System.out.println(" 50以内的偶数之和为:" + sum2);
int sum2 = 0 ;
int num2 = 2 ;
while( num2 <= 50){
sum2 = sum2 + num2 ;
num2= num2 + 2 ;
};
System.out.println(" 50以内的偶数之和为:" + sum2);
2015-06-15