Thursday 15 April 2010

java - How would i write a for loop for this code i have written -


I have written a Java code for which a loop is required. I am unsure about how to write one for this program because I have only written for the knives for int or doubles. I do not want the full answer because I really would like to end this code by myself. I need a little help in understanding how to write a loop for this code.

This project was supposed to write AO code which encourages a user to enter a sentence and should display each character on the screen except the space character (''). This is the code I have written. As I said above how I have been stuck as a writing for loop

  import java.util.Scanner; Public class sheet {public static boolean is asespace (four sentences) {if (sentence == ''); {System.out.print (sentence + ":" + "space"); Back true; }} Static boolean is the case above (four input status) {if (incententance> = 'A' and input centenance & lt; = 'Z') {System.out.print (Input status + ":" + "Upper case"); Back true; } return false; } Public stable boolean isLlCerCase (char inputSentence) {if (Incentantance> = 'A' & amp; inputSentence & lt; = 'z') {System.out.print (inputSentence + ":" + "Lower Case") ; Back true; } return false; } Public static zero main (string [] args) {scanner keyboard_input = new scanner (System.in); System.out.print ("Please enter a sentence:"); String sentence = keyboard_input.next (); For me ()}   

I also have a quick question on how my string sentence can be read in the form of characters in the program. Thanks!

The method reads only one word. You should use the method so that you can read the entire sentence.

The method gives you a char [] . With this you can write for a loop as you do with int s and double s.

 for  (int i = 0; iAlert; length; i ++) {// ...}   

If you If you are interested, you can learn more about this for loop here -.

No comments:

Post a Comment