0% found this document useful (0 votes)
3 views2 pages

java

The document contains Java code examples that demonstrate how to read a string input from the user and manipulate it. The first example removes duplicate characters, the second reverses the string using an array, and the third reverses the string using a loop. Each example is encapsulated in a main method within a class named 'IndexOfExample'.

Uploaded by

abunahidanik
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

java

The document contains Java code examples that demonstrate how to read a string input from the user and manipulate it. The first example removes duplicate characters, the second reverses the string using an array, and the third reverses the string using a loop. Each example is encapsulated in a main method within a class named 'IndexOfExample'.

Uploaded by

abunahidanik
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

safdgsfsdhf

safdgh

package javapractice;

import java.util.Scanner;

public class IndexOfExample {


public static void main(String args[]) {

Scanner sc = new Scanner(System.in);


String name = sc.nextLine();
String uniq = "";

for (int i = 0; i < name.length(); i++) {


char a = name.charAt(i);
if(uniq.indexOf(a)== -1) uniq+=a;

}
System.out.println(uniq);

-----------------------------------------------------------------------------------
-

qwerty
ytrewq

package javapractice;

import java.util.Scanner;

public class IndexOfExample {


public static void main(String args[]) {

Scanner sc = new Scanner(System.in);


String name = sc.nextLine();
char[] namearray = name.toCharArray();

//String uniq = "";


char[] uniqarray = new char[namearray.length] ;
int j = 0;
for (int i = namearray.length-1; i >= 0; i--) {
uniqarray[j]= namearray[i];
j++;
}
//uniq= uniqarray.toString();
System.out.println(uniqarray);

package javapractice;

import java.util.Scanner;
public class IndexOfExample {
public static void main( String args[]) {

Scanner sc = new Scanner(System.in);


String input = sc.nextLine();
String reverse= "";

for(int i= input.length()-1 ; i >= 0 ; i) {

reverse += input.charAt(i);

}
System.out.println(reverse);
}

----------------------------------------------------

You might also like