首页 > 编程语言 >Java基础语法2

Java基础语法2

时间:2023-02-14 13:04:51浏览次数:41  
标签:Java Scanner int 基础 System 语法 ++ print out

 作者: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 + "\n" + 'B' + " " + b + "\n" + 'C' + " " + c + "\n" + 'D' + " " + d + "\n" + 'E'
+ " " + e + "\n");
}
}

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);
}
}

 

标签:Java,Scanner,int,基础,System,语法,++,print,out
From: https://blog.51cto.com/u_15965659/6056614

相关文章

  • Java基础语法n
    BK     分段函数(SDUT2257)importjava.util.*;publicclassMain{publicstaticvoidmain(String[]args){Scannersc=newScanner(System.in);......
  • Java基础语法3
    排序(SDUT1582)importjava.util.*;publicclassMain{publicstaticvoidmain(String[]args){Scannersc=newScanner(System.in);intn;inta[]=new......
  • Java面向对象2(G~J)
    G   织女的红线(SDUT2240)importjava.util.Scanner;importjava.text.DecimalFormat;classSum{doublex1,y1,x2,y2;Sum(doublen1,doublem1,doublen2,dou......
  • Java面向对象6(AA ~ AE)
    AE 简单的复数运算(类和对象)(SDUT4303)importjava.util.*;classComplex{ inta,b; Complex(){ } Complex(intn,intm){ a=n; b=m; } voi......
  • Java面向对象3(K~O)
     K    正方形(SDUT2444)importjava.lang.reflect.Array;importjava.util.*;publicclassMain{ publicstaticvoidmain(String[]args){ Scanners......
  • JAVA-studyDay02
    java-day02一.注释//书写注释是非常好的习惯//单行注释////多行注释/**///JavaDoc:文档注释/***///平时写代码一定要注意规范注意:注释不会影响代码二.运算符1.......
  • rxjava之复习
    1.rxjava之操作符1).转换类操作符(mapflatMapconcatMapflatMapIterableswitchMapscangroupBy...);map及flatMap以及concatMap区别?map和flatMap都可以对RxJava传入......
  • java根据地址获取百度API经纬度
    java根据地址获取百度API经纬度(详细文档)1publicvoidgetLarLng(Stringaddress)throwsException{23Stringak="vZ5wAkH9uc6mCnrhtYWey2fBHBmU9Rh......
  • Java 通过get post 请求url
    .已获取小程序的access_token为例,通过Get请求url1importcom.alibaba.fastjson.JSONObject;23StringwechatUrl="https://api.weixin.qq.com/cgi-bin/tok......
  • java删除字符串最后一位
    Strings="1,2,3,4,5,6,7,8,";//目标:删除最后一个","s=s.substring(0,s.length()-1);System.out.println(s); ......