9*9乘法表
public class test{
public static void main(String[] args) {
for (int x=1;x<=9 ;x++ )//x控制行,y控制列,因为起始值是1*1,所以x和y的初始值要设成1
{
for (int y=1;y<=x;y++ )
{
System.out.print(y+"×"+x+"="+x*y+"\t");//从行上面看,第一个数是变动的,而且是每一列加1,所以第一个数是变量y
<span style="white-space:pre"> </span>//第二个数每行都没有变动,所以第一个数是变量x,/t的作用是为了美观,方便查看
}
System.out.println();
}
}
}
class test1 //输出三个数中最大的数。方法一:
{
public static void main(String[] args)
{
int max=0;
int a=9;
int b=5;
int c=6;
if (a>b)
{
if (a>c){
max=a;
}
}else
if (b>c)
{
max=b;
}else
{max=c;}
System.out.println(max);
}
}
class test2 //输出三个数中最大的数。方法二:
{
public static void main(String[] args)
{
int max=0;
int a=4;
int b=9;
int c=6;
max=(a>b?a:b)>c?(a>b?a:b):c;
System.out.println(max);
}
}
import java.util.Arrays; //导入包 具体的可以去下个中文版API文档查看
class test3 //输出三个数中最大的数。方法三:
{
public static void main(String[] args)
{
int max=0;
int a=4;
int b=9;
int c=6;
int[] x ={a,b,c};
Arrays.sort(x);
System.out.println(x[x.length-1]);
}
}
多方法比较
最新推荐文章于 2020-09-14 19:42:14 发布