国家给出了 8 岁男宝宝的标准身高为 130 厘米、标准体重为 27 公斤;8 岁女宝宝的标准身高为 129 厘米、标准体重为 25 公斤。

现在你要根据小宝宝的身高体重,给出补充营养的建议。

输入格式:
输入在第一行给出一个不超过 10 的正整数 N,随后 N 行,每行给出一位宝宝的身体数据:

性别 身高 体重
其中性别是 1 表示男生,0 表示女生。身高和体重都是不超过 200 的正整数。

输出格式:
对于每一位宝宝,在一行中给出你的建议:

如果太矮了,输出:duo chi yu!(多吃鱼);
如果太瘦了,输出:duo chi rou!(多吃肉);
如果正标准,输出:wan mei!(完美);
如果太高了,输出:ni li hai!(你厉害);
如果太胖了,输出:shao chi rou!(少吃肉)。
先评价身高,再评价体重。两句话之间要有 1 个空格。

输入样例:

4
0 130 23
1 129 27
1 130 30
0 128 27

输出样例:

ni li hai! duo chi rou!
duo chi yu! wan mei!
wan mei! shao chi rou!
duo chi yu! shao chi rou!
//cpp
#include<iostream>
using namespace std;class Baby{public:int sex ;int height;int weight;
};int main(){Baby B[10];int N = 0;cin>>N;void heightpanduan (int flag, int height);void weightpanduan (int flag, int weight);for (int i = 0; i < N; i++){cin>>B[i].sex;cin>>B[i].height;cin>>B[i].weight;}for (int i = 0; i < N; i++){if (B[i].sex == 1){heightpanduan (130, B[i].height);weightpanduan (27, B[i].weight);} else {heightpanduan (129, B[i].height);weightpanduan (25, B[i].weight);}}return 0;
}void heightpanduan (int flag, int height) {if (height > flag) {cout<<"ni li hai! ";} else if (height == flag) {cout<<"wan mei! ";} else {cout<<"duo chi yu! ";}
}
void weightpanduan (int flag, int weight) {if (weight > flag) {cout<<"shao chi rou!"<<endl;} else if (weight == flag) {cout<<"wan mei!"<<endl;} else {cout<<"duo chi rou!"<<endl;}
}

照例按着Cpp写Java

import java.util.Scanner;class Baby{int sex ;int height;int weight;
}public class Main{public static void main(String[] args){Scanner sc = new Scanner(System.in);int N = sc.nextInt();void heightpanduan (int flag, int height);void weightpanduan (int flag, int weight);Baby[] B = new Baby[10];for (int i = 0; i < N; i++){B[i].sex = sc.nextInt();B[i].height = sc.nextInt();B[i].weight = sc.nextInt();}for (int i = 0; i < N; i++){if (B[i].sex == 1){heightpanduan (130, B[i].height);weightpanduan (27, B[i].weight);} else {heightpanduan (129, B[i].height);weightpanduan (25, B[i].weight);}}}void heightpanduan (int flag, int height) {if (height > flag) {System.out.print("ni li hai! ");} else if (height == flag) {System.out.print("wan mei! ");} else {System.out.print("duo chi yu! ");}}void weightpanduan (int flag, int weight) {if (weight > flag) {System.out.println("shao chi rou!");} else if (weight == flag) {System.out.println("wan mei!");} else {System.out.println("duo chi rou!");}}
}

报错

Main.java:14: error: illegal start of expression
void heightpanduan (int flag, int height);
^
Main.java:14: error: ‘;’ expected
void heightpanduan (int flag, int height);
^
Main.java:14: error: expected
void heightpanduan (int flag, int height);
^
Main.java:14: error: not a statement
void heightpanduan (int flag, int height);
^
Main.java:14: error: ‘;’ expected
void heightpanduan (int flag, int height);
^
Main.java:15: error: illegal start of expression
void weightpanduan (int flag, int weight);
^
Main.java:15: error: ‘;’ expected
void weightpanduan (int flag, int weight);
^
Main.java:15: error: expected
void weightpanduan (int flag, int weight);
^
Main.java:15: error: not a statement
void weightpanduan (int flag, int weight);
^
Main.java:15: error: ‘;’ expected
void weightpanduan (int flag, int weight);
^
10 errors

