English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I need to java code to "Display letter nearest end of alphabet" please help im stuck

2007-03-12 04:00:40 · 6 answers · asked by 5789854322379 1 in Computers & Internet Programming & Design

I need a code that when I input the following

FAB
RUM
GIN
CAN
YOU

it chooses the "last" letter from the alphetbet for each one

2007-03-12 04:09:48 · update #1

Could you please right the code for me I cant even understand it....

2007-03-12 04:14:34 · update #2

( For inti <=5

char1 = ?;
char2 = ?;
char3 = ?;
nearest_end(char1,char2,char3)

Is what I have so far

2007-03-12 04:31:07 · update #3

6 answers

This sounds more like homework help so I'm not going to give you the code, here are a couple of methods...

You need to examine your string to find the letter Z, and if it's not there the letter Y, then X etc until you find the latest letter of the alphabet.

In: 'Hello' you want O.
In: 'Hi' you want 'I'
In: 'This is an amazing sentence' - you'd want Z.

You could loop through each letter in your string and determine it's ASCII value. Then find out which character has the highest ASCII value - then convert that back to text.

or

You could loop through the alphabet (backwards from Z-A)
And determine if the loop letter is in your string - jump out of the loop when you have a hit.

2007-03-12 04:10:52 · answer #1 · answered by mark 7 · 0 0

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class t
{
public static void main(String [] args)throws Exception
{
//Welcome message:
System.out.println("Starting program... type a word or exit to terminate");
//Initialize input:
BufferedReader reader= new BufferedReader(new InputStreamReader(System.in));
//Our read string:
String str="";
//A loop is done until "exit" word is entered
do
{
//Read a string:
str=reader.readLine();
//Convert to UpperCase just to make things easy
str=str.toUpperCase();
//This var contains the greatest letter. Initialize to 0 to start comparation
char l=0;
//Look for the answer through all the string
for(int i=0;i {
//This is the key: find the greatest letter
if(str.charAt(i)>l)
l=str.charAt(i);
}
//Print result:
System.out.println("greatest letter for "+str+" is "+l);
}
while(!str.equals("EXIT"));
}
}

2007-03-12 04:56:23 · answer #2 · answered by Anonymous · 1 0

uve 2 b specific in ur q !, unlike wad uve put !

2007-03-12 04:12:43 · answer #3 · answered by chintu_victor 1 · 0 0

Please be specific dude. Whats "nearest end of alphabet"?

2007-03-12 04:04:31 · answer #4 · answered by NeevarP M 3 · 0 0

just print 'Z'

2007-03-12 04:10:31 · answer #5 · answered by Anonymous · 0 0

you did not explain ur question Please explain ur question..

2007-03-12 04:06:29 · answer #6 · answered by SaoodMUHAMMAD miyan 1 · 0 0

fedest.com, questions and answers