#include<stdio.h>
#include<conio.h>
#include<string.h>
void main(void)
{
int i,k,n;
char name[50],temp;
printf("\n enter no.of persons");
scanf("%d",&n);
for(i=0;i<n;i++)
gets(name[i]);
for(k=0;k<n-1;k++)
{
for(i=0;i<n-k-1;i++)
{
if(strcmp(name[i],name[i+1])>0)
{
strcpy(temp,name[i]);
strcpy(name[i],name[i+1]);
strcpy(name[i+1],temp);
}
}
}
printf("\n sorted list \n");
for(i=0;i<n;++i)
puts(name[i]);
}
#include<stdio.h>
#include<conio.h>
main()
{
char names[40][20],temp[20];
int i,n,j;
printf("How many names?:");
scanf("%d",&n);
printf("Enter the %d names one by one:",n);
for(i=0;i<n;i++)
scanf("%s",names[i]);
for(i=0;i<=n-1;i++)
for(j=i+1;j<n;j++)
if(strcmp(names[i],names[j])>0)
{
strcpy(temp,names[i]);
strcpy(names[i],names[j]);
strcpy(names[j],temp);
}
printf("Names in Alphabetical order");
for(i=0;i<n;i++)
printf("%s",names[i]);
getche();
}
class project_4
{
/*Enter a sentence*/
public static void main(String sent)
{
int i,x,length;
length=sent.length();
char temp;
char ch[]=new char[length];
for(i=0;i
{
ch[i]=sent.charAt(i);
}
for(i=0;i { for(x=0;x { if(ch[x]>ch[x+1]) { temp=ch[x]; ch[x]=ch[x+1]; ch[x+1]=temp; } } } for(i=0;i System.out.print(ch[i]); } } final char[] chars = str.toCharArray(); Arrays.sort(chars); return String.valueOf(chars); } Answer 3 import java.io.*; class Alphabetical { protected static void main()throws IOException { BufferedReader in=new BufferedReader(new InputStreamReader(System.in)); System.out.print("Enter the String: "); String s=in.readLine(); for(short i=65;i<91;i++) { for(short j=0;j { char ch=s.charAt(j); if(ch==i ch==i+32) System.out.print(ch); }
// Names are stored here
final ArrayList<String> names = new ArrayList<String>();
// Get input from standard in
final BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
// Prompt for input
System.out.println("Enter names to sort: ");
// Get input
String currentLine;
while ((currentLine = in.readLine()) != null) {
// A blank line equals the end of input
if (currentLine.equals("")) {
break;
}
names.add(currentLine);
}
// Remember to close our input
in.close();
System.out.println("Sorting: " + names);
// Let Java do our sorting for us.
Collections.sort(names);
System.out.println("Sorted: " + names);
public class sort1
{
public static void main(String args[])
{
int len = args.length;
if(len == 0)
{
System.out.println("No Arguments");
System.exit(0);
}
char str[] = args[0].toCharArray();
char temp;
for(int i = 0; i<len ; i++)
{
for(int j = 0; j<len ; j++)
{
if(str.CharAt(j) > str.CharAt(j+1))
{
temp = str[j];
str[j] = str[i];
str[i] = temp;
}
}
}
for(int i = 0 ; i< len; i++)
{
System.out.println(str[i]);
}
}
}
I assume you want to sort the names alphabetically. Java has a built in alphabetical sorting command. You first need to put your strings into an array, and then use the method java.util.Arrays.sort(String Array). The method Collections.sort(List Name) will then sort your list into alphabetical order. Keep in mind you will need to import these methods.
Write a program using a while loop to print the numbers 2 to 10 in increments of two. The output of your program should be 2 4 6 8 10
TL Kidd Kiddle Graphics Kids Kommotion H Kidby The Kids Art Academy
what is string
i dont no string for servlate
.... String line = "This is example program with spaces"; String[] tokens = line.split(" "); System.out.println(tokens.length-1); .......
what is if(!(str[i]==32))
[ string toupper $str ] or [ string tolower $str ]
what is string
i dont no string for servlate
i am sam
This is an assignment not a question.
what is if(!(str[i]==32))
.... String line = "This is example program with spaces"; String[] tokens = line.split(" "); System.out.println(tokens.length-1); .......
what is if(!(str[i]==32))
[ string toupper $str ] or [ string tolower $str ]
No.
final String[] days = new String[] {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
One way to do this is to convert the number to a String, then use the corresponding String method to find out the length of the String.
This is not a question.