JAVA入门

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

(SDUT专题练习)

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
" + 
				"A
" + 
				"3.140000 ");
	}
}

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

import java.util.Scanner;

public class Main {

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

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("******************************
" + 
				"
" + 
				"          Very good!
" + 
				"
" + 
				"******************************");
	}
}

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


import java.util.Scanner;

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

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
",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
", 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
", C);
	}
}

火车(SDUT 2396)

原文地址:https://www.cnblogs.com/lcchy/p/10139519.html