- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试创建一个系统,其中有人输入 0-100 之间的数字,然后程序会将数字分配到设定的边界,基本上是一个成绩存储系统。我会向您展示我的代码,然后详细说明。
public static void main(String[] args) {
//Boundary0/30/40/70 indicates which band the counter is for. e.g. 0-29, 30-39 etc
int Boundary0 = 0;
int Boundary30 = 0;
int Boundary40 = 0;
int Boundary70 = 0;
int Grade;
int count;
count = 0;
Scanner in = new Scanner(System.in);
//Read in first number
System.out.print("Enter an Integer");
Grade = in.nextInt();
while (Grade < 100){
//To count number of students
count++;
//To allocate each grade to corresponding tier
if(Grade >= 0 && Grade <= 29){
Boundary0++;
}
if(Grade >= 30 && Grade <= 39){
Boundary30++;
}
if(Grade >= 40 && Grade <= 69){
Boundary40++;
}
if(Grade >= 70 && Grade <= 100){
Boundary70++;
}
Grade = in.nextInt();
}
//To print each boundary seperately with the number of marks in each tier and overall total
System.out.println("0-29:" + " " + Boundary0 );
System.out.println("30-39:" + " " + Boundary30);
System.out.println("40-69:" + " "+ Boundary40);
System.out.println("70-100:" + " " +Boundary70);
System.out.println("Amount of Students: " + count);
}
}
当用户输入一个数字时,程序会将相应的边界变量加1
然后当用户输入大于 100 的数字时,程序停止并打印
tiers 并在每一层旁边,告诉用户每一层中有多少个值。
那么我想做的是,在代码的末尾,sout 命令所在的地方,
与其从字面上说每个部分有多少数字,我想表示
例如带*s的值
0-29: *****
30-39: ****
40-69: ********
70-100: *****
抱歉,如果我不是很清楚,我认为这可能只是我自己缺乏理解......
谢谢
最佳答案
创建一个可重用的方法,为您打印 *
-
public static void printStars(int n){
for(int i = 0 ; i < n ; i++)
System.out.print("*");
}
然后这样调用它-
System.out.println("0-29:" + " " + printStars(Boundary0));
System.out.println("30-39:" + " " + printStars(Boundary30));
System.out.println("40-69:" + " "+ printStars(Boundary40));
System.out.println("70-100:" + " " +printStars(Boundary70));
关于java - 如何打印与变量值对应的一组字符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20314827/
我想检查我的应用程序或系统中是否存在库。在 Java 中,我通常执行 System.loadlibrary,但是有谁知道 C 中类似的相应调用吗? 最佳答案 是dlopen打开一个库,dlsym 从加
我在 typescript 中输入以下内容 export type Excludable = T & { isExcluded?: boolean } 其中过滤值: export type Filte
我最近在我的应用程序中添加了一种方法,可以自动格式化 TextView ,从“50000”到“50,000”,效果绝对完美。现在我遇到的问题是,在我的应用程序中,有多个按钮功能可以从该 TextVie
SELECT * FROM conversations WHERE chatMembers LIKE '%1%'AND chatMembers LIKE '%10%' 对话表 id | chatMem
我正在编写一个需要将 Java Date() 值保存到 MySQL 数据库的 RESTful Web 服务,但是,我不确定 MySQL 中可以保存 Java Date() 的数据类型是什么,或者我是否
同样,在任何 Red Hat 或 JBoss 站点上都没有关于此的信息,所以我在这里问... 我不确定是 13 还是 14。 最佳答案 Mapping the Community versions w
同样,在任何 Red Hat 或 JBoss 站点上都没有关于此的信息,所以我在这里问... 我不确定是 13 还是 14。 最佳答案 Mapping the Community versions w
我曾尝试使用 swift 开发一款利用 iPhone 的 3D 触摸硬件的游戏。然而,当我将我的应用程序提交到 App Store 时,它被拒绝了,因为该游戏无法在 iPad 上玩。 我的问题是,
Qt 的有序关联容器对应项 std::map是QMap , std::set是QSet , 对于无序关联容器 std::unordered_map是QHash . 我应该用什么来代替std::unor
JavaScript 方法 String.fromCharCode() 在以下意义上与 Python 的 unichar() 等效: print unichr(213) # prints Õ on t
正如谷歌在 "Discontinuing support for JSON-RPC and Global HTTP Batch Endpoints" 中提到的那样,Google API 客户端库已重新
我正在使用 MapLayer 和 MapOverlay 在 map 中创建自己的路径/折线,GPS 捕获的所有点都存储在一个结构中,以便我可以访问它们。随时。 现在,我希望路径在用户操作 map (缩
我们使用 Adobe Flash Builder 创建由 Flex 提供支持的交互式 Web 应用程序。现在我们正在寻找替代方案,让我们在 UI 设计和迎合 HTML5 的编码方面拥有同样的开发便
我想知道Android/Java 中类似C#/C++ 中的GetTickCount 方法的相应方法吗? 最佳答案 Android 为 SystemClock.uptimeMillis() .请注意,u
我用 Vue + Phaser 开始了新项目,但是当我尝试加载 Assets 时,this.game.load.image 中的“load”和“add”返回“undefined”。我尝试从 JS 文件
我是一名优秀的程序员,十分优秀!