Can someone please help me write a Java boolean expression?

2009-08-18 7:37 am
Write a java expression which tests whether the String variable, name, contains the char literal 'e'.

回答 (2)

2009-08-18 12:47 pm
✔ 最佳答案
//pk

import java.util.Scanner;

public class Test3 {
public static void main (String[] args) {
Scanner kb = new Scanner (System.in);
System.out.print("Enter name: ");
String name = kb.nextLine();
if (name.indexOf('e') == -1) {
System.out.println ("Character 'e' is NOT present in text ["+name+"]");
}
else {
System.out.println ("Character 'e' is present in text ["+name+"]");
}
}
}
2009-08-18 3:59 pm
name.indexOf('e') == -1


收錄日期: 2021-05-01 00:58:47
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20090817233725AARCiM4

檢視 Wayback Machine 備份