Created
October 3, 2014 19:56
-
-
Save emettely/6f24e2fb9cd409a77edf to your computer and use it in GitHub Desktop.
Revisions
-
emettely created this gist
Oct 3, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,44 @@ import java.util.Scanner; public class AgeFirstname { public static void main(String[] args) { // TODO Auto-generated method stub //read age System.out.println("What is your age?"); Scanner inputage = new Scanner(System.in); //change string to integer String age = inputage.nextLine(); int age1 = Integer.parseInt(age); //read name System.out.println("What is your name?"); String name = inputage.nextLine(); if (age1 < 15){ //while age is bigger than 0, print one and increment while (age1 > 0){ age1--; System.out.println(name); } } else { //store name length in len int len = name.length(); //store name length as arrays in alpha char[] th = new char[len]; int ar = 0; //LOOP! new integer value alpha is last letter of name //until i is to 0 (first letter) count down for(int i = len - 1; i >= 0; i--){ //count up and store characters in name from last to beginning using i th[ar++] = name.charAt(i); } System.out.println(th); } } }