|
|
|
![]() |
|
|||||||
|
||||||||
|
|
Thread Tools | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
JAVA 101 help
As a complete novice with JAVA I am trying some sample tests to get some sort of handle on how to program in this language.
Please see the below code ################################# import java.util.Scanner; public class makeitwork { static Scanner scanner = new Scanner(System.in); public static void main(String[] args) { Boolean alarm = false; System.out.println("What time 0-24"); Integer clock = Integer.parseInt(scanner.nextLine()); System.out.println("Door open 'T' or 'F'"); String door = (scanner.nextLine()); System.out.println("Test combo 0000-9999"); String combo = (scanner.nextLine()); System.out.println("#1-t-"+clock+"-d-"+door+"-c-"+combo+"-a-"+alarm); if (clock < 5){ System.out.println("clock<5"); } if (clock == 5){ System.out.println("clock = 5"); } if (clock >5 && clock <24){ System.out.println("clock > 5 and < 24"); } if (clock >5 || clock <24){ // watch out for this one it only fails with 24System.out.println("clock > 5 or < 24"); } if (clock >=23 && clock <=24 || clock>= 0 && clock <= 3){ System.out.println("clock 11pm to 3 am"); } // all those integer functions seem to work on clock. // lets see what work for strings if (door == "t"){ System.out.println("It's a t ");} else{ System.out.println("Don't know-"+door+"-"); } } //end of main }// end of public ############################################## The integer functions seem to work just as expected but when I try the same thing with what I think is a string it does not work at all. The print will always be "Don't know-"+door+"-" result. So my question(s) are; What am I doing wrong? Where in the "eclipse" enviroment can I find example help on functions? When using the 'Help' function in eclipse what does one do to get a list functions? Currently I am looking for way of finding things out about a string such as; 1)it's length 2)how to strip a string apart one charater at a time and search for delimiters etc. for example; assume test[] are strings test = "334,5,t,678,c,9" from the 'test' I would like to extract the string parts separted by a ',' to get test1 = "334" test2 = "5" test3 = "t" test4 = "678" test5 = "c" test6 = "9" Many thanks |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|