JAVA入門(SDUT專題練習)
阿新 • • 發佈:2018-12-10
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)