import java.io.*;
class s30
{
public static void main (String args[]) throws IOException
{
DataInputStream k=new DataInputStream (System.in);
String a;
System.out.println("Enter String: ");
a=k.readLine();
char s = a.charAt(1);
System.out.println(s);
System.out.println(a.length());
}
}
Showing posts with label String. Show all posts
Showing posts with label String. Show all posts
Problem 2: CharAt and length
Similar the previous problem, create a program that will allow the user to enter a string (word or phrase) that will also show the second character and the length based on the string entered by the user.
Problem: CharAt and String
Create a program that will display the first letter of a string as well as display the string's length. Note that the string will not be provided by the user.
class s30
{
public static void main (String args[])
{
String a = "Hello World";
char s = a.charAt(0);
System.out.println(s);
System.out.println(a.length());
}
}
Input and Output
if you want to input something in Java, you should add import java.io.*; before your class name, throws IOException after (String args[]), and DataInputStream for buffering
Try this:
Note that newinput can be replaced by any word or letter which depends to the programmer. Let's say that the programmer wants to put his name on it, let's say his name is Nick, Nick can put it this way...
DataInputStream Nick = new DataInputStream(System.in);
Make sure also, that the uses of newinput in the program are replaced by Nick.
Notice: readLine should always be written as readLine() with an uppercased L.
Try this:
import java.io.*;
public class import
{
public static void main (String args[]) throws IOException
{
DataInputStream newinput = new DataInputStream(System.in);
String new;
System.out.println("Enter phrase here:");
new = newinput.readLine();
System.out.println(new);
}
}
Note that newinput can be replaced by any word or letter which depends to the programmer. Let's say that the programmer wants to put his name on it, let's say his name is Nick, Nick can put it this way...
DataInputStream Nick = new DataInputStream(System.in);
String new;
System.out.println("Enter phrase here:");
new = Nick.readLine();
System.out.println(new);
}
}
Make sure also, that the uses of newinput in the program are replaced by Nick.
Notice: readLine should always be written as readLine() with an uppercased L.
Subscribe to:
Posts (Atom)
Extended Search

Custom Search