比较名字异同

题目要求

使用键盘输入两个名字。如果这两个名字相同,则显示“名字相同”。
如果这两个名字不同,但它们的长度相同,则显示“名字长度相同”。
如果这两个名字和名字长度都不相同,则不显示任何内容。

要求:
• 程序应从键盘读取两行内容。
• 程序应包含 System.out.println() 或 System.out.print()。
• 如果这两个名字相同,则显示“名字相同”
• 如果这两个名字不同,但它们的长度相同,则显示“名字长度相同”
• 如果这两个名字和名字长度都不相同,则不显示任何内容。

我的代码

package zh.codegym.task.task04.task0421;
/* 
珍或珍?
*/

import java.io.*;
import java.util.Scanner;

public class Solution {
    public static void main(String[] args) throws Exception {
        //在此编写你的代码
        Scanner na = new Scanner(System.in);
        String name1 = na.nextLine();
        String name2 = na.nextLine();
        if (name1.equals(name2)){
            System.out.println("名字相同");
        }else if (name1.length() == name2.length()){
            System.out.println("名字长度相同");
        }else{

        }
    }
}

参考代码

package zh.codegym.task.task04.task0421;

import java.io.BufferedReader;
import java.io.InputStreamReader;

/* 
珍或珍?
*/

public class Solution {

    public static void main(String[] args) throws Exception {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        String name1 = reader.readLine();
        String name2 = reader.readLine();

        if (name1.equals(name2)) {
            System.out.println("名字相同");
        } else if (name1.length() == name2.length()) {
            System.out.println("名字长度相同");
        }
    }
}

比较年龄

题目要求

使用键盘输入名字和年龄。如果年龄小于 18,则显示“再长大一点”。

要求:
• 程序应从键盘读取两次数据。
• 程序应使用 System.out.println() 或 System.out.print()。
• 如果年龄小于 18,则显示“再长大一点”,此外不显示其他任何内容。
• 如果年龄大于或等于 18,则不显示任何内容。

我的代码

package zh.codegym.task.task04.task0422;

/* 
18 岁以上
*/

import java.io.*;

public class Solution {
    public static void main(String[] args) throws Exception {
        //在此编写你的代码
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        String name = reader.readLine();
        int age = Integer.parseInt(reader.readLine());
        if (age < 18){
            System.out.println("再长大一点");
        }else{
		
        }
    }
}

参考代码

package zh.codegym.task.task04.task0422;

import java.io.BufferedReader;
import java.io.InputStreamReader;

/* 
18 岁以上
*/

public class Solution {

    public static void main(String[] args) throws Exception {
        BufferedReader bis = new BufferedReader(new InputStreamReader(System.in));
        String name = bis.readLine();
        int age = Integer.parseInt(bis.readLine());

        if (age < 18) {
            System.out.println("再长大一点");
        }
    }
}


比较两个相同的数

题目要求

三个数字
使用键盘输入三个整数。其中一个数字是唯一的。另外两个数字相同。显示不同于其他两个的数字的序号。
例如,对于 4 6 6:
1

例如,对于 6 6 3:
3

Requirements:

  1. 程序应从键盘读取这些数字。
  2. 程序应使用 System.out.println() 或 System.out.print()。
  3. 程序应显示不同于其他两个的数字的序号。
  4. 如果所有这些数字都不相同,则不显示任何内容。

我的代码

package zh.codegym.task.task04.task0424;

/* 
三个数字
*/

import java.io.*;

public class Solution {
    public static void main(String[] args) throws Exception {
        //在此编写你的代码
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        int  a = Integer.parseInt(reader.readLine());
        int  b = Integer.parseInt(reader.readLine());
        int  c = Integer.parseInt(reader.readLine());
        if (a == b && b != c && a != c){
            System.out.println(3);
        }else if (a == c && a != b && b != c){
            System.out.println(2);
        }else if(b == c && b != a && c != a){
            System.out.println(1);
        }else{

        }
    }
}

参考代码

package zh.codegym.task.task04.task0424;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/* 
三个数字
*/

public class Solution {
    public static void main(String[] args) throws IOException {
        BufferedReader bis = new BufferedReader(new InputStreamReader(System.in));
        int a = Integer.parseInt(bis.readLine());
        int b = Integer.parseInt(bis.readLine());
        int c = Integer.parseInt(bis.readLine());
        if (a == b && a == c && b == c) {
        } else {
            if (a == b) {
                System.out.println(3);
            } else {
                if (b == c) {
                    System.out.println(1);
                } else if (a == c) {
                    System.out.println(2);
                }
            }
        }
    }
}

输入坐标,寻找象限

题目要求

目标已锁定!
使用键盘输入两个整数,以表示不在坐标轴上的点的坐标。
显示包含给定点的象限的编号。

提示:
如果满足以下条件,则点 (a,b) 属于某个象限:
对于第一象限:a>0 且 b>0;
对于第二象限:a<0 且 b>0;
对于第三象限:a<0 且 b<0;
对于第四象限:a>0 且 b<0。

例如,对于 4 6:
1

例如,对于 -6 -6:
3

Requirements:

  1. 程序应从键盘读取这些数字。
  2. 程序应使用 System.out.println() 或 System.out.print()。
  3. 如果该点在第一象限内,则显示“1”。
  4. 如果该点在第二象限内,则显示“2”。
  5. 如果该点在第三象限内,则显示“3”。
  6. 如果该点在第四象限内,则显示“4”。

我的代码

package zh.codegym.task.task04.task0425;

/* 
目标已锁定!
*/

import java.io.*;

public class Solution {
    public static void main(String[] args) throws Exception {
        //在此编写你的代码
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        int a = Integer.parseInt(reader.readLine());
        int b = Integer.parseInt(reader.readLine());
        if (a > 0){
            if (b > 0){
                System.out.println(1);
            }else{
                System.out.println(4);
            }
        }else{
            if(b > 0){
                System.out.println(2);
            }else{
                System.out.println(3);
            }
        }
    }
}

参考代码

package zh.codegym.task.task04.task0425;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/* 
目标已锁定!
*/

public class Solution {
    public static void main(String[] args) throws IOException {
        BufferedReader bis = new BufferedReader(new InputStreamReader(System.in));
        int a = Integer.parseInt(bis.readLine());
        int b = Integer.parseInt(bis.readLine());
        if (a > 0 && b > 0) {
            System.out.println(1);
        } else if (a < 0 && b > 0) {
            System.out.println(2);
        } else if (a < 0 && b < 0) {
            System.out.println(3);
        } else if (a > 0 && b < 0) {
            System.out.println(4);
        }
    }
}

心有多大,梦就有多大。

@侧耳听智慧,专心求聪明 Turnging your ear to wisdom and applying your heart to understanding!