如何编写一个条件来检查名为s的字符串是否至少包含2个字符 [英] How do I write a condition that checks if a string called s has at least 2 characters

查看:53
本文介绍了如何编写一个条件来检查名为s的字符串是否至少包含2个字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何编写检查名为s的String是否至少包含2个字符的条件?



我怎么做其余的>>

编写一个条件来检查一个名为s的字符串是否至少有其中2个字符



写一个条件,检查字符串a和字符串b是否从第2个字符到第5个字符串相同

字符忽略大小



条件/ ifs:



写一个if / else语句打印真棒! 如果一个名为number的变量是5的倍数但不是

9,或者大于1000并打印Lame!否则



开关:

写一个switch语句,根据一个叫做alert的字符串进行切换。

如果alert等于red,它应该打印Ohh no

如果警告等于黄色它应该打印保持冷静

如果警报等于绿色它应该打印我们没事

它应该说我觉得现在的同类相食是好的如果警惕等于其他任何东西



原语和参考值:

命名3个原始整数类型,2个原始浮点数类型,以及一个原始类型

既不是



int [] arr = {1,2,3};

arr2 = arr;

arr2 [1] + = 6;

现在arr是什么? __ __ __



类/方法:

创建一个包含两个字段的Student类:一个名为name的字符串和一个名为grade的int。创建一个构造函数

,它接受两个参数并使用参数初始化字段。制作一种名为练习的方法

将等级提高10并返回新等级。



在课堂上有一个主要方法:< br $>


public static void main(String [] args){



}

,在里面制作一个Student对象,使用练习方法,然后打印出新的等级。



数组/循环:



创建一个名为nums的整数数组并初始化它以便它可以容纳100个东西。



创建一个带有int数组的静态函数参数并检查所有值以查看是否有13。它

如果找到13则返回true,否则返回false并且应该在任何长度的数组上工作



创建一个for语句,从20开始向后计数5s



我尝试过:



我已经尝试了一切,我只是不明白......请帮忙,我需要知道这些问题。嘿明天会在课堂上问...帮助

How do I write a condition that checks if a String called s has at least 2 characters?

also how do I do the rest of this >>
Write a condition that checks if a String called s has at least 2 characters in it

Write a condition that checks whether String a and String b are identical from the 2 nd character to the 5 th
character ignoring case

Conditions/ifs:

Write an if/else statement that prints "Awesome!" if a variable called number is a multiple of 5 but not
9, or greater than 1000 and prints "Lame!" otherwise

Switch:
Write a switch statement that switches based on a String called alert.
If alert equals "red" it should print "Ohh no"
If alert equals "yellow" it should print "Stay calm"
If alert equals "green" it should print "We’re ok"
And it should say "I guess cannibalism is ok now" if alert equals anything else

Primitives and reference values:
Name 3 primitive integer types, and 2 primitive floating number types, and one primitive type that is
neither

int[] arr = {1, 2, 3};
arr2 = arr;
arr2[1] +=6;
What does arr equal now? __ __ __

Classes/Methods:
Create a Student class with two fields: a String called name and an int called grade. Make a constructor
that takes two arguments and initializes the fields with the arguments. Make a method called practice
that increases the grade by 10 and returns the new grade.

Have a main method in your class:

public static void main(String[] args){

}
and inside it make a Student object, use the practice method on it, and print out the new grade.

Arrays/ loops:

Create an integer array called nums and initialize it so it can hold 100 things.

Create a static function that takes an int array argument and checks all the values to see if any are 13. It
returns true if it finds a 13 and false otherwise and should work on an array of any length

Create a for statement that counts backwards from 20 counting by 5s

What I have tried:

I've tried everything and I just don't understand it...please help, I need to know these questions fro they will be asked in class tomorrow...HELP

推荐答案

引用:

我怎么做其余的

直到那里,我愿意帮忙。甚至渴望。

但现在呢?没有。

我们不做你的功课:这是有原因的。它就是为了让你思考你被告知的事情,并试着理解它。它也在那里,以便您的导师可以识别您身体虚弱的区域,并将更多的注意力集中在补救措施上。



如果你甚至无法查看长度你自己需要一个字符串,然后你需要拼命重新阅读你的课程笔记,并在开始练习之前至少学习基础知识。亲自尝试一下,你可能会发现它并不像你想象的那么困难!



如果你遇到一个具体的问题,那么请询问一下,我们会尽力而为帮助。但是我们不打算为你做这一切!

Right up to there, I was willing to help. Even eager.
But now? No.
We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.

And if you can't even check the length of a string on your own, then you need desperately to re-read your course notes so far and learn at least the basics before you get to this exercise. Try it yourself, you may find it is not as difficult as you think!

If you meet a specific problem, then please ask about that and we will do our best to help. But we aren't going to do it all for you!


String(Java Platform SE 7) [ ^ ]。


这篇关于如何编写一个条件来检查名为s的字符串是否至少包含2个字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