Write a Java program to print the last word and word length in a given String, without using the split() method.
Output: string=6
class Main {
public static void main(String[] args) {
String input ="Occurence of string";
String st="";
for(int i= 0;i<input.length();i++){
if(input.charAt(i)==' '){
st="";
}
if(input.charAt(i)!=' '){
st+=input.charAt(i);
}
}
System.out.println(st+" = "+st.length());
}
}
Write a java program to check given number is even or odd ,by not using any conditional and looping statement.
class Main {
public static void main(String[] args) {
int n =17;
String[] arr={"even","odd"};
System.out.println("this is a "+arr[n%2]+" number.");
}
}