Hello I am new but I have been in a intro programming class with Java as the main entree. I have this program where I need to end input characters at 65 characters and break the line and then add a new line.
This is my code:
import static java.lang.Syste m.*;
import java.util.Scann er;
class formatter3 {
public static void main (String[] args) {
Scanner stdin = new Scanner (System.in);
int maxlen = 65;
int outlen = 0;
int spaces = 0;
while (stdin.hasNext ()) {
String word = stdin.next();
System.out.prin tf(word); ++(spaces);
if ((outlen + spaces + word.length) > maxlen) printf ("%n");
}
}
}
and i get these error messages when i try to complie:
bash-2.03$ javac formatter3.java
formatter3.java :14: cannot find symbol
symbol : variable length
location: class java.lang.Strin g
if ((outlen + spaces + word.length) > maxlen) printf ("%n");
^
formatter3.java :14: operator + cannot be applied to int,java.lang.S tring.length
if ((outlen + spaces + word.length) > maxlen) printf ("%n");
^
formatter3.java :14: operator > cannot be applied to <nulltype>,in t
if ((outlen + spaces + word.length) > maxlen) printf ("%n");
^
formatter3.java :14: cannot find symbol
symbol : method printf(java.lan g.String)
location: class formatter3
if ((outlen + spaces + word.length) > maxlen) printf ("%n");
^
4 errors
Waaahhhh!!!! any suggestions would be helpful. please I've been searching aorund campus for a community that does java and could help out and let me be a part, but santa cruz is HIPPY! x_x
This is my code:
import static java.lang.Syste m.*;
import java.util.Scann er;
class formatter3 {
public static void main (String[] args) {
Scanner stdin = new Scanner (System.in);
int maxlen = 65;
int outlen = 0;
int spaces = 0;
while (stdin.hasNext ()) {
String word = stdin.next();
System.out.prin tf(word); ++(spaces);
if ((outlen + spaces + word.length) > maxlen) printf ("%n");
}
}
}
and i get these error messages when i try to complie:
bash-2.03$ javac formatter3.java
formatter3.java :14: cannot find symbol
symbol : variable length
location: class java.lang.Strin g
if ((outlen + spaces + word.length) > maxlen) printf ("%n");
^
formatter3.java :14: operator + cannot be applied to int,java.lang.S tring.length
if ((outlen + spaces + word.length) > maxlen) printf ("%n");
^
formatter3.java :14: operator > cannot be applied to <nulltype>,in t
if ((outlen + spaces + word.length) > maxlen) printf ("%n");
^
formatter3.java :14: cannot find symbol
symbol : method printf(java.lan g.String)
location: class formatter3
if ((outlen + spaces + word.length) > maxlen) printf ("%n");
^
4 errors
Waaahhhh!!!! any suggestions would be helpful. please I've been searching aorund campus for a community that does java and could help out and let me be a part, but santa cruz is HIPPY! x_x
Comment