BK 分段函数(SDUT 2257)
import java.util.*;
public class Main{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
double n;
int t;
while(sc.hasNext()) {
t=sc.nextInt();
for(int i=0;i<t;i++) {
n=sc.nextDouble();
System.out.printf("%.2f\n",f(n));}
}
}
public static double f(double n){
if(n==0) return 0;
else if(n>=10)return n*n;
else if(n<0) return -1*n+Math.sin(n);
else return Math.log(n)/Math.log((double)2);
}
}
BL C/C++程序训练6---歌德巴赫猜想的证明(SDUT 1136)
import java.util.*;
public class Main{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n;
n = sc.nextInt();
for(int i = 2; i <= n; i ++)
{
if(prime(i)==1 && prime(n-i)==1) {
System.out.printf("%d=%d+%d\n",n,i,n-i);
break;
}
}
}
public static int prime(int n)
{
if(n == 0 || n == 1) return 0;
for(int i = 2; i <= (int)Math.sqrt((double)n); i ++)
{
if(n % i == 0) return 0;
}
return 1;
}
}
BM C语言实验——计算1到n的和(循环结构)(SDUT 1120)
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n;
n = sc.nextInt();
int ans = 0;
for (int i = 0; i <= n; i++)
ans += i;
System.out.println(ans);
}
}
BN 数列求和(SDUT1134)
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a, n;
a = sc.nextInt();
n = sc.nextInt();
int ans = 0, sum = 0;
sum = a;
for (int i = 0; i < n; i++) {
ans += sum;
sum *= 10;
sum += a;
}
System.out.println(ans);
}
}
BO C语言实验——大小写转换(SDUT 1168)
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String str;
str = sc.nextLine();
int len = str.length(); // 字符串长度
for(int i = 0; i < len; i ++) // 字符串单个字符引用
{
char op = str.charAt(i);
if(op>='a'&&op<='z')System.out.print((char)(op-32));
else if(op>='A'&&op<='Z')System.out.print((char)(op+32));
else System.out.print(op);
}
}
}
BP C语言实验——最小公倍数和最大公约数(SDUT 1181)
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n, m;
n = sc.nextInt();
m = sc.nextInt();
int ans1, ans2;
ans2 = gcd(n, m);
ans1 = n * m / ans2;
System.out.println(ans1 + " " + ans2);
}
public static int gcd(int x, int y) {
return (y == 0) ? x : gcd(y, x % y);
}
}
BQ 成绩评估(SDUT 1222)
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n, f = 0;
while(sc.hasNext())
{
f = 0;
n = sc.nextInt();
if(n>=90&&n<=100)f=1;
else if(n>=80&&n<=89)f=2;
else if(n>=70&&n<=79)f=3;
else if(n>=60&&n<=69)f=4;
else if(n>=0&&n<=59)f=5;
else f = 0;
if(f==0)System.out.println("Score is error!");
else System.out.println((char)('A' + f - 1));
}
}
}
字符的变化(SDUT 3272)
package kk;
import java.util.Scanner;
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
String str = sc.nextLine();
int n;
n = sc.nextInt();
n %= 26;
int len = str.length();
for(int i = 0; i < len; i ++)
{
char op = str.charAt(i);
if((char)(op+n) > 'z'){
System.out.print((char)(op+n-26));
}
else System.out.print((char)(op+n));
}
System.out.println("");
}
}
LCM的个数(SDUT 3275)
标签:Java,Scanner,int,基础,System,else,语法,sc,public From: https://blog.51cto.com/u_15965659/6056615