我试图使用一个文件在命令窗口中创建一个菜单.用户从这些菜单选项中进行选择.系统会提示他们输入一个数字.该数字传递给两个重载方法,这些方法确定数字是整数还是浮点数.计算完成后,结果将打印到屏幕上,菜单重新出现.这是我的两个文件中的代码.
MyMathOpsTest类:
import java.util.Scanner; // import Scanner class
public class MyMathOpsTest
{
//method to pause until a key is pressed
public static void pause()
{
try
{
System.out.print("Press <Enter> to continue...");
System.in.read();
}
catch (Exception e)
{
System.err.printf("Error %s%c\n",e.getMessage(),7);
}
}//end pause
public static void main( String args[] )
{
//variables to capture keyboard input
Scanner keyBd = new Scanner( System.in );
char selection;
//int selection;
do{//display menu
System.out.println( "1. Square a Number");
System.out.println( "2. Cube a Number");
System.out.println( "3. …
Run Code Online (Sandbox Code Playgroud) 有一个与while函数有关的新问题.听起来很简单,我仍然无法绕过它.
就像我上一个程序一样,这个程序在正确和错误的消息之后意外关闭.我希望在输入数字后循环,这样程序就不会停止.感谢您的帮助,如果有的话.
#include <iostream>
using namespace std;
int main()
{
int X = 0; //setting the first variable
int num; //setting the second
while (X == 0) //this should happen whenever X is equal to 0
{
cout << "Type a number bigger than 3. "; //output
X++; //This should increase X, so that the next while function can happen
}
while (X == 1) //again, since I increased x by one, (0+1=1 obviously) this should happen
{
cin >> …
Run Code Online (Sandbox Code Playgroud) 我的字符串看起来像这样:
$str = www.example.com/forums/pages/name.php
Run Code Online (Sandbox Code Playgroud)
我想得到这个:
name
Run Code Online (Sandbox Code Playgroud)
我试过了:
echo rtrim($str,".php");
Run Code Online (Sandbox Code Playgroud)
但我得到了 www.example.com/forums/pages/name
非常感谢.
我必须在C中添加一个数字.我必须在没有像'+','++'等算术运算符的情况下这样做.
我写了以下代码行.
int a = 1234;
int b = 1;
printf("%d", a ^ b);
Run Code Online (Sandbox Code Playgroud)
这工作正常,直到达到整数限制,即,对于32位,它是4294967295.但我在许多其他网站中看到,执行相同的两个数字的AND,然后是XOR和左移.
请告知我的方法是否正确,因为我是C的新手.
所以我对String类的equals()方法有问题.我正在尝试检查以确保用户输入不仅仅是一个新行字符("\n"),但每当我比较只是换行符的用户输入时,它总是返回false.这是代码:
command = kb.nextline();
if(!command.equals("\n"))
{
performProcess(command);
}
Run Code Online (Sandbox Code Playgroud)
其中"kb"是扫描仪.有任何想法吗?
我正在加密和解密Web应用程序.我已经构建了一个使用24字节密钥来加密/解密消息的算法.
查看此算法,请在此算法中提出可以使其表现更好的重要和错误.您的贡献可以帮助我们改进算法.
代码在我的GitHub上提供
算法:-
1] 24位输入/生成的密钥将被转换为24位代码的ASCII码.
public void setKey(char[] arr){
for(int i=0;i<24;i++){
key[i] = (int)arr[i];
}
}
Run Code Online (Sandbox Code Playgroud)
2]输入的字符串将更改为字符数组.
然后,每个字符将首先使用键的值递增,并更改为10位二进制代码.
public void Encryption(String text){
char[] msg = text.toCharArray();
int flag = 0;
int l = msg.length;
for(int i=0;i<l;i++){
int a = (int)msg[i];
// System.out.print(msg[i]+" "+a+"-> ");
if(flag>23)
flag=0;
int b=a+key[flag];
flag++;
//System.out.print(b+" | ");
String z = binary(b);
sb.append(lookUpTool(z));
//Character.toString((char)b);
}
//sb.append(sumBinary);
sb = comp1(sb);
}
Run Code Online (Sandbox Code Playgroud)
3] lookUp(): - 它将10位字符串作为输入和矩阵,并将该字符串分成两个5位二进制代码.
然后,我们将计算每个5位二进制代码的十进制值.
示例:0011101101 - > 00111 = 7和01101 …
java ×2
c ×1
c++ ×1
cryptography ×1
encryption ×1
equals ×1
newline ×1
overloading ×1
php ×1
while-loop ×1