zoukankan      html  css  js  c++  java
  • Java基础语法2

    转载请注明出处:https://blog.csdn.net/Mercury_Lc/article/details/82800547 作者:Mercury_Lc

    SDUT Java基础语法练习2

    I       C语言实验——打印菱形(SDUT 1174)

    
    import java.util.Scanner;   
    
    public class Main {
    	public static void main(String[] args) {
    		Scanner sc = new Scanner(System.in);
    		int n;
    		n = sc.nextInt();
    		for(int i = 0; i < n; i ++) 
    		{
    			for(int j = 0; j < n - i - 1; j ++)System.out.print(" ");
    			for(int j = 0; j < i + 1; j ++)System.out.print('*');
    			for(int j = 0; j < i; j ++)System.out.print('*');
    			System.out.println("");
    		}
    		for(int i = n - 2; i >= 0; i --)
    		{
    			for(int j = 0; j < n - i - 1; j ++)System.out.print(" ");
    			for(int j = i; j >= 0 ; j --)System.out.print('*');
    			for(int j = i; j >= 1; j --)System.out.print('*');
    			if(i != 0 )System.out.println("");
    		}
    	}
    }
    

    C语言实验——打印数字图形(SDUT 1179)

    
    import java.util.Scanner;   
    
    public class Main {
    	public static void main(String[] args) {
    		Scanner sc = new Scanner(System.in);
    		int n;
    		n = sc.nextInt();
    		for(int i = 0; i < n; i ++) 
    		{
    			for(int j = 0; j < n - i - 1; j ++)System.out.print(" ");
    			for(int j = 0; j < i + 1; j ++)System.out.print(j + 1);
    			for(int j = 0; j < i; j ++)System.out.print(i - j);
    			System.out.println("");
    		}
    		for(int i = n - 2; i >= 0; i --)
    		{
    			for(int j = 0; j < n - i - 1; j ++)System.out.print(" ");
    			for(int j = i; j >= 0 ; j --)System.out.print(i - j + 1);
    			for(int j = i; j >= 1; j --)System.out.print(j);
    			if(i != 0 )System.out.println("");
    		}
    	}
    }
    

    k     做乘法(SDUT 2249)

    
    import java.util.Scanner;
    
    public class Main {
    	public static void main(String[] args) {
    		Scanner sc = new Scanner(System.in);
    		int n;
    		n = sc.nextInt();
    		for (int i = 1; i <= n; i++) {
    			System.out.println(n + "*" + i + "=" + n * i);
    		}
    	}
    }
    

    L   期末考试之分等级(SDUT 2251)

    
    import java.util.Scanner;
    
    public class Main {
    	public static void main(String[] args) {
    		Scanner sc = new Scanner(System.in);
    		int n, x;
    		n = sc.nextInt();
    		int a, b, c, d, e;
    		a = b = c = d = e = 0;
    		for (int i = 0; i < n; i++) {
    			x = sc.nextInt();
    			if (x >= 90)a++;
    			else if (x < 90 && x >= 80)b++;
    			else if (x < 80 && x >= 70)c++;
    			else if (x < 70 && x >= 60)d++;
    			else if (x < 60) e++;
    		}
    		System.out.print('A' + " " + a + "
    " + 'B' + " " + b + "
    " + 'C' + " " + c + "
    " + 'D' + " " + d + "
    " + 'E'
    				+ " " + e + "
    ");
    	}
    }
    

    M     C语言实验——矩阵转置(SDUT 1164)

    
    import java.util.Scanner;
    import java.util.Arrays;
    
    public class Main {
    	public static void main(String[] args) {
    		Scanner sc = new Scanner(System.in);
    		int n;
    		int a[][] = new int[1000][1000];
    		n = sc.nextInt();
    		for (int i = 0; i < n; i++) {
    			for (int j = 0; j < n; j++) {
    				a[i][j] = sc.nextInt();
    			}
    		}
    		for (int i = 0; i < n; i++) {
    			for (int j = 0; j < n; j++) {
    				if (j != n - 1)
    					System.out.print(a[j][i] + " ");
    				else
    					System.out.print(a[j][i]);
    			}
    			System.out.println("");
    		}
    	}
    }
    

    N      C语言实验——矩阵下三角元素之和(SDUT 1172)

    package ll;
    
    import java.util.Scanner;
    
    public class Main {
    	public static void main(String[] args) {
    		Scanner sc = new Scanner(System.in);
    		int a[][] = new int[100][100];
    		int n;
    		n = sc.nextInt();
    		int sum = 0;
    		for (int i = 1; i <= n; i++) {
    			for (int j = 1; j <= n; j++) {
    				a[i][j] = sc.nextInt();
    				if (i >= j)
    					sum += a[i][j];
    			}
    		}
    		System.out.println(sum);
    	}
    }
    
  • 相关阅读:
    Go基础系列:流程控制结构
    Go基础系列:数据类型转换(strconv包)
    Go基础系列:简单数据类型
    Go基础系列:常量和变量
    Go基础系列:map类型
    Go基础系列:Go slice详解
    go基础系列:数组
    Go基础系列:import导包和初始化阶段
    Go基础系列:构建go程序
    go基础系列:结构struct
  • 原文地址:https://www.cnblogs.com/lcchy/p/10139517.html
Copyright © 2011-2022 走看看