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);
    	}
    }
    
  • 相关阅读:
    Manjaro 安装与初步使用
    hp 820 G3 驱动安装不上
    Linux Mint
    PHP模板引擎原理
    报名系统跟商品购物有点类似,可以参考一下他们的ER图
    tp5接口开发流程(思路版)
    mysql中主键和外键的作用,主表和从表如何区分,以及如何使用联合查询和TP5的联合查询
    关于会员-考生-考生自定义表单-预览打印
    PHP unserialize()和serialize两者的用法
    如何解决复杂的问题?如何在未知的领域里,解决需求?
  • 原文地址:https://www.cnblogs.com/lcchy/p/10139517.html
Copyright © 2011-2022 走看看