- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试编写一个使用凯撒密码对纯文本进行编码的java程序。我有一个包含纯文本的文件和另一个应放置编码文本的文件。我不知道问题是什么,但出现错误:线程“main”java.util.NoSuchElementException 中出现异常。请帮助我!
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintStream;
import java.util.Scanner;
public class zevendesim {
public static void main(String[] args)
throws FileNotFoundException {
Scanner input=new Scanner(new File("C:\\erida\\t.txt"));
PrintStream output=new PrintStream(new File("C:\\erida\\c.txt"));
String text=input.nextLine();
zevendesim(text, output);
}
public static void zevendesim(String text, PrintStream output)
{
int i=0;
String s;
Scanner data = new Scanner(text);
while (data.hasNext()) {
s=data.next();
if (s.charAt(i) >= 97 && s.charAt(i)<= 120)
{
int x = s.charAt(i) - 97;
x = (x + 2) % 26;
if (x < 0)
x += 26;
// = (char) (x + 32);
}
output.print(" " + data.next());
}
}
}
请帮我找到解决办法!
错误堆栈跟踪是:
Exception in thread "main" java.util.NoSuchElementException at
java.util.Scanner.throwFor(Unknown Source) at java.util.Scanner.next(Unknown Source) at Zevendesimi.zevendesim.zevendesim(zevendesim.java:33) at Zevendesimi.zevendesim.main(zevendesim.java:15)
最佳答案
错误发生在 output.print(""+ data.next());
中,因为最后一个标记已在几行之前使用 s=data.next( );
您可能想将 x 写入输出?
关于java - 使用文件的凯撒密码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40674421/
我刚刚开始学习 C 语言类(class),并且遇到了命令行参数的问题。分配是这样的(还有更多,但这是开头有关命令行参数的部分): - 你的程序必须接受一个命令行参数,一个非负整数。 - 如果您的程序在
我需要检查命令行参数中是否有非数字字符。例如: ./problem 20x 应该打印出“不是数字”,因为它包含一个 x。我的代码似乎没有循环遍历命令行参数中的所有字符。 我基本上尝试了不同类型的循环,
这里我有从标准输入将字符流输入到数组中的代码。然后将该数组转换为二维数组。然后,它将该数组从行列顺序更改为列行顺序。然后它打印出创建凯撒移位加密的新数组。我遇到的问题是我的数组开始使用第二个用户输入的
我有点被这个问题困住了。当我运行程序时,由于某种原因,循环经过 z 的所有字母都不会打印。问题来自这个链接:http://docs.cs50.net/2016/x/ap/problems/caesar
我是一名优秀的程序员,十分优秀!