2021级-JAVA01 Java入门编程题


7-1 模仿练习

public class Main {
    public static void main(String[] args) throws Exception {
        System.out.println("Programming is fun!");
        System.out.println("Fundamentals First");
        System.out.println("Problem Driven");
    }
}

7-2 Hello World!

public class Main {
    public static void main(String[] args) throws Exception {
        System.out.println("Hello World!");
    }
}

7-3 sdut-入门-交换两个整数的值

import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner reader = new Scanner(System.in);
        int a, b, temp;
        a = reader.nextInt();
        b = reader.nextInt();
        temp = a;
        a = b;
        b = temp;
        System.out.print(a + " " + b);
        reader.close();
    }
}

7-4 sdut-入门-转换字母

import java.util.*;

public class Main {
    public static void main(String[] args){
        String a;
        Scanner input = new Scanner(System.in);
        a = input.nextLine();
        System.out.println(a.toUpperCase());
        input.close();
    }
}

7-5 球的表面积和体积

import java.util.Scanner;
import java.text.DecimalFormat;
public class Main
{
    public static void main(String[] args)
    {
        Scanner reader = new Scanner(System.in);
        double d1 = reader.nextDouble();
        double s, v, p;
        p = 3.1415926535;
        s = 4 * d1 * d1 * p;
        v = (4 * p * d1 * d1 * d1) / 3;
        DecimalFormat df = new DecimalFormat("0.00");
        System.out.print(df.format(s) + " " + df.format(v));
    }
}

7-6 华氏温度转化为摄氏温度

import java.text.DecimalFormat;
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        double c;
        double f = in.nextDouble();
        c = (f - 32) * 5 / 9;
        DecimalFormat df = new DecimalFormat("0.00");
        System.out.println("c="+df.format(c));
        in.close();
    }
}

7-7 sdut-入门-1 A+B for Input-Output Practice(I)

import java.util.Scanner;

public class Main
{
    public static void main(String[] args)
    {
        Scanner reader = new Scanner(System.in);
        int a, b, c;
        while(reader.hasNext())
        {
            a = reader.nextInt();
            b = reader.nextInt();
            c = a + b;
            System.out.println(c);
        }
        reader.close();
    }
}


7-8 sdut-入门-2 A+B for Input-Output Practice (II)

import java.util.Scanner;
public class Main
{
    public static void main(String[] args)
    {
        Scanner reader = new Scanner(System.in);
        int a, b, m, c;
        m = reader.nextInt();
        while(m-- >0)
        {
            a = reader.nextInt();
            b = reader.nextInt();
            c = a + b;
            System.out.println(c);
        }
        reader.close();
    }
}

7-9 sdut0-入门-3 A+B for Input-Output Practice (III)

import java.util.Scanner;
public class Main
{
    public static void main(String[] args)
    {
        Scanner in = new Scanner(System.in);
        while(in.hasNext())
        {
            int a, b;
            a = in.nextInt();
            b = in.nextInt();
            if(a == 0 && b == 0) break;
            System.out.println(a + b);
        }
    }
}


7-10 sdut-入门-4 A+B for Input-Output Practice (IV)

import java.util.Scanner;

public class Main
{
    public static void main(String[] args)
    {
        Scanner in = new Scanner(System.in);
        while(in.hasNext())
        {
            int n = in.nextInt();
            if(n == 0) break;
            int sum = 0;
            for(int i = 0; i < n; i ++)
            {
                int x = in.nextInt();
                sum += x;
            }
            System.out.println(sum);
        }
    }
}


7-11 sdut-入门-5 A+B for Input-Output Practice (V)

import java.util.Scanner;
public class Main
{
    public static void main(String[] args)
    {
        Scanner reader = new Scanner(System.in);
        int x, n, m;
        m = reader.nextInt();
        while(m-- >0)
        {
            x = 0;
            n = reader.nextInt();
            while(n-- > 0)
            {
                x += reader.nextInt();
            }
            System.out.println(x);
        }
        reader.close();
    }
}

7-12 sdut-入门-6 A+B for Input-Output Practice (VI)

import java.util.Scanner;

public class Main
{
    public static void main(String[] args)
    {
        Scanner in = new Scanner(System.in);
        while(in.hasNext())
        {
            int n = in.nextInt();
            int sum = 0;
            for(int i = 0; i < n; i ++)
            {
                int x = in.nextInt();
                sum += x;
            }
            System.out.println(sum);
        }
    }
}


7-13 sdut-入门-7 A+B for Input-Output Practice (VII)

import java.util.Scanner;

public class Main
{
    public static void main(String[] args)
    {
        Scanner in = new Scanner(System.in);
        while(in.hasNext())
        {
            int a = in.nextInt();
            int b = in.nextInt();
            System.out.println(a + b);
            System.out.println();
        }
    }
}

7-14 sdut-入门-8 A+B for Input-Output Practice(VIII)

import java.util.Scanner;
public class Main
{
    public static void main(String[] args)
    {
        Scanner reader = new Scanner(System.in);
        int x, n, m;
        m = reader.nextInt();
        while(m-- >0)
        {
            x = 0;
            n = reader.nextInt();
            while(n-- > 0)
            {
                x += reader.nextInt();
            }
            System.out.println(x);
            System.out.println();
        }
        reader.close();
    }
}

7-15 打印字母B。

import java.util.Scanner;

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

  • 5
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值