6.打印九九乘法表 - /* //九九乘法表
- import java.util.Scanner;
- class 练习题集合{
- public static void main (String [] args ){
- Scanner sc = new Scanner(System.in);
- System.out.println("请输入乘法表结束位数");
- int x = sc.nextInt();
-
- for (int i = 1; i <= x; i++ ) {
- for (int j=1; j<=i ; j++) {
- System.out.print(i+"*"+j+"="+i*j+"\t");
- }
- System.out.println();
- }
- }
- }
- */
复制代码
7.打印倒三角星星
- /* //打印倒三角星星
- class temp {
- public static void main (String[] args) {
- for (int i = 6; i >= 1;i--) {
- for (int j=1;j<=i; j++ ) {
- System.out.print("*");
- }
- System.out.println();
- }
- }
- }
-
- */
复制代码
8.键盘录入行数,列数,通过构造函数的方法打印出相应的图形。 - //键盘录入行数,列数,通过构造函数的方法打印出相应的图形。
- import java.util.Scanner;
- class 练习题集合 {
- public static void main (String[]args){
- Scanner sc = new Scanner(System.in);
- System.out.println ("请输入行数");
- int a = sc.nextInt();
- System.out.println ("请输入列数");
- int b = sc.nextInt();
- System.out.println();
- getXing(a,b);
- }
- public static void getXing (int a, int b) {
- for (int i = 1;i<=a ;i++ ) {
- for (int j=1;j<=b; j++ ) {
- System.out.print("*");
- }
- System.out.println();
- }
- return;
- }
- }
- */
复制代码
9.构造方法,输出构造方法,输出数组中的最大数- /* 翻转数组并打印数组
- class Temp {
- public static void main (String[] args) {
- int[] arr = {11,22,33,44,55,66};
-
- reArray (arr);
- print (arr);
- }
- public static void reArray (int[] arr) {
- for (int i = 0; i < arr.length/2; i++) {
- int temp = arr[i];
- arr[i] = arr[arr.length - 1 - i];
- arr[arr.length - 1 - i] = temp;
- }
- return;
- }
- public static void print (int[] arr) {
- for (int i = 0;i < arr.length; i++ ) {
- System.out.print(arr[i]+" ");
- }
- return;
- }
- }
- */
复制代码
10.翻转数组并打印数组- /* 翻转数组并打印数组
- class Temp {
- public static void main (String[] args) {
- int[] arr = {11,22,33,44,55,66};
-
- reArray (arr);
- print (arr);
- }
- public static void reArray (int[] arr) {
- for (int i = 0; i < arr.length/2; i++) {
- int temp = arr[i];
- arr[i] = arr[arr.length - 1 - i];
- arr[arr.length - 1 - i] = temp;
- }
- return;
- }
- public static void print (int[] arr) {
- for (int i = 0;i < arr.length; i++ ) {
- System.out.print(arr[i]+" ");
- }
- return;
- }
- }
- */
复制代码 11.构造方法,找到数组中的某个值,并输出序号- /*
- //构造方法,找到数组中的某个值,并输出序号
- class temp {
- public static void main (String[] args) {
-
- int[] arr = {11,22,33,44,55,66,77,88,99,88};
- int value = getValue(arr,88);
- System.out.println (value);
- }
- public static int getValue (int[] arr, int value) {
- for (int i = 0; i < arr.length; i++ ) {
- if (arr[i]==value) {
- return i;
- }
-
- }
- return -1;
- }
-
-
- }
- */
复制代码
|