可能重复:
如何比较Java中的字符串?
我无法理解为什么声明的变量不一样.
前代码:
String firstPart = "F";
String whole = "False";
String connected = firstPart + "alse";
System.out.println(connected == whole);
Run Code Online (Sandbox Code Playgroud)
现在这产生一个布尔值,我认为它将是"真的"但它不是,它出来是假的,我不明白为什么.
有人可以解释一下吗?
我得到了我的手腕,因为在一项任务中,当输入错误发生时,我有一个方法调用.我不知道如何使用或使用什么而不是我写的代码.我需要帮助才能找到正确的方法.
我喜欢编码所以我只需要以正确的方式轻推!:)
我写的代码看起来像这样.
private void SumTheNumbers()
{
Console.Write("Please give the value no "+ index + " :");
if (false == int.TryParse(Console.ReadLine(), out num))
{
//Errormessage if the user did not input an integer.
Console.WriteLine("Your input is not valid, please try again.");
Console.WriteLine();
sum = 0;
SumTheNumbers();
}
else
{
//Calculate the numbers given by user
sum += num;
}
}
Run Code Online (Sandbox Code Playgroud) 我遇到了这段代码的麻烦,我无法弄清楚如何让它工作.我无法弄清楚问题是什么,看起来它应该工作.两个地方名为m_nameList的字符串数组都标记为'非静态字段,方法或属性'Solutionname.classname.m_nameList'所需的对象引用
代码:
public static bool CheckVacantSeats(int seatNumber)
{
if (m_nameList[seatNumber] == null)
{
return true;
}
return false;
}
Run Code Online (Sandbox Code Playgroud)
m_nameList是在此静态bool之前在构造函数中声明的数组:
public SeatManager(int maxNumberOfSeats)
{
m_totNumOfSeats = maxNumberOfSeats;
m_nameList = new string[m_totNumOfSeats];
m_priceList = new double[m_totNumOfSeats];
}
Run Code Online (Sandbox Code Playgroud)
我从另一个类调用CheckVacantSeat:
bool validSeats = SeatManager.CheckVacantSeats(seatNumber, m_nameList);
Run Code Online (Sandbox Code Playgroud)
我无法弄清楚它有什么问题.所以我需要一些帮助来弄清楚为什么m_nameList对我不起作用?
提前致谢!!
//问候
我完全是 Haskell 的菜鸟我根本无法让我的代码工作,我也不知道如何修复它!我需要帮助 :) 如果有人知道我需要查看哪里才能解决我的问题,我将非常感谢您提供正确方向的想法和推动。
我正在尝试创建一种 C# string.Format ,它会重复直到列表完成。该列表由用户输入创建,然后我只想重复一个字符串,直到列表完成。
test :: Integer -> String
let list_n [0..k]
test k = putStrLn (r * r) | r <- list_n --My idea here is that i am forcing
--the entire list onto r and making it repeated as long as there is more in the
--list, But im not even sure that is possible :(
Run Code Online (Sandbox Code Playgroud)
任何人都对如何做到这一点有更好的想法?我希望所有的结果都在一行而不是一行中,因此我试图创建迭代,但在 HaskeLL 中,说起来容易,做起来容易:/
如何在此类父类中调用私有方法?我所做的是一个丑陋的代码,但虽然我不认为这是一个真正的解决方案.
非常感谢有关如何做到这一点的一些建议.我已经找到了解决方案,但是没有给我一些明确的问题.
public abstract class Car {
public void passItOn(int a) {
takesVariable(a);
}
private void takesVariable(int a) {
//Process the variables
}
Run Code Online (Sandbox Code Playgroud)
孩子:
public abstract class Wheel extends Car {
boolean a = anotherMethod();
if(value() != a) {
passItOn(a);
}
}
Run Code Online (Sandbox Code Playgroud)
我的收益率存在一些问题,但我在上面!所有人都会给予回复+分数!
我正在寻找一种有效的方法,并有助于捕获错误输入.如果输入不是1或2,我需要处理.或者 - 或者只是任何一封信.我试过捕获,似乎没有什么工作:/
有人想让我尝试一下吗?我很满意任何建议!! Thx提前!
问候
我到目前为止编写的代码如下所示:
console.WriteLine();
Console.Write("Make your choice: ");
int myinput = int.Parse(Console.ReadLine());
if (myinput == 1)
{
FirstEvent();
}
if (myinput == 2)
{
SecondEvent();
}
Run Code Online (Sandbox Code Playgroud) 我在将三个不同的面板放在框架顶部时遇到了麻烦,因为我需要在每个面板上放置不同的布局.我似乎无法让它工作,我已经连续4天尝试了.我无法在此代码中找到我出错的地方.
我这样做是最好的方式吗?任何想法或帮助将不胜感激!!!!!
我的代码:
public Mem() {
super("3 panels on 1 frame");
JFrame frame = new JFrame();
setSize(500, 500);
setDefaultCloseOperation(EXIT_ON_CLOSE);
JPanel p1 = new JPanel();
JPanel p2 = new JPanel();
JPanel p3 = new JPanel();
//Adding three different panels with borderlayout
frame.setLayout(new BorderLayout());
//Panel 1 is the Player Panel with labels
JLabel ply1 = new JLabel("Player 1");
JLabel ply2 = new JLabel("Player 2");
JLabel ply3 = new JLabel("Player 3");
JLabel ply4 = new JLabel("Player 4");
p1.add(ply1); p1.add(ply2); p1.add(ply3); p1.add(ply4);
//Panel 2 …Run Code Online (Sandbox Code Playgroud) 我在发送List<>文本框时遇到问题,我不确定是什么问题.我已经检查过,因此List实际上有值,并且它可以从类中正确地转移到这个块中.
代码:
public void Listtest(List<string> m_customers)
{
lstRegistry.Items.Clear();
for (int index = 0; index == m_customers.Count; index++)
{
lstRegistry.Items.Add(m_customers[index]);
}
}
Run Code Online (Sandbox Code Playgroud)
正在发送的另一个类 List<>
class CustomManager
{
//private List<Customer> m_customers;
List<string> m_customers = new List<string>();
public void CreateNewString(string adresslist, string emaillist, string phonelist, string namelist)
{
MainForm strIn = new MainForm();
string newlist = string.Format("{0,-3} {1, -10} {2, -20} {3, -30}", namelist, phonelist, emaillist, adresslist);
m_customers.Add(newlist); //líst is created.
strIn.Listtest(m_customers);
}
}
Run Code Online (Sandbox Code Playgroud)
我只是不能让它工作,我真的卡住了.:/
感谢任何和所有的帮助和想法!
//问候
我知道如何在VB中执行此操作,但我在C#编码,所以我需要弄清楚如何获得两个不同的radomized整数(1-8),我似乎无法让它工作,我得到相同的一遍又一遍甚至更多我越努力.我已经阅读了很多,但我找不到更具体的帮助,因为大多数人只想要一个rnd数字,我可以做...很容易;)
我编码的是你不给我两个不同的数字.
public string GetFruitCombination()
{
Random fruitcombo = new Random();
int indexone = fruitcombo.Next(0, 8);
Random fruitcombotwo = new Random();
int indextwo = fruitcombotwo.Next(0, 8);
string firstfruit = m_fruit[indexone];
string secondfruit = m_fruit[indextwo];
return string.Format("{0}&{1}", firstfruit, secondfruit);
}
Run Code Online (Sandbox Code Playgroud)
必须有一种更简单的方法来获得2个不同的rnd数字吗?所以我需要有人帮助我朝着正确的方向前进!
在此先感谢任何想法和帮助!
//问候
我正在尝试从字符串列表中获取一个随机项并将其保存到另一个字符串列表但我无法让我的代码工作.
import System.Random
import Control.Applicative ( (<$>) )
food = ["meatballs and potoes","veggisoup","lasagna","pasta bolognese","steak and fries","salad","roasted chicken"]
randomFood xs = do
if (length xs - 1 ) > 0 then
[list] <- (fmap (xs!!) $ randomRIO (0, length xs -1))
else
putStrLn (show([list])
Run Code Online (Sandbox Code Playgroud)
我在输入'< - '上得到解析错误,但我确定还有更多问题:/还有一个问题,列表可能连续两天包含相同的菜肴,这不是我想要的,我猜我可以删除重复项,但这也将删除列表中的项目数,我希望保持与列表中的数字相同.
任何人都知道我怎么能这样做?我一直在寻找一天,我找不到对我有用的东西,但那仅仅是因为我在错误的地方寻找.关于我如何能够做到这一点或在哪里可以找到信息的任何建议都将受到极大关注!
//问候
我无法弄清楚为什么我得到两个不同的结果,但我确定它与IO我有所关系,我开始讨厌!
例如:
ghci> x <- readFile "foo.txt"
ghci> let y = read x :: [Int]
ghci> :t y
y :: [Int]
Run Code Online (Sandbox Code Playgroud)
现在,当我创建该文件并执行相同的操作时,它出现了IO [Int]吗?
foo.txt 是一个仅包含以下内容的txt文件: 12345
有人可以向我解释一下吗?因为我要抢购它!
感谢您的任何见解!
我试图找出是否有可能在ASP中的另一个控件内部有一个控件,如下所示:
<asp:FormView ID="FormView1" runat="server" Width="630px" Height="496px">
<ItemTemplate>
<asp:Literal ID="ID" runat="server">Idnumber: </asp:Literal><%#Eval("ID") %>
<asp:DataList ID="DataList1" runat="server">
<ItemTemplate>
<asp:HyperLink ID="ID" runat="server"><a href="url/<%# Eval("ID") %>/<%#Eval("FILE")%>"> <%# Eval("FILE") %> </a></asp:HyperLink>
</ItemTemplate>
</asp:DataList>
</ItemTemplate>
</asp:FormView>
Run Code Online (Sandbox Code Playgroud)
我可以访问DataList1控件吗?我一直在尝试,但我无法弄清楚,我应该能够访问嵌套控件,但我不能让它去做.
我在接收中遇到了一个问题,因为我是Erlang的新手,我已经阅读了我能找到的所有内容,但没有什么能让我更清楚.
这里的问题是,它永远不会检查第二后卫,我不明白为什么.
我写的警卫错了吗?有另一种方式吗?
receive
{ask, {guessed, N}, User} when guessed < N ->
From ! {answer, {wrong, N, lower}},
main_loop(N, update(wrong, Stats));
{ask, {guessed, N}, User} when guessed > N ->
From ! {answer, {wrong, N, higher}},
main_loop(N, update(wrong, Stats));
end.
Run Code Online (Sandbox Code Playgroud)