java用方法重载就圆的面积_Java面向对象1(A~F)

QWQ请假一节课,错过一章内容,只能求助qsh了。

import java.util.*;

class Number {

int a, b;

Number(int n, int m) {

a = n;

b = m;

}

int getGcd() {

int n = a, m = b;

while (m > 0) {

int x = n;

n = m;

m = x % m;

}

return n;

}

int getLcm() {

int x = getGcd();

return a * b / x;

}

void Print() {

System.out.println(getGcd() + "\n" + getLcm());

}

}

public class Main {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

Number num = new Number(sc.nextInt(), sc.nextInt());

num.Print();

sc.close();

}

}

C/C++经典程序训练3---模拟计算器

import java.util.Scanner;

class Number

{

int a, b;

String c;

Number(int n, int m, String k)

{

a = n;

b = m;

c = k;

}

int getAns()

{

int ans = 0;

if(c.equals("+"))ans = a + b;

else if(c.equals("-"))ans = a - b;

else if(c.equals("*"))ans = a * b;

else ans = a / b;

return ans;

}

void Print()

{

System.out.println(getAns());

}

}

public class Main {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

int a, b;

String c;

a = sc.nextInt();

b = sc.nextInt();

sc.nextLine();

c = sc.nextLine();

Number p = new Number(a, b, c);

p.Print();

sc.close();

}

}

面向对象程序设计上机练习一(函数重载)(SDUT 1140)

import java.util.Scanner;

class Max

{

static int getMax(int a[])

{

int ans = -1;

for(int i = 0; i < 5; i ++) if(a[i] > ans) ans = a[i];

return ans;

}

static float getMax(float b[])

{

float ans = -1;

for(int i = 0; i < 5; i ++) if(b[i] > ans) ans = b[i];

return ans;

}

static long getMax(long c[])

{

long ans = -1;

for(int i = 0; i < 5; i ++) if(c[i] > ans) ans = c[i];

return ans;

}

}

public class Main {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

int a[] = new int[10];

float b[] = new float[10];

long c[] = new long[10];

for(int i = 0; i < 5; i ++) a[i] = sc.nextInt();

for(int i = 0; i < 5; i ++) b[i] = sc.nextFloat();

for(int i = 0; i < 5; i ++) c[i] = sc.nextLong();

Max max = new Max();

System.out.print(max.getMax(a)+"\n"+max.getMax(b)+"\n"+max.getMax(c)+"\n");

}

}

D    圆的面积 (SDUT 1588)

import java.util.Scanner;

import java.text.DecimalFormat;

class Sum {

double x;

Sum(double n) {

x = n;

}

double getAns() {

return (x * x * 3.141592653);

}

}

public class Main {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

DecimalFormat df = new DecimalFormat(".00");

int t;

t = sc.nextInt();

for (int i = 1; i <= t; i++) {

Sum n = new Sum(sc.nextDouble());

System.out.println("Case" + " " + i + ":" + " " + df.format(n.getAns()));

}

}

}

E    正方形面积(SDUT 2101)

import java.util.Scanner;

import java.text.DecimalFormat;

class Sum {

long x;

Sum(long n) {

x = n;

}

long getAns() {

return (x * x);

}

}

public class Main {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

// df = new DecimalFormat(".00");

while (sc.hasNext()) {

Sum n = new Sum(sc.nextLong());

System.out.println(n.getAns());

}

}

}

F    回文时间 (SDUT 2174)

import java.util.*;

class Time{

String s;

int a,b,c,d;

Time(String s){

this.s = s;

a = s.charAt(0) - '0';

b = s.charAt(1) - '0';

c = s.charAt(3) - '0';

d = s.charAt(4) - '0';

}

void getAns() {

if(a == d && b == c)d ++;

while(a != d || b != c) {

d ++;

if(d == 10) {

d = 0;

c ++;

}

if(c == 6) {

c = 0;

b ++;

}

if(b == 10) {

b = 0;

a ++;

}

if(b + a * 10 >= 24) {

a = 0;

b = 0;

}

}

System.out.println(a +""+ b + ":" + c +""+ d);

}

}

public class Main{

public static void main(String args[]) {

Scanner sc = new Scanner(System.in);

String s;

while(sc.hasNext()) {

s = sc.nextLine();

Time p = new Time(s);

p.getAns();

}

}

}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值