JAVA语法练习

SDUT - 2543 整除

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner cin = new Scanner( System.in );
		int n, i;
		int a[] = new int [10000005];
		a[1] = 0;
		for(i = 2; i <= 10000000; i++)
		{
			if((i % 5)==0 || (i % 6)==0 || (i % 8)==0)a[i] = a[i - 1] + 1;
			else a[i] = a[i - 1];
		}
		while(cin.hasNext())
		{
			n = cin.nextInt();
			System.out.println(a[n]);
		}
		cin.close();
	}

}

SDUT - 2562 相似三角形

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner cin = new Scanner( System.in );
		double a, b, c, d, e, f, t;
		while(cin.hasNext())
		{
			a = cin.nextDouble();
			b = cin.nextDouble();
			c = cin.nextDouble();
			d = cin.nextDouble();
			e = cin.nextDouble();
			f = cin.nextDouble();
			if(a > b){t = a; a = b; b = t;}
			if(b > c){t = b; b = c; c = t;}
			if(a > b){t = a; a = b; b = t;}
			if(d > e){t = d; d = e; e = t;}
			if(e > f){t = e; e = f; f = t;}
			if(d > e){t = d; d = e; e = t;}
			if(a / d == b / e && a / d == c / f && a + b > c)System.out.println("YES");
			else System.out.println("NO");
		}
		cin.close();
	}

}

SDUT - 2747 洗衣服

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner cin = new Scanner (System.in);
		int n, m;
		while(cin.hasNext())
		{
			n = cin.nextInt();
			m = cin.nextInt();
			System.out.println(n / m);
		}
		cin.close();
	}

}

SDUT - 2252 分段函数求值

import java.text.DecimalFormat;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner cin = new Scanner (System.in);
		double x, ans = 0;
		while(cin.hasNext())
		{
			x = cin.nextDouble();
			if(x > 0)ans = x * x + 1;
			else if(x < 0)ans = -x;
			else ans = 100;
			DecimalFormat df = new DecimalFormat(".0");
			System.out.println(df.format(ans));
		}
		cin.close();
	}

}

 

已标记关键词 清除标记
相关推荐
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页