先去查了Java中方法(函数)的定义和使用
https://blog.csdn.net/hohiuching/article/details/77480471

weightpanduanheightpanduan两个函数前面加了public
又报错

Main.java:25: error: non-static method heightpanduan(int,int) cannot be referenced from a static context
heightpanduan (130, B[i].height);
^ Main.java:26: error: non-static method weightpanduan(int,int) cannot be referenced from a static context
weightpanduan (27, B[i].weight);
^ Main.java:28: error: non-static method heightpanduan(int,int) cannot be referenced from a static context
heightpanduan (129, B[i].height);
^ Main.java:29: error: non-static method weightpanduan(int,int) cannot be referenced from a static context
weightpanduan (25, B[i].weight);
^ 4 errors

于是在public void 函数名,public和void中间加了个static
提交,跑通了但是啥也没输出
小伙伴: Baby[] B = new Baby[10];,这个之后还要在for循环里来一下。于是加了个B[i] = new Baby();
成功输出

注意啊:

Baby[] B = new Baby[10];**//这个在外面        for (int i = 0; i < N; i++){B[i] = new Baby();//这个在里面
//java
import java.util.Scanner;class Baby{int sex ;int height;int weight;
}public class Main{public static void main(String[] args){Scanner sc = new Scanner(System.in);int N = sc.nextInt();//void heightpanduan (int flag, int height);//void weightpanduan (int flag, int weight);Baby[] B = new Baby[10];for (int i = 0; i < N; i++){B[i] = new Baby();B[i].sex = sc.nextInt();B[i].height = sc.nextInt();B[i].weight = sc.nextInt();}for (int i = 0; i < N; i++){if (B[i].sex == 1){heightpanduan (130, B[i].height);weightpanduan (27, B[i].weight);} else {heightpanduan (129, B[i].height);weightpanduan (25, B[i].weight);}}}public static void heightpanduan (int flag, int height) {if (height > flag) {System.out.print("ni li hai! ");} else if (height == flag) {System.out.print("wan mei! ");} else {System.out.print("duo chi yu! ");}}public static void weightpanduan (int flag, int weight) {if (weight > flag) {System.out.println("shao chi rou!");} else if (weight == flag) {System.out.println("wan mei!");} else {System.out.println("duo chi rou!");}}
}

以及还参考了这个博文
https://blog.csdn.net/wen_binobject/article/details/84957301

团体程序设计天梯赛-练习集——L1-063 吃鱼还是吃肉(类数组、方法定义和使用)相关推荐

  1. 【CCCC】PAT : 团体程序设计天梯赛-练习集 L1 答案

    [CCCC]PAT : 团体程序设计天梯赛-练习集 L1 答案 鉴定完毕,全部水题 ヾ(•ω•`)o 标号 标题 分数 通过数 提交数 通过率 L1-001 Hello World 5 46779 1 ...

  2. 团体程序设计天梯赛 -- 练习集 (L1合集)

    文章目录 L1-001 Hello World (5 分) L1-002 打印沙漏 (20 分) L1-003 个位数统计 (15 分) L1-004 计算摄氏温度 (5 分) L1-005 考试座位 ...

  3. PAT : 团体程序设计天梯赛-练习集L1 个人题解

    另把天梯赛所有题解内容全部打包成了一个文档,可以自行下载:https://download.csdn.net/download/daixinliangwyx/11170075 L1-001 Hello ...

  4. 团体程序设计天梯赛-练习集 L1

    目录 L1-001 Hello World L1-002 打印沙漏 L1-003 个位数统计 L1-004 计算摄氏温度 L1-005 考试座位号 L1-006 连续因子[枚举] L1-007 念数字 ...

  5. 团体程序设计天梯赛-练习集 L1合集

    来自<https://www.patest.cn/contests/gplt> L1-001. Hello World 这道超级简单的题目没有任何输入. 你只需要在一行中输出著名短句&qu ...

  6. 团体程序设计天梯赛-练习集 L1阶段 全部题解

    L1-001. Hello World 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 这道超级简单的题目没有任何输入. 你只需要在一行中输 ...

  7. 团体程序设计天梯赛-练习集-L1区001——048C语言全解

    题目链接:https://www.patest.cn/contests/gplt 所有一区的题都是用c语言编写的,都通过了,有的可能设计的比较复杂.仅供参考,同时也感谢网上的一些大佬们提供的思路.如果 ...

  8. 【CCCC】PAT : 团体程序设计天梯赛-练习集 L2 答案,题解,附代码

    [CCCC]PAT : 团体程序设计天梯赛-练习集 L2 答案 鉴定完毕,全部水题 ヾ(•ω•`)o 知识点分类(32): 1.树锯结构(9):二叉树的存储,编号,遍历顺序转换,求深度,底层节点,从底 ...

  9. 团体程序设计天梯赛练习集题解整合

    网上介绍 团体程序设计天梯赛练习集 的文章已经很多了, 我的这篇文章是对练习集题解的整合,方便每一位备战 团体程序设计天梯赛 的同学使用. 一年一度的 团体程序设计天梯赛 即将开始,PTA的练习集是必 ...

  10. 团体程序设计天梯赛-练习集 L1-033——L1-048

    团体程序设计天梯赛-练习集 /** @Description: 出生年* @version: * @Author: * @Date: 2021-03-25 08:13:57* @LastEditors ...

最新文章

  1. Maya摄像机动画技能学习教程
  2. javascript 判断浏览器
  3. PHP 通过随机数获得ASCII 值返回字符。
  4. Opencv 实现图像的离散傅里叶变换(DFT)、卷积运算(相关滤波)
  5. python 单线程_python的单线程多任务的实现
  6. C#+Sql数据库备份
  7. 探讨TensorRT加速AI模型的简易方案 — 以图像超分为例
  8. 诗与远方:无题(三十七)- 凿壁偷光
  9. ERP产品销售发货判断库存功能(四十二)
  10. 第十二章课下测试补交博客
  11. 渗透测试学习 十六、 常见编辑器漏洞解析
  12. 从零基础入门Tensorflow2.0 ----三、9.tf.function
  13. BOOST 升压电路调试笔记
  14. java页面数值转文本_Java读取Excel表格以及读取数字列转为文本的解决办法
  15. 大数据毕设 - 大数据二手房数据分析与可视化(python 爬虫)
  16. 微型计算机联想c325,寓教于乐一体机 联想IdeaCentre B325评测
  17. 记录一次关于百度网盘打开提示页面不存在的问题(吃相不要太难看)
  18. 华为digix算法大赛2020机器学习赛道-ctr预估初赛/决赛rank1
  19. 用Cool Edit Pro 2.1做铃声渐入的效果
  20. 域管理:windows server分发与分配软件

热门文章

  1. 根据出生日期计算宝宝的年龄,几岁几个月几天!
  2. 半导体中杂质和缺陷能级和半导体中载流子的统计分布​​​​​
  3. Windows 10的便签在哪里
  4. 腾讯云yum安装mysql_腾讯云CentOS7.0使用yum安装mysql_MySQL
  5. 数组对象,JSON.parse()解析
  6. 基于Hadoop的豆瓣电影的数据抓取、数据清洗、大数据分析(hdfs、flume、hive、mysql等)、大屏可视化
  7. 两万字总结python之pandas库
  8. (八)用Matplotlib画曲线图
  9. 你自学3dmax一直没进步?只因没找到这几个突破口,萌新须知
  10. 使用CMake编译Libigl错误问题解决方法