File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ package com .xinan .test ;
2+
3+ import java .util .InputMismatchException ;
4+ import java .util .Scanner ;
5+
6+ public class Triangle {
7+ public static void main (String [] args ) {
8+ boolean flag = false ;
9+ do {
10+ try {
11+ System .out .println ("请输入三角形的高" );// 从控制台输入
12+ Scanner sc = new Scanner (System .in );
13+ int h = sc .nextInt ();
14+ while (h < 0 ) {
15+ System .out .println ("高度不能为负数" );
16+ System .out .println ("请重新输入三角形的高" );// 从控制台输入
17+ h = sc .nextInt ();
18+ }
19+ System .out .println ("请输入三角形的偏移量" );
20+ int n = sc .nextInt ();
21+
22+ // System.out.println("请输入三角形的偏移量");
23+ for (int i = 1 ; i <= h ; i ++) {
24+ for (int j = h + n ; j >= i ; j --) {
25+ System .out .print (" " );
26+ }
27+ for (int k = 1 ; k <= 2 * i - 1 ; k ++) {
28+ if ((k == 1 ) || (k == 2 * i - 1 )) {
29+ System .out .print ("*" );// 控制最外层*输出
30+ } else if (i == h ) {
31+ System .out .print ("*" );// 控制最后一行*输出
32+ } else {
33+ System .out .print (" " );// 控制中心空格的输出
34+ }
35+ }
36+ System .out .println ();
37+ }
38+ flag = false ;
39+ } catch (InputMismatchException ime ) {
40+ System .out .println ("请输入一个正整数" );
41+ flag = true ;
42+ }
43+ } while (flag );
44+ }
45+ }
Original file line number Diff line number Diff line change 1+ package com .xinan .testoop01 ;
2+
3+ public class Sanjiaoxing {
4+ public static void main (String [] args ){
5+ int num =5 ;
6+ for (int i =0 ;i <num ;i ++){
7+ for (int j =1 ;j <(5 -i );j ++){
8+ System .out .print (" " );
9+ }
10+ for (int k =0 ;k <(2 *i +1 );k ++){
11+ System .out .print ("*" );
12+ }
13+ System .out .println ();
14+ }
15+ }
16+
17+ }
Original file line number Diff line number Diff line change 1+ package test01 ;
2+
3+ public class Base
4+ {
5+ private String baseName = "base" ;
6+ public Base ()
7+ {
8+ callName ();
9+ }
10+
11+ public void callName ()
12+ {
13+ System . out . println (baseName );
14+ }
15+
16+ static class Sub extends Base
17+ {
18+ private String baseName = "sub" ;
19+ public void callName ()
20+ {
21+ System . out . println (baseName ) ;
22+ }
23+ }
24+ public static void main (String [] args )
25+ {
26+ Base b = new Sub ();
27+ }
28+ }
Original file line number Diff line number Diff line change 1+ package test01 ;
2+
3+ public class Test02 {
4+ public static void main (String [] args ){
5+ short a =128 ;
6+ byte b =(byte )a ;
7+ System .out .println (a );
8+ System .out .println (b );
9+ }
10+ }
Original file line number Diff line number Diff line change 1+ package test01 ;
2+
3+ public class Test03 {
4+ public static void main (String [] args ){
5+ boolean b =true ?false :true ==true ?false :true ;
6+ System .out .println (b );
7+ }}
You can’t perform that action at this time.
0 commit comments