Thread: JAVA 101 help
View Single Post
  #1   Spotlight this post!  
Unread 31-10-2016, 08:19
Tem1514 Mentor's Avatar
Tem1514 Mentor Tem1514 Mentor is offline
Registered User
FRC #1514
Team Role: Mentor
 
Join Date: Feb 2010
Rookie Year: 2010
Location: Toronto
Posts: 238
Tem1514 Mentor is a splendid one to beholdTem1514 Mentor is a splendid one to beholdTem1514 Mentor is a splendid one to beholdTem1514 Mentor is a splendid one to beholdTem1514 Mentor is a splendid one to beholdTem1514 Mentor is a splendid one to beholdTem1514 Mentor is a splendid one to beholdTem1514 Mentor is a splendid one to behold
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 24
System.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
Reply With Quote