I would like to complete a project that requires a name as a console input, but returns an output of that name in reverse. It should only use for-loops and strings/substrings.
I think it needs to use an array to get it done. I am right?
Below is my attempt using an array, but not correct...
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package javalessonnr;
/**
*
* SVW
*/
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner kbReader = new Scanner(System.in);
System.out.print("Please enter your name. ");
String myName = kbReader.nextLine();
int nmeLength = myName.length();
System.out.println(nmeLength);
int revArr[] = new int[nmeLength];
int arrLngth = revArr.length;
System.out.println(arrLngth);
String revName="";
for(int i = 0; i < nmeLength; i++)
{
revName = myName.substring(nmeLength);
}
System.out.print(revName);
}
}