我是Java初学者,请耐心等待.:)我还没有学过任何类似if语句的东西,但我只学习了循环,变量和类.我需要编写一个循环,它产生以下输出:
10 0 9 1 8 2 7 3 6 4 5 5
Run Code Online (Sandbox Code Playgroud)
我可以从片段中看到,数字之间的差异减少了一个,所以从10到0减去10,然后从0到9加9,它在加法和减法之间交替.
我的想法是创建循环,其中我的变量i = 10在循环(i--)中减少1 但我不太确定如何在循环中添加和减去之间交替?
public class Exercise7 {
public static void main(String[] args) {
for(int i = 10; i >= 0; i--) {
System.out.print(i + " ");
}
}
}
Run Code Online (Sandbox Code Playgroud) 在我的文档中,我使用 label 函数来标记表格和数字:
\label{}
Run Code Online (Sandbox Code Playgroud)
然后我使用该\ref{}函数来引用表格或图形。在我的文本中。
我遇到的问题是,在我的文本中我这样写:
As can be seen in Table \ref{table1}.
Run Code Online (Sandbox Code Playgroud)
它会将我的文本输出为:
As can be seen in Table 1.
Run Code Online (Sandbox Code Playgroud)
然而,只有数字“1”是可点击的并通向表格。我希望“表格”部分也可以点击,这样您就可以点击“表格 1”的任何部分并被引用到表格中。
我已经通过使用\phantomsection\label{}and then尝试了不同的方法\hyperref[]{},但这不会动态输出表格或数字编号。
给出以下数据框:
structure(list(`-5` = c(0, 1, 0, 0, 9, 22), `-4` = c(1, 3, 0,
0, 1, 17), `-3` = c(1, 3, 0, 0, 0, 12), `-2` = c(1, 3, 0, 0,
2, 10), `-1` = c(0, 0, 0, 4, 3, 9), `0` = c(0, 1, 0, 2, 2, 21
), `1` = c(0, 1, 1, 7, 1, 21), `2` = c(1, 0, 1, 2, 1, 10), `3` = c(0,
9, 0, 6, 1, 12), `4` = c(0, 2, 0, 5, …Run Code Online (Sandbox Code Playgroud) 我正在用Java编写一个程序,该程序试图将毫秒转换为年,月,日,小时,分钟和秒。
public class convertexercise {
public static void main(String[] args) {
System.out.println("Current Time in milliseconds = " + System.currentTimeMillis());
long[] converter = new long [6];
converter[0] = System.currentTimeMillis() / (1000 * 60 * 60 * 24 * 365); // years
converter[1] = System.currentTimeMillis() / (1000 * 60 * 60 * 24 * 30); // months
converter[2] = System.currentTimeMillis() / (1000 * 60 * 60 * 24); // days
converter[3] = System.currentTimeMillis() / (1000 * 60 * 60); // hours
converter[4] …Run Code Online (Sandbox Code Playgroud) 我有以下"索引"列表,其中包含六种类型的汽车名称及其相关ID(DF1).
DF1 = structure(list(Car = c("Toyota", "Mitsubishi", "Audi",
"Merecedes", "Ford", "Fiat"), ID = structure(c(1L,
2L, 3L, 4L, 5L, 6L), .Label = c("1", "2", "3", "4", "5",
"6"), class = "factor")), .Names = c("Car",
"ID"), row.names = c(NA, 6L), class = "data.frame")
Run Code Online (Sandbox Code Playgroud)
然后我有各种信息列表(DF2).
DF2 = structure(list(City = c("New York City", "Los Angeles", "Chicago", "Miami", "Dallas", "Atlanta"), `2005` = c("", "", "",
"Mercedes, Mitsubishi", "Ford", ""), `2006` = c("",
"", "", "Ford", "Audi", ""), `2007` = c("Toyota",
"", "Toyota", "", "Fiat, Audi, …Run Code Online (Sandbox Code Playgroud) 我知道这听起来像是一个重复的问题,但我昨天花了一整天时间在Stack和Google上进行了广泛的搜索,虽然有不同的解决方案(其中一个是我自己的尝试)我觉得我已经我的代码需要一些指导.
我想简单地创建一个只接受值1到50的扫描仪.在我的主要方法中,我有以下内容:
import java.util.Scanner;
public class test {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int inputInt = getInput(in);
System.out.print(inputInt);
}
public static int getInput(Scanner in) {
System.out.println("Enter the number of questions (between 1-50):");
int input = 0;
while (true) {
input = in.nextInt();
if(input > 50 || input < 1)
break;
System.out.print("Invalid input.\nEnter the number of questions (between 1-50):");
}
return input;
}
}
Run Code Online (Sandbox Code Playgroud)
当输入高于50或低于1时,它似乎没有给我"无效输入"错误.我一直在尝试搜索过去2天的解决方案,我找到的每个解决方案都有自己的问题并试图解决每一个问题,只是将我深入挖掘到一个洞.问题如[1] [2] [3] [4] [5] [6].我觉得在这一点上,如果没有一点指导我就无法理解这一点.