Java入门 - 详细的 Java 语法编程练习

转载请注明出处:JAVA入门_Mercury_Lc的博客-CSDN博客

(SDUT专题练习)

详细的 Java 语法编程练习

A-  A+B Problem(SDUT 1000)

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
			Scanner sc = new Scanner(System.in);
			int a, b;
			a = sc.nextInt();
			b = sc.nextInt();
			System.out.println(a+b);
	} 
}

B-A+B for Input-Output Practice (I)(SDUT 1010)

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a, b;
		while (sc.hasNext()) {
			a = sc.nextInt();
			b = sc.nextInt();
			System.out.println(a + b);		
		}
	}
}

C-A+B for Input-Output Practice (II)(SDUT 1011)

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a, b, n;
		while (sc.hasNext()) {
			n = sc.nextInt();
			for (int i = 0; i < n; i++) {
				a = sc.nextInt();
				b = sc.nextInt();
				System.out.println(a + b);
			}
		}
	}
}

D-A+B for Input-Output Practice (III)(SDUT 1012)

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a, b;
		while (sc.hasNext()) {
			a = sc.nextInt();
			b = sc.nextInt();
			if (a == 0 && b == 0)
				break;
			System.out.println(a + b);
		}
	}
}

E-A+B for Input-Output Practice (IV)(SDUT 1013)

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
			Scanner reader = new Scanner(System.in);
			int n,x,sum;
			while(reader.hasNext()){
			n = reader.nextInt();
			if(n == 0)break;
			sum  = 0;
			for(int i = 0; i < n; i ++){
				x =reader.nextInt();
				sum  += x;
			}
			System.out.println(sum);
		}
	}
}

F-A+B for Input-Output Practice (V)(SDUT 1014)

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int m, sum, x, n;
		while (sc.hasNext()) {
			n = sc.nextInt();
			sum = 0;
			for (int k = 0; k < n; k++) {
				m = sc.nextInt();
				sum = 0;
				for (int i = 0; i < m; i++) {
					x = sc.nextInt();
					sum += x;
				}
				System.out.println(sum);
			}
		}
	}
}

G-A+B for Input-Output Practice (VI)(SDUT 1015)

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int sum, x, n;
		while (sc.hasNext()) {
			n = sc.nextInt();
			sum = 0;
			for (int i = 0; i < n; i++) {
				x = sc.nextInt();
				sum += x;
			}
			System.out.println(sum);
		}
	}
}

H-A+B for Input-Output Practice (VII)(SDUT  1016)

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a, b;
		while (sc.hasNext()) {
			a = sc.nextInt();
			b = sc.nextInt();
			System.out.println(a + b);
			System.out.println("");
		}
	}
}

I-A+B for Input-Output Practice(SDUT 1017)

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int m, sum, x, n;
		while (sc.hasNext()) {
			n = sc.nextInt();
			sum = 0;
			for (int k = 0; k < n; k++) {
				m = sc.nextInt();
				sum = 0;
				for (int i = 0; i < m; i++) {
					x = sc.nextInt();
					sum += x;
				}
				System.out.println(sum);
				System.out.println("");
			}
		}
	}
}

J-C语言实验——Hello World!(printf练习)(SDUT 1110)

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		System.out.println("Hello World!");
	}
}

K-C语言实验——格式化输出(常量练习)(SDUT 1111)

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		System.out.println("100\r\n" + 
				"A\r\n" + 
				"3.140000 ");
	}
}

L-C语言实验——图形输出(字符常量练习)(SDUT  1112)

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		System.out.println("#\r\n" + 
				"##\r\n" + 
				"###\r\n" + 
				"####\r\n" + 
				"#####\r\n" + 
				"######");
	}
}

M-C语言实验——单个字符输入和输出(顺序结构)(SDUT 1113)


import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		char c;
		String s;
		Scanner sc = new Scanner(System.in);
		s = sc.next();
		c = s.charAt(0);
		System.out.println(c);
	}
}

N-C语言实验——计算A+B(顺序结构)(SDUT 1114)

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
			Scanner sc = new Scanner(System.in);
			int a, b;
			a = sc.nextInt();
			b = sc.nextInt();
			System.out.println(a+b);
	} 
}

O-C语言实验——交换两个整数的值(顺序结构)(SDUT 1115)


import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a, b, c;
		a = sc.nextInt();
		b = sc.nextInt();
		c = a;
		a = b;
		b = c;
		System.out.println(a + " " + b);
	}
}

P-C语言实验——转换字母(顺序结构)(SDUT 1116)


import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s;
		s = sc.nextLine();
		System.out.println(s.toUpperCase());
	}
}

Q-C语言实验——输出字符串(SDUT 1151)


import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		System.out.println("This is a C program.");
	}
}

R-C语言实验——求两个整数之和(SDUT 1152)


import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		System.out.println("sum is 579");
	}
}

S-C语言实验——打印图形(SDUT 1155)


import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		System.out.println("******************************\r\n" + 
				"\r\n" + 
				"          Very good!\r\n" + 
				"\r\n" + 
				"******************************");
	}
}

T-C语言实验——用*号输出字母C的图案(SDUT 1156)


import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		System.out.println("*****\r\n" + 
				"*\r\n" + 
				"*\r\n" + 
				"*\r\n" + 
				"*****");
	}
}

U-C语言实验——三个整数和、积与平均值(SDUT 1167)


import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a,b,c;
		a = sc.nextInt(); b = sc.nextInt();c = sc.nextInt();
		double ave = (a + b + c) / 3.0;
		System.out.print(a+b+c+" "+ (a*b*c)+" ");
		System.out.printf("%.2f\n",ave);
	}
}

V-C语言实验——逆置正整数(SDUT 1189)


import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n, a, b, c, m;
		n = sc.nextInt();
		a = n / 100;
		b = n / 10 % 10;
		c = n % 100 % 10;
		m = a + b * 10 + c * 100;
		System.out.println(m);
	}
}

W-C语言实验——买糖果(SDUT 1203)


import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n, m, k;
		n = sc.nextInt();
		n = n * 10;
		m = n / 3;
		k = n % 3;
		System.out.println(m + " " + k);
	}
}

C语言实验——圆柱体计算(SDUT 1207)


import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		final double P = 3.1415926;
		double r, h;
		double ans1, ans2, ans3, ans4;
		r = sc.nextDouble();
		h = sc.nextDouble();
		ans1 = 2 * P * r;
		ans2 = P * r * r;
		ans3 = 2 * P * r * h;
		ans4 = ans2 * h;
		System.out.printf("%.2f %.2f %.2f %.2f\n", ans1, ans2, ans3, ans4);
	}
}

C语言实验——温度转换(SDUT 1208)


import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		double F, C;
		F = sc.nextDouble();
		C = 5 * (F - 32) / 9;
		System.out.printf("%.2f\n", C);
	}
}

火车(SDUT 2396)

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Mercury_Lc

愿闻天下事,愿读圣贤书。

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值