import java.io.*;
import java.util.*;
public class Name2{
Scanner scan=new Scanner(System.in);
String name;
int index;
public void input(){
try{
System.out.println("Enter your Name: ");
name=scan.nextLine();
System.out.println("Enter the number to show which character is in that position: ");
index=scan.nextInt();
}
catch(Exception e){
System.out.println("Error Code: "+e);
System.exit(0);
}
}
public void compute(){
if(index>=name.length())
System.out.println("No character.");
if(index<name.length()){
if(name.charAt(index)==' '){
index-=1;
System.out.println("Character at \""+index+"\" number of your name is: "+(name.charAt(index-1)));
}
else
System.out.println("Character at \""+index+"\" number of your name is: "+(name.charAt(index-1)));
}
}
public static void main(String[] args){
Name2 obj=new Name2();
obj.input();
obj.compute();
}
}
import java.util.*;
public class Name2{
Scanner scan=new Scanner(System.in);
String name;
int index;
public void input(){
try{
System.out.println("Enter your Name: ");
name=scan.nextLine();
System.out.println("Enter the number to show which character is in that position: ");
index=scan.nextInt();
}
catch(Exception e){
System.out.println("Error Code: "+e);
System.exit(0);
}
}
public void compute(){
if(index>=name.length())
System.out.println("No character.");
if(index<name.length()){
if(name.charAt(index)==' '){
index-=1;
System.out.println("Character at \""+index+"\" number of your name is: "+(name.charAt(index-1)));
}
else
System.out.println("Character at \""+index+"\" number of your name is: "+(name.charAt(index-1)));
}
}
public static void main(String[] args){
Name2 obj=new Name2();
obj.input();
obj.compute();
}
}
Comments