charat

How to check 2 charAt(i)

此生再无相见时 提交于 2019-12-13 02:54:16
问题 I have this lines: 812.12 135.14 646.17 1 812.12 135.14 646.18 1 812.12 135.14 646.19 10 812.12 135.14 646.20 10 812.12 135.14 646.21 100 812.12 135.14 646.22 100 I want to delete only the last group so I did code like this: if(lines[i].charAt(lines[i].length())-1>= '0'&&lines[i].charAt(lines[i].length()-1)<= '9'){ lines[i] = lines[i].substring(0, lines[i].length()-1); } else if(lines[i].charAt(lines[i].length())>='10'+c&&lines[i].charAt(lines[i].length()-1)<='99'){ lines[i] = lines[i]

How do you use charAt with an array?

守給你的承諾、 提交于 2019-12-11 23:20:23
问题 i am having a bit of trouble in implementing charAt with an array. I am a beginner in Java (and this is my only coding experience i suppose). The objective: To create a program that the user inputs any string, and the total number of vowels are recorded in the output (case sensitive) example: Input: charActer Output: a = 1 A = 1 e = 1 import java.util.Scanner; public class HW5 { public static void main(String[] args) { String [] alphabets = {

How can I check if the char array has an empty cell so I can print 0 in it?

北城以北 提交于 2019-12-05 09:54:28
Code: public void placeO(int xpos, int ypos) { for(int i=0; i<3;i++) for(int j = 0;j<3;j++) { // The line below does not work. what can I use to replace this? if(position[i][j]==' ') { position[i][j]='0'; } } } Change it to: if(position[i][j] == 0) Each char can be compared with an int. The default value is '\u0000' i.e. 0 for a char array element. And that's exactly what you meant by empty cell , I assume. To test this you can run this. class Test { public static void main(String[] args) { char[][] x = new char[3][3]; for (int i=0; i<3; i++){ for (int j=0; j<3; j++){ if (x[i][j] == 0){ System

IndexOutOfBoundsException when taking character input from the user

最后都变了- 提交于 2019-12-02 13:41:01
In the 15th line ch = s1.charAt(0); , why ch is not getting the 0th word of s1, i.e., the operator . I've tried without using the try-catch method but then the error was regarding the exception and now no exception, no errors but the program don't ask for operator and directly after inputting the 1st and 2nd value , it shows the exception"can't do that" please post your kind replies, thanks import java.util.Scanner; class apples { public static void calcu() { try{ int a, b; String s1; char ch; Scanner sc = new Scanner(System.in); System.out.print("Enter the 1st value : "); a = sc.nextInt();

Capitalize First Letter Of Each Word In A String - JavaScript

痞子三分冷 提交于 2019-11-26 22:08:04
What is wrong with this function? I am lost thanks for help. function titleCase(str) { var splitStr = str.toLowerCase().split(' '); for (var i = 0; i < splitStr.length; i++) { if (splitStr.length[i] < splitStr.length) { splitStr[i].charAt(0).toUpperCase(); } str = splitStr.join(' '); } return str; } titleCase("I'm a little tea pot"); somethinghere You are not assigning your changes to the array again, so all your efforts are in vain. Try this: function titleCase(str) { var splitStr = str.toLowerCase().split(' '); for (var i = 0; i < splitStr.length; i++) { // You do not need to check if i is

Capitalize First Letter Of Each Word In A String - JavaScript

岁酱吖の 提交于 2019-11-26 06:35:03
问题 What is wrong with this function? I am lost thanks for help. function titleCase(str) { var splitStr = str.toLowerCase().split(\' \'); for (var i = 0; i < splitStr.length; i++) { if (splitStr.length[i] < splitStr.length) { splitStr[i].charAt(0).toUpperCase(); } str = splitStr.join(\' \'); } return str; } titleCase(\"I\'m a little tea pot\"); 回答1: You are not assigning your changes to the array again, so all your efforts are in vain. Try this: function titleCase(str) { var splitStr = str