- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在这个网站上寻找与查找程序中最高/最低数据值有关的答案,但我发现的只是与数组有关的代码。我的代码中没有数组,因此我假设查找最高值或最低值的技术将以不同的方式执行。
如果您查看我的代码,您可以在输出的底部看到有两行内容:
The highest performance score was: 0
The lowest performance score was: 0
我根本不知道如何使用代码来输出最高性能分数或最低性能分数。我想要比较和显示正在分析的两台计算机的两个性能分数,而不是那些 0。再次强调,我希望输出中的不是 0,而是:
The highest performance score was: 15400.000000000002
The lowest performance score was: 13000.0
那么我该如何执行呢?感谢所有帮助。
输出:
How many computers are being processed? 2
Computer Hardware Graphics Quality Recommendation Tool
Enter the clock speed (in Megahertz) of your graphics card: 1000
Enter the clock speed (in Megahertz) of your processor: 2000
Enter the number of cores that your processor has: 4
Monitor resolution menu:
1. 1280 x 720
2. 1920 x 1080
3. 2560 x 1440
4. 3840 x 2160
Please select one of the choices above: 1
GPU Clock Speed: 1000 MHz
CPU Clock Speed: 2000 MHz
Number of cores: 4
Monitor Resolution: 1280 x 720
Performance Score: 13000.0
Recommended Graphics Quality: Medium
The highest performance score was: 0
The lowest performance score was: 0
Computer Hardware Graphics Quality Recommendation Tool
Enter the clock speed (in Megahertz) of your graphics card: 2000
Enter the clock speed (in Megahertz) of your processor: 3000
Enter the number of cores that your processor has: 6
Monitor resolution menu:
1. 1280 x 720
2. 1920 x 1080
3. 2560 x 1440
4. 3840 x 2160
Please select one of the choices above: 3
GPU Clock Speed: 2000 MHz
CPU Clock Speed: 3000 MHz
Number of cores: 6
Monitor Resolution: 2560 x 1440
Performance Score: 15400.000000000002
Recommended Graphics Quality: High
The highest performance score was: 0
The lowest performance score was: 0
我的代码:
/*
This program will help the user identify and further understand the capabilities of their computer's hardware.
When the program is run, the user will be asked to input facts and information about their computer's hardware.
Once the information about the user's computer hardware is processed by the program,
the user will see results that explain the capabilities and potential of their computer.
In this new edition of the program, the user will have the option to analyze multiple computers, rather than just one.
They will also be able to compare their computer's performance score at the end.
*/
import java.util.Scanner; //This allows the program to utilize the Scanner class to get the user's input.
public class Project2_Ben_Mayo
{
public static void main(String[] args)
{
String title = "Computer Hardware Graphics Quality Recommendation Tool"; //Title string
int numOfComputers = 0; //To hold the number of computers being tested
int GPUspeed = 0; //To hold the user's GPU clock speed (in Megahurtz)
int CPUspeed = 0; //To hold the user's CPU clock speed (in Megahurtz)
int numCores = 0; //To hold the number of cores in the user's CPU
int menuChoice = 0; //To hold the user's menu choice
String monitorRes = ""; //To hold the user's monitor resoltion
String quality = ""; //To hold the quality of performance while gaming
double multiplier = 0.0; //To hold the multiplier value
double performanceScore = 0.0; //To hold the performance score value
int highestScore = 0;
int lowestScore = 0;
Scanner sc = new Scanner(System.in); //This is the scanner object
System.out.print("\n" + "How many computers are being processed? "); //ask the user to enter the number of computers they would like to test
numOfComputers = sc.nextInt();
if (numOfComputers <= 0) { //If the number of computers is less than or equal to 0, this notifies the user that the number of computers must be greater than or equal to 1
System.out.print("The number of computers being processed must be at least one.");
}
//Use for loop to ask the user to enter the information for each computer
for(int computerNumber = 0; computerNumber < numOfComputers; computerNumber++) { //Begin for loop
System.out.println("\n" + title); //Print the title
System.out.print("\n" + "Enter the clock speed (in Megahertz) of your graphics card: "); //This is an indicator of how fast the user's graphics card is
GPUspeed = sc.nextInt();
while(GPUspeed < 800 || GPUspeed > 2000) { //While the user provides an invalid input, display an error message and have them re-enter their input
System.out.print("Invalid input. Plase enter a valid GPU speed: "); //display an error message if the user gave invalid input
GPUspeed = sc.nextInt(); //re-read in the user's input for the GPU speed
}
System.out.print("Enter the clock speed (in Megahertz) of your processor: "); //This is an indicator of how fast the user's processor is
CPUspeed = sc.nextInt();
while(CPUspeed < 1000 || CPUspeed > 5500) { //While the user provides an invalid input, display an error message and have them re-enter their input
System.out.print("Invalid input. Plase enter a valid CPU speed: "); //display an error message if the user gave invalid input
CPUspeed = sc.nextInt(); //re-read in the user's input for the CPU speed
}
System.out.print("Enter the number of cores that your processor has: "); //This is an indicator of how many cores the user's CPU contains
numCores = sc.nextInt();
while(numCores < 1 || numCores > 16) { //While the user provides an invalid input, display an error message and have them re-enter their input
System.out.print("Invalid input. Plase enter a valid number of cores: "); //display an error message if the user gave invalid input
numCores = sc.nextInt(); //re-read in the user's input for the number of cores
}
//Monitor resolution menu
System.out.println("Monitor resolution menu:");
System.out.println("1. 1280 x 720");
System.out.println("2. 1920 x 1080");
System.out.println("3. 2560 x 1440");
System.out.println("4. 3840 x 2160");
System.out.print("Please select one of the choices above: "); //Ask the user to choose the resolution of their monitor
menuChoice = sc.nextInt();
while(menuChoice < 1 || menuChoice > 4) { //While the user provides an invalid input, display an error message and have them re-enter their input
System.out.print("Invalid selection. Plase pick a valid option from the menu: "); //display an error message if the user gave invalid input
menuChoice = sc.nextInt(); //re-read in the user's input for the menu selection
}
//Assign the menu options to their values to enable the menu to funtion correctly
if (menuChoice == 1) { //If the user selects menu option number 1, "monitorRes" = "1280 x 720"
monitorRes = "1280 x 720";
}
else if (menuChoice == 2) { //If the user selects menu option number 2, "monitorRes" = "1920 x 1080"
monitorRes = "1920 x 1080";
}
else if (menuChoice == 3) { //If the user selects menu option number 3, "monitorRes" = "2560 x 1440"
monitorRes = "2560 x 1440";
}
else if (menuChoice == 4) { //If the user selects menu option number 4, "monitorRes" = "3840 x 2160"
monitorRes = "3840 x 2160";
}
//This segment will determine what the mulitplier object will be
if (menuChoice == 1) {
multiplier = 1;
}
else if (menuChoice == 2) {
multiplier = .75;
}
else if (menuChoice == 3) {
multiplier = .55;
}
else if (menuChoice == 4) {
multiplier = .35;
}
//Performance Score multiplier
performanceScore = ((5 * GPUspeed) + (numCores * CPUspeed)) * multiplier;
//Recommended graphics quality that the user's hardware can support.
if (performanceScore >= (17000)) { //If the performance score is greater than or equal to 17,000, the quality of the performance is ultra
quality = "Ultra";
}
else if (performanceScore >= (15000)) { //If the performance score is greater than or equal to 15,000, the quality of the performance is high
quality = "High";
}
else if (performanceScore >= (13000)) { //If the performance score is greater than or equal to 13,000, the quality of the performance is medium
quality = "Medium";
}
else if (performanceScore >= (11000)) { //If the performance score is greater than or equal to 11,000, the quality of the performance is low
quality = "Low";
}
else if (performanceScore < (11000)) { //If the performance score is less than 11,000, the quality of the performance is unplayable
quality = "Unable to Play";
}
//Print the results
System.out.println("\nGPU Clock Speed: " + GPUspeed + " MHz"); //User's GPU speed (in Megahurtz)
System.out.println("CPU Clock Speed: " + CPUspeed + " MHz"); //User's CPU speed (in Megahurtz)
System.out.println("Number of cores: " + numCores); //Number of cores that the user's CPU contains
System.out.println("Monitor Resolution: " + monitorRes); //User's moniter resolution
System.out.println("Performance Score: " + performanceScore); //The user's computer performance score
System.out.println("Recommended Graphics Quality: " + quality); //Estimated quality of graphics during gameplay
System.out.println("\n" + "The highest performance score was: " + highestScore);
System.out.println("The lowest performance score was: " + lowestScore);
} //End for loop
} //End class
} //End main
最佳答案
如果您不想创建列表并将 PerformanceScore 值存储在其中,则可以在打印结果之前在 for 循环内添加逻辑,以便将您的最高和最低 PerformanceScore 存储在变量最高和最低性能分数中到目前为止已迭代:
if(performanceScore > highestScore) {
highestScore = performanceScore;
}
if(lowestScore == 0 || performanceScore < lowestScore) {
lowestScore = performanceScore;
}
关于java - 提供多个数据值后,可以编写什么代码来比较数据并确定最高/最低值? java ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60531658/
我刚刚开始学习,我的一项练习需要帮助。 我需要最终用户输入每个月的降雨量。然后我需要输出平均降雨量、最高月份和最低月份以及降雨量高于平均水平的月份。 我一直在最高和最低中得到相同的数字,我不知道为什么
我试图让一排 div 都与最高的那个的高度相匹配,所以它们看起来是统一的。 我已经阅读了很多这方面的资料,但似乎找不到任何适用于跨浏览器的解决方案。 我目前使用的脚本是: var maxHei
我有一个像 [1,4,3,1,6,5,1,4,4] 的数组 这里最高元素频率是 3 ,我需要从数组中选择频率为 3 的所有元素,如上例中的 [1,4] 。 我已经尝试过这个 var count = {
我有一个学生记录列表,grades ,我想按 GPA 排序,返回前 5 个结果。由于某种原因count awk '{ if (count awk '{ if (count<=8) print $3,
我有一个用于显示博客文章的页面。在页面的开头,我使用以下 SQL 获取数据: SELECT posts.*, count(comments.post_id) as number_of_comments
我有一张 table 城市 |状态|比赛|值(value) 可以有多个相同城市/州/种族和不同值的记录。 我想创建一个新表,其中每个城市|州|种族有一条记录 与 计数(原始表中包含城市/州/种族的记录
我是一名初级 Java 程序员(例如 0 级...)。我正在做这个项目,但我已经被难住了好几天了。我可能还有很多我没有注意到的小错误。 项目是这样的: 要求用户输入从 0.00 到 100.00 的一
我已经对我的数据进行了分组。现在,我要做的是每周从“高”列中选择最高值,并从“低”列中选择最低值,然后使用最高值减去最低值得到范围。但是代码总是错误的。有人对我有想法吗? 这是我的 DataFrame
所以几个月前我在参加编程面试时,由于某种原因这个问题让我绊倒了。我可以想到几个解决方案,但其中大多数似乎效率极低。虽然多年来我一直以某种身份进行编程,但我目前正在大学攻读 CS 学位,所以我的引用点可
我已经制定了一个程序来显示给定日期的特定时间的最高和最低流行项目。该过程没有错误或异常,并且一切正常。如您所见,为了显示 Items 的第一条记录,查询重复了两次,但唯一的区别在于顺序(ASC 和 D
我正在尝试将配对的 div 设置为相同的高度。 Some text Some text Some textSome textSome textSome textSome text Som
R 提供了最大值和最小值,但除了对整个向量进行排序然后从此向量中选取值 x 之外,我没有看到一种真正快速的方法来查找顺序中的另一个值。 例如,是否有更快的方法来获取第二高值? 最佳答案 使用sort(
这是我的命令: top -b -n 1 | head -3 | tail -n 1 | awk '{ print $2 }' 我运行一个 bash 脚本来获取这些详细信息(还有平均负载和内存消耗)并将
对于这个计划,我的目标是...使用 findKth 查找最高分、最低分、中位数和平均分用户必须输入数字(输入-1以停止扫描),但他们不知道有多少个以及是否已排序但是,我在尝试执行此操作时遇到了一些问题
我正在创建这个网站: https://www.melkerhei.be/smeltkroes/index.html 左上角的标志应该是可以点击的。这是代码:
关闭。这个问题是off-topic .它目前不接受答案。 想改进这个问题吗? Update the question所以它是on-topic用于堆栈溢出。 关闭 9 年前。 Improve this
我的 table 是这样的: name | var ---------------- Joe | 3 Liz | 1 Liz | 4 Joe | 2 Peter
我有这个: function sayHello() { return new Promise( resolve => { throw new Error('reject');
JSFiddle:Example 我正在寻找一种方法来使容器 div 的高度等于其最高的子级。 每个其他子项的大小都应调整为容器的高度。 如果子元素超出其宽度,我还需要容器水平滚动。 到目前为止,我已
我有一个大小为 208 的列表(208 个句子数组),它看起来像: all_words = [["this is a sentence ... "] , [" another one hello bo
我是一名优秀的程序员,十分优秀!