如何编写九九乘法表:
public class a {
public static void main(String[] args){
int i,j;
for(i=1;i<=9;i++)
{
for(j=1;j<=i;j++)
System.out.print(i+"*"+j+"="+i*j+" ");
System.out.print('\n');
}
}
}
计算三个整数的总和和平均值并输出:
import java.util.Scanner;
public class Lin {
public static void main(String[] args){
Scanner dn=new Scanner(System.in);
Scanner en=new Scanner(System.in);
Scanner fn=new Scanner(System.in);
int a,b,c,sum,average;
a=dn.nextInt();
b=en.nextInt();
c=fn.nextInt();
sum=a+b+c;
average=sum/3;
System.out.println(sum);
System.out.print(average);
}
}
打印金字塔型:
import java.util.Scanner;
public class lu {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
int i,j,n;
n=sc.nextInt();
for(i=1;i<=n;i++)
{
for(j=n-i;j>=1;j--)
System.out.print(' ');
for(j=2*i;j>1;j--)
System.out.print('*');
System.out.print('\n');
}
}
public class a {
public static void main(String[] args){
int i,j;
for(i=1;i<=9;i++)
{
for(j=1;j<=i;j++)
System.out.print(i+"*"+j+"="+i*j+" ");
System.out.print('\n');
}
}
}
计算三个整数的总和和平均值并输出:
import java.util.Scanner;
public class Lin {
public static void main(String[] args){
Scanner dn=new Scanner(System.in);
Scanner en=new Scanner(System.in);
Scanner fn=new Scanner(System.in);
int a,b,c,sum,average;
a=dn.nextInt();
b=en.nextInt();
c=fn.nextInt();
sum=a+b+c;
average=sum/3;
System.out.println(sum);
System.out.print(average);
}
}
打印金字塔型:
import java.util.Scanner;
public class lu {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
int i,j,n;
n=sc.nextInt();
for(i=1;i<=n;i++)
{
for(j=n-i;j>=1;j--)
System.out.print(' ');
for(j=2*i;j>1;j--)
System.out.print('*');
System.out.print('\n');
}
}
}